Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a CMake build directory build type is Debug or Release?

Tags:

cmake

I know the build type can be set using -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug but is there a command line way to check/confirm which build type is being used by CMake?

like image 774
jterm Avatar asked Mar 22 '16 20:03

jterm


People also ask

Does CMake default to release or debug?

In this answer, it says Debug is the default cmake build configuration.

What does CMake build type do?

Specifies the build type on single-configuration generators (e.g. Makefile Generators or Ninja ). Typical values include Debug , Release , RelWithDebInfo and MinSizeRel , but custom build types can also be defined.

How do I debug a CMake file?

You can also start a debug session from Solution Explorer. First, switch to CMake Targets View in the Solution Explorer window. Then, right-click on an executable and select Debug. This command automatically starts debugging the selected target based on your active configuration.


1 Answers

Besides looking in CMakeCache.txt you could - in the build directory - use

cmake -L . | grep CMAKE_BUILD_TYPE
...
CMAKE_BUILD_TYPE:STRING=Release

or you could e.g. add a customized target to your CMakeLists.txt for doing it

add_custom_target(print_build_type COMMAND ${CMAKE_COMMAND} -E echo ${CMAKE_BUILD_TYPE})

will then be called with something like

$ make --silent print_build_type
Release

But CMAKE_BUILD_TYPE could be empty.

So here is a more generic version using generator expressions:

add_custom_target(
    print_build_type 
    COMMAND ${CMAKE_COMMAND} -E echo $<$<CONFIG:>:Undefined>$<$<NOT:$<CONFIG:>>:$<CONFIG>>
)

References

  • What happens for C/C++ builds if CMAKE_BUILD_TYPE is empty?
  • CMake - Find out which build type is currently used
like image 124
Florian Avatar answered Oct 14 '22 21:10

Florian