Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cmake target name for debug and release configuration

Tags:

People also ask

How do I set Cmake debug mode?

We can use CMAKE_BUILD_TYPE to set the configuration type: cd debug cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . cd ../release cmake -DCMAKE_BUILD_TYPE=Release ..

How do I change the build type in Cmake?

And for me, it's a lot easier to do 2 clicks in my IDE to change build types than open a command prompt, navigate to my build root, then type cmake . -DCMAKE_BUILD_TYPE=Release .

What is Cmake_build_type?

Specifies the build type on single-configuration generators. This statically specifies what build type (configuration) will be built in this build tree. Possible values are empty, Debug , Release , RelWithDebInfo and MinSizeRel .

What is default Cmake build type?

CMake has several default build types, but if nothing is specified when configuring your project it defaults to an empty string and no optimization flags are used.


I am trying to differentiate between a debug and release build.

If a debug build is in progress I want to install myLibd in /usr/local/lib. If a release build is in progress I want to install myLib in /usr/local/lib.

Here is my approach

IF(CMAKE_BUILD_TYPE MATCHES RELEASE)
    SET(LIB_NAME myLib) 
ELSE()
    SET(LIB_NAME myLibd) 
ENDIF(CMAKE_BUILD_TYPE MATCHES RELEASE)

ADD_LIBRARY(${LIB_NAME} ${Source_files} ${Header_files})
INSTALL(TARGETS ${LIB_NAME} DESTINATION /usr/local/lib)

However, the target name is in both cases (CMAKE_BUILD_TYPE=Debug or Release) always myLibd. What is the problem here?