[CMake] debug & optimized

Brad King brad.king at kitware.com
Fri Mar 11 10:26:36 EST 2005


Martin Groher wrote:
> I’ve created a library with CMake called 'viewers'. Now, I want to link
> against this lib in another CMake project, but, on WIN32, I want to use the
> debug lib in DEBUG mode and the optimized lib in RELEASE mode. 
> 
> Lib viewers: Since I don't know the path in advance where to find the libs
> (and I don't want to add the path to the PATH-variable), I would like to
> copy the created libs to a dedicated directory (viewers/lib). Now, in WIN32,
> I would like to have two libs there, viewers.lib and viewersD.lib. Then I
> could just used the optimized/debug keywords in the other project to link
> against these libs. 
> 
> I tried to create a post-build command to copy the created viewer libs to
> the viewers/lib directory, but here, I cannot tell which lib I'm copying,
> debug or optimized. Since the debug/release libs have the same name, I don't
> know how to do that since the keywords debug/optimized just hold for the
> LINK_LIBRARIES and TARGET_LINK_LIBRARIES commands. 
> Is there some way to create different custom commands for debug/optimized
> mode? Or any other way to somehow tell CMake how to distinguish created libs
> within the same project?

You can create your own executable to do the copy operation.  Then add 
the custom command using ${CMAKE_CFG_INTDIR} as part of the source 
location.  At build time it will be expanded to ".\Debug" or ".\Release" 
depending on the build configuration.  Then your executable can check 
the directory from which it is copying the library to decide whether it 
is the debug or optimized version.

Alternatively you can follow the instructions from section 6.7 of the 
"Mastering CMake" book available here:

http://www.cmake.org/HTML/Documentation.html

This will let you setup a package configuration file for the "viewers" 
library to make it easy to link it into outside projects.

-Brad


More information about the CMake mailing list