I would like to force CMake to use the "Unix Makefiles" generator from within CMakeLists.txt.
This is the command I use now.
cmake -G "Unix Makefiles" .
I would like it to be this.
cmake .
When running on windows with VC installed and a custom tool-chain.
I would expect to be-able to set the generator in the CMakeLists.txt
file.
Maybe something like this.
set(CMAKE_GENERATOR "Unix Makefiles")
Here is what worked for me - create a file called PreLoad.cmake in your project dir containing this:
set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
This is not what I get, when I run the same command, cmake will look for a gcc compiler / make utility. If the PATH is not set up correctly it will fail with something like:
when gcc / mingw is in the path then everything works fine. So could you provide more information as to your PATH variable or CMAKE version?
It seems to me that the variable
CMAKE_GENERATOR
is set too late if set in theCMakeLists.txt
. If you use (even at the beginning ofCMakeLists.txt
)you can see in the output something like
So the variable is only set at the very end of the generation procedure. If you use something like
in
CMakeLists.txt
, then in the very first run ofcmake ../source
(without-G
) the default generator is used. The variableCMAKE_GENERATOR
is stored in the cache, though. So if you reruncmake ../source
afterwards, it will use the generator as specified in theCMAKE_GENERATOR
variable in the cache.This is surely not the most elegant solution, though ;-) Maybe use a batch file that will actually execute the
cmake -G generator
for the user...