jterm
jterm

Reputation: 1093

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

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?

Upvotes: 10

Views: 15832

Answers (2)

Florian
Florian

Reputation: 42862

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

Upvotes: 10

Dimitri Merejkowsky
Dimitri Merejkowsky

Reputation: 1060

You can grep the value from the CMakeCache.txt file in the build dir. Just out of curiosity, what are you trying to do ?

Upvotes: 1

Related Questions