Is it possible to pass the build type (Debug, Release)
from Visual Studio to CMake? Currently I am doing this manually in a two step process:
Change the CMakeLists.txt
file in the top project directory as:
cmake_minimum_required (VERSION 3.1.0)
set (MyConfig Release)
set (PROJECT myProject)
...
From the Visual Studion pull down menu, I select Release
version of the build. And then do the build.
I am trying to avoid the mistake of choosing conflicting build types in VS and CMake.
First, you don't change the build type by setting the variable PROJECT
to "Release". That would be done with the variable CMAKE_BUILD_TYPE
.
The CMAKE_BUILD_TYPE
variable should not be used within your CMakeLists.txt, but you pass it to the CMake call. It is passed on command line via cmake -DCMAKE_BUILD_TYPE=Release ..
. That's only relevant for build systems, that support a single build type.
For build systems, like the one from Visual Studio, you don't need it all. Multiple configurations are created and you select the build type in your IDE (pull down in VS).
Further reading: https://cmake.org/Wiki/CMake_Useful_Variables#Compilers_and_Tools