Reputation: 24068
In this answer, it says Debug is the default cmake build configuration.
But I have a different observation:
I have following in my CMakeLists.txt to choose debug and release versions of a lib according to the current build configuration.
target_link_libraries(MyApp debug Widgets_d)
target_link_libraries(MyApp optimized Widgets)
It seems that when I invoke cmake without specifying -DCMAKE_BUILD_TYPE
, Widgets
is used instead of Widgets_d
(When I delete Widgets
and try to build, Make complains that lib is not there). So that means by default the build configuration is optimized, not debug.
So what actually is the default build configuration? If it is debug, what could be wrong with my CMakeLists.txt?
Upvotes: 14
Views: 28428
Reputation: 5026
If depends on whether you are using a single-configuration generator (Makefiles) or a multi-configuration generator (Visual Studio, XCode).
The link cited in the question is about a multi-configuration generator. When using a multi-configuration generator, the configuration variable CMAKE_BUILD_TYPE
is ignored. To select the configuration to build, cmake allows the switch --config
. In many cases, omitting --config
builds a Debug
configuration, but the current CMake documentation now clarifies that there is no specified default - it can even be empty.
However, when using a single-configuration generator, the switch --config
is ignored. Only the configuration variable CMAKE_BUILD_TYPE
is used to determine the build type. The default depends on the toolchain (see docs).
More background info on single- and multiconfiguration-generators in this answer.
Upvotes: 14
Reputation: 1678
target_link_libraries with optimized
keyword corresponds to all configurations, which are not debug.
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).
Upvotes: 11