[CMake] Config Dependent Link Paths

Michael Wild themiwi at gmail.com
Wed Aug 19 15:48:36 EDT 2009


On 19. Aug, 2009, at 20:42, <aaron.meadows at thomsonreuters.com> <aaron.meadows at thomsonreuters.com 
 > wrote:

> Background:
> 	* I am moving from Visual Studio 2008 projects to Cmake in
> preparation
> 	  for porting our software to Linux.
>
> 	* We have debug and release versions of 3rdparty libraries to
> link
> 	  against in two separate paths but under the same name.
> 		(debug/library1.lib & release/library1.lib are debug and
> 		release builds of the same library)
>
> Question:
> 	With the "multi-configuration generator" for Visual Studio, how
> can I configure my root CMakeList.txt file to setup these two separate
> link paths based on which configuration is used?
>
> Any help you can give would be great, even if it's directing me toward
> which concept to read about to understand the answer.  Thanks!
>


Either you use something like this:

# adjust these names on Linux...
set( LIB1_DEBUG /full/path/to/debug/library1.lib )
set( LIB1_RELEASE /full/path/to/release/library1.lib )

target_link_libraries( some_target debug ${LIB1_DEBUG} optimized $ 
{LIB1_RELEASE} )

Or you use import libraries (never used that myself, though):

add_library( lib1 SHARED IMPORTED )
set_target_properties( lib1d PROPERTIES
   IMPORTED_CONFIGURATIONS "DEBUG;OPTIMIZED;"
   IMPORTED_IMPLIB /full/path/to/release/library1.lib
   IMPORTED_LOCATION /full/path/to/release/library1.dll
   IMPORTED_IMPLIB_RELEASE /full/path/to/release/library1.lib
   IMPORTED_LOCATION_RELEASE /full/path/to/release/library1.dll
   IMPORTED_IMPLIB_DEBUG  /full/path/to/debug/library1.lib
   IMPORTED_LOCATION_DEBUG /full/path/to/debug/library1.dll
   # more configurations...
   # use IMPORTED_LINK_INTERFACE_LIBRARIES for transitive dependencies  
in the interface of library1
   # use IMPORTED_LINK_DEPENDENT_LIBRARIES for dependent libraries not  
in the interface of library1
   )

target_link_libraries( some_target lib1 )


HTH

Michael


More information about the CMake mailing list