What is the default build config of cmake
In this answer , it says Debug is the default cmake build configuration.
But I have a different opinion:
I have in my CMakeLists.txt to select the debug and release lib version according to the current build config.
target_link_libraries(MyApp debug Widgets_d) target_link_libraries(MyApp optimized Widgets)
It seems that when I call cmake without sepcifying -DCMAKE_BUILD_TYPE, Widgets is used instead of Widgets_d (when I uninstall Widgets and try to build, complain that the lib is not there). So the default build configuration is optimized and not debugged.
So what is the actual default build configuration? If it's debugging, what could be wrong with my CMakelists.txt?
source to share
target_link_libraries with the keyword optimized
matches all configurations that are not debugged.
Try adding message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
to your CMakeLists.txt to see the actual build type (I suppose it should be empty).
source to share
If it depends if you are using a single- config generator (Makefiles) or multiple config generator (Visual Studio, XCode).
The link cited in the question is for a multi-configuration generator. When using a generator with multiple configurations, the configuration variable is CMAKE_BUILD_TYPE
ignored. To select a config to build, cmake allows switching --config
, and by default this is Debug
. So
cmake --build .
in a multi-configuration project builds a Debug
version.
However, when using a configuration generator, the --config
switch is --config
ignored. Only the config variable is CMAKE_BUILD_TYPE
used to define the build type, and is the default Release
.
More details on single and multi-configuration generators in this answer .
source to share