I have multiple versions of Visual Studio installed (2010, 2012, 2015 trial).
How can I force CMake to generate the makefiles for a specific VS version? By default it generates for VS2015.
In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).
Visual Studio uses a CMake configuration file to drive CMake generation and build. CMakePresets. json is supported by Visual Studio 2019 version 16.10 or later and is the recommended CMake configuration file.
CMake Generators are platform-specific so each may be available only on certain platforms. The cmake(1) command-line tool --help output lists available generators on the current platform. Use its -G option to specify the generator for a new build tree.
First you can check what generators your CMake version does support (and how they are named):
> cmake.exe --help ... The following generators are available on this platform: ... Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". ...
Then you can give the generator with
cmake.exe -G "Visual Studio 11" ..
(short name) cmake.exe -G "Visual Studio 11 2012" ..
(full name)I prefer the later, because of its clarity. And I normally have this call in a build script wrapper:
@ECHO off IF NOT EXIST "BuildDir\*.sln" ( cmake -H"." -B"BuildDir" -G"Visual Studio 11 2012" ) cmake --build "BuildDir" --target "ALL_BUILD" --config "Release"
The full name is transferred to an internal cached CMake variable name CMAKE_GENERATOR
. So the above calls are equivalent to
cmake -DCMAKE_GENERATOR="Visual Studio 11 2012" ..
This gives us an interesting possibility. If you place a file called PreLoad.cmake
parallel to your main CMakeLists.txt
file you can force the default (if available) to take for your project there
cmake.exe ..
PreLoad.cmake
if (NOT "$ENV{VS110COMNTOOLS}" STREQUAL "") set(CMAKE_GENERATOR "Visual Studio 11 2012" CACHE INTERNAL "Name of generator.") endif()
Sometimes you may need to add also -T <toolset-name>
or -A <platform-name>
option:
cmake.exe -G "Visual Studio 10" -T "v90" ..
And last but not least if you are really only interested in the compiler
"\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat"
cmake.exe -G "NMake Makefiles" ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With