When using CMake to generate a Visual Studio 15 Solution for the 64 bit architecture one has to first call vcvarsall.bat amd64
and then call cmake with the generator option cmake . -Bbuild -G"Visual Studio 14 2015 Win64"
. CMake will then determine the value of a couple of variables when executing the project()
function.
CMAKE_GENERATOR: Visual Studio 14 2015 Win64
CMAKE_BUILD_TOOL: C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
CMAKE_CXX_COMPILER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
CMAKE_C_COMPILER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
CMAKE_LINKER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/link.exe
CMAKE_CXX_COMPILER_ID: MSVC
CMAKE_CXX_COMPILER_VERSION: 19.0.24215.1
CMAKE_VS_PLATFORM_NAME: x64
I would like to get rid of the call to vcvarsall.bat
and the -G"generator"
option by setting the values of the variables in a toolchain file like this:
# VisualStudio2015.cmake
set(CMAKE_GENERATOR "Visual Studio 14 2015 Win64" CACHE STRING "The CMake generator" FORCE )
set(CMAKE_BUILD_TOOL "C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe" CACHE FILEPATH "The visual studio build-system" FORCE)
set(CMAKE_CXX_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft compiler" FORCE)
set(CMAKE_C_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft compiler" FORCE)
set(CMAKE_LINKER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/link.exe" CACHE FILEPATH "Microsoft linker" FORCE)
set(CMAKE_CXX_COMPILER_ID MSCV CACHE STRING "The Id string of the compiler" FORCE)
set(CMAKE_CXX_COMPILER_VERSION 19.0.24215.1 CACHE STRING "The version of the compiler" FORCE)
set(CMAKE_VS_PLATFORM_NAME x64 CACHE STRING "Target processor architecture" FORCE)
and then call cmake with the CMAKE_TOOLCHAIN_FILE
option:
cmake . -Bbuild -DCMAKE_TOOLCHAIN_FILE=VisualStudio2015.cmake
The problem is that this does not seem to work. When cmake executes the project()
function it overrides the values for the compiler that I have set. So do I just forget to set some variables that are required or is this simply not possible?
Thank you for your time.