CMake: defining link directories and libraries for different build purposes

I have a vs2008 project. His project files are created using CMake. What I want to do is define the libraries and library directories for the Debug and Release target independently, that is, release the libraries for the target version of the release and debug the libraries for the debug purpose, of course.

So far, I have no idea how to do this. I know that I can define different compiler arguments with CMAKE_CXX_FLAGS_DEBUG and CMAKE_CXX_FLAGS_RELEASE , for example (or, however, assembly target names), but I have no idea how to do this for dirs and libs links.

The person who created the CMakeLists file with all the definitions tried it with

IF( CMAKE_BUILD_TYPE MATCHES "Debug" ) 

but it does not work. According to some CMake wiki, the CMAKE_BUILD_TYPE variable is not defined at setup time, only at run time, depending on what purpose you are using, of course.

Right now I'm kinda like a dead end and would be grateful for any hints or directions :).

+6
visual-studio-2008 cmake
source share
2 answers

There is a target_link_libraries option to help you do this. But you will need to expand the name of your library to the full path.

 target_link_libraries(foo debug c:/path/to/debug/lib/blah.lib optimized c:/path/to/optimized/lib/blah.lib) 

If your place in the library is named as CMake does (Debug / MinSizeRel / RelWithDebInfo / Release), you can use the VS $(ConfigurationName) variable:

 link_directories(c:/path/to/all/libs/$(ConfigurationName)/) 

Beware, $(ConfigurationName) not a cmake variable: it will only expand VS during the build / link phase.

+10
source share

you can just call cmake with the set already configured:

 cmake -DCMAKE_BUILD_TYPE="Debug" 

or what I do is specify the link and platform on the command line, and then manually configure the type of configuration:

 cmake -dMyConfigType="DebugStaticX86" #CMakeLists.txt if( ${MyConfigType} STREQUAL "DebugStaticX86" ) set( CMAKE_BUILD_TYPE Debug ) set( MyLinkType Static ) set( MyPlatform x86 ) #now include other files that set the actual compile/link options #depending on values of MyLinkType and MyPlatform .... endif 
0
source share

All Articles