Following this post, if I run cmake .. inside my build folder with no options I get the error:

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. CMake Error: CMAKE_Fortran_COMPILER not set, after EnableLanguage CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred!

which I can solve by running

cmake .. -D CMAKE_MAKE_PROGRAM:PATH=/mingw64/bin/mingw32-make

However, I want to set the CMAKE_MAKE_PROGRAM from inside the CMakeLists.txt file. I tried the

if(MSYS) set(CMAKE_MAKE_PROGRAM /mingw64/bin/mingw32-make) endif(MSYS)

but it doesn't work. I would appreciate it if you could help me know how I can resolve this problem.

P.S.1. Here is the code.

P.S.2. I tried the

set(CMAKE_MAKE_PROGRAM /mingw64/bin/mingw32-makemingw32-make CACHE FILEPATH "" FORCE)

as suggested in the comments but it did not help.