If I use one of the visual studio generators, the compiler is selected automatically, but if I use “NMake Makefiles” it seems I need to set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly. Some posts suggest I don’t need to do this if I run my build appropriate native tools command prompt, but my builds need to be invoked from a python script. I’m uncertain as to the best approach.
Normal CMake policy is that it must be run in an environment correctly configured for building, i.e. it must have access to the build tools. Running from a build tool command prompt is the easiest way to do that. If that is not an option (such as in your script), you can set up the environment in alternate ways. You could for example set variables such as CC
, CXX
, and PATH
as necessary, or somehow manually reuse or invoke the appropriate vcvars*.bat
.
A few generators are an exception to this, they can figure out the build tool setup by system introspection and don’t have to run in a pre-configured environment. That is the case for Visual Studio generators, but it must be viewed as a special case.
Thank you for the information Petr. I think - within the script - I can locate the appropriate vcvars*.bat and then execute it before each of the two cmake commands issued by the script. I mainly wished to know that there wasn’t an altogether better way.