Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default build configuration of cmake

Tags:

c++

cmake

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 sepcifying -DCMAKE_BUILD_TYPE flag, 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?

like image 271
Lahiru Chandima Avatar asked Nov 23 '14 06:11

Lahiru Chandima


2 Answers

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).

like image 133
Mikhail Maltsev Avatar answered Nov 17 '22 04:11

Mikhail Maltsev


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, and this defaults to Debug. So

cmake --build .

in a multi-configuration project builds a Debug version.

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, and this defaults to Release.

More background info on single- and multiconfiguration-generators in this answer.

like image 36
Adrian W Avatar answered Nov 17 '22 04:11

Adrian W