It seems to me that the CMAKE_GENERATOR variable CMAKE_GENERATOR set too late if it is set in CMakeLists.txt . If you use (even at the beginning of CMakeLists.txt )
set(CMAKE_GENERATOR "Ninja") message("generator is set to ${CMAKE_GENERATOR}")
you can see something like
% cmake ../source -- The C compiler identification is GNU 4.9.2 ... -- Detecting CXX compile features - done generator is set to Ninja -- Configuring done -- Generating done -- Build files have been written to: /tmp/build
Thus, the variable is set only at the very end of the generation procedure. If you use something like
set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE)
in CMakeLists.txt , then the very first run of cmake ../source (without -G ) uses the default generator. However, the CMAKE_GENERATOR variable CMAKE_GENERATOR stored in the cache. Therefore, if you re-run cmake ../source after this, it will use the generator as specified in the CMAKE_GENERATOR variable in the cache.
This, of course, is not the most elegant solution, though ;-) Perhaps use a batch file that actually runs cmake -G generator for the user ...
Michael Kopp Apr 23 '15 at 9:34 2015-04-23 09:34
source share