Release and Debug with Cmake and QtCreator

I have used qmake for a while and the debug_and_release facilities to have both debug and release version of my code (with different executable, different build tress …)
Now I use cmake and qtcreator on a regular basis, to obtain the same behavior I have found the following approach :

in my CMakeLists.txtm something like

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib-debug)
set(LIB_INSTALL_DIR ${CMAKE_SOURCE_DIR}/lib-debug)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin-dbg)
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(LIB_INSTALL_DIR ${CMAKE_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
endif()

in QtCreator :
First time you open a CMakeLists.txt, simply choose a build dir (some thing like XXX/qtcreator-build) and run cmake,
then go to Tab projects->edit build configuration -> add -> clone selected
Chage build dir (something like XXX/qtcreator-build-dbg) and click “Run cmake”
In the Arguments edit line enter -DCMAKE_BUILD_TYPE=Debug
You can check that in run settings, working directory has changed to the new bin-dbg directory …

3 responses to “Release and Debug with Cmake and QtCreator”

Leave a Reply

Your email address will not be published. Required fields are marked *