[CMake] How to support separate debug and release build directories?

David Demelier markand at malikania.fr
Fri Jun 21 09:26:27 EDT 2019


Le 21/06/2019 à 15:19, David Aldrich a écrit :
> I now want to support separate target directories: build/debug and 
> build/release.  I've shown my CMakeLists.txt below. So far I've just 
> added an attempt to support build/debug:
> 
> if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
>      message("debug mode")
>      set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug)
> endif (CMAKE_BUILD_TYPE EQUAL "DEBUG")
> 

Do never test CMAKE_BUILD_TYPE in CMakeLists.txt files, it is ignored in 
multiple generators (e.g. Visual Studio).

Just use the appropriate variables that contain suffixes regarding the 
configuration.

e.g

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/release)

See [0] for a list with _<CONFIG> variables.

[0]: https://cmake.org/cmake/help/v3.15/manual/cmake-variables.7.html

HTH

-- 
David


More information about the CMake mailing list