https://stackoverflow.com/questions/24460486/cmake-build-type-is-not-being-used-in-cmakelists-txt
There are two types of generators: single-configurations and multi-configurations.
1. Single configurations
Make-like generators: Unix Makefiles
, NMake Makefiles
, MinGW Makefiles
, ...
You set the configuration type in the generate step:
cmake -H. -B_builds/Debug -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles"
In this case, the build step is always Debug:
> cmake --build _builds/Debug
/usr/bin/c++ -g ...
> cmake --build _builds/Debug --config Debug # `--config` ignored
/usr/bin/c++ -g ...
> cmake --build _builds/Debug --config Release # yep, ignored
/usr/bin/c++ -g ...
2. Multi-configuration
IDE generators: Visual Studio
, Xcode
CMAKE_BUILD_TYPE on generate step is ignored,
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_BUILD_TYPE
both:
> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Debug "-GVisual Studio 12 2013 Win64"
and
> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release "-GVisual Studio 12 2013 Win64"
will have the same effect:
This is because all the configurations is internal (i.e., _builds/msvc-opaque/Release
and _builds/msvc-opaque/Debug
or something, doesn't matter).
You can use --config options to switch:
> cmake --build _builds --config Release
cl /O2 ...
> cmake --build _builds --config Debug
cl /Od ...
3. Control
Yes, you can. Just define CMAKE_CONFIGURATION_TYPES:
# Somewhere in CMakeLists.txt
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
Default output:
-- Detecting CXX compiler ABI info - done
Generated with config types: Debug;Release;MinSizeRel;RelWithDebInfo
-- Configuring done
Rewrite it:
> cmake -H. -B_builds -DCMAKE_CONFIGURATION_TYPES="Debug;Release" "-GVisual Studio 12 2013 Win64"
-- Detecting CXX compiler ABI info - done
Generated with config types: Debug;Release
-- Configuring done
You can even define your own configuration type:
> cmake -H. -B_builds -DCMAKE_CONFIGURATION_TYPES="Debug;MyRelease" -DCMAKE_CXX_FLAGS_MYRELEASE="/My-Rel-flag" -DCMAKE_EXE_LINKER_FLAGS_MYRELEASE="/My-Linker-flags" "-GVisual Studio 12 2013 Win64"
And build:
cmake --build _builds --config MyRelease
4. Messy (?)
Not at all if you know the trick
标签:cmake,builds,--,BUILD,Debug,CMAKE,config,build From: https://www.cnblogs.com/Searchor/p/17283249.html