[CMake] target_link_libraries difficulties

Benoit Thomas benoit.thomas at gameloft.com
Fri Apr 2 09:56:37 EDT 2010


Maybe I'm missing something here, but I don't see with your code sample 
how I can have both configuration in the same project. From what I 
understand for CMAKE_BUILD_TYPE, this would work with out-of-source 
build if I do something like:

\root cmakelists.txt directory
         \ config1 directory
         \ config2 directory

But currently, since we are using cmake to generate a visual studio 
project, and I'm looking for a "one solution do it all".

I'll try today a solution using CMAKE_EXE_LINKER_FLAGS_<CONFIG> to see 
if it can do the trick.

Thanks for the input,
Ben.

On 2010-04-01 15:05, Michael Jackson wrote:
> Not sure if this is recommended or not with CMake 2.8 BUT:
>
> [mjackson at Ferb]$ cmake --help-command link_directories
> cmake version 2.6-patch 4
> ------------------------------------------------------------------------------ 
>
> SingleItem
>
>   link_directories
>        Specify directories in which the linker will look for libraries.
>
>          link_directories(directory1 directory2 ...)
>
>        Specify the paths in which the linker should search for libraries.
>        The command will apply only to targets created after it is called.
>        For historical reasons, relative paths given to this command are
>        passed to the linker unchanged (unlike many CMake commands which
>        interpret them relative to the current source directory).
>
>
>
> set (CMAKE_BUILD_TYPE "Config-1")
> link_directories ( ${SOME_SOURCE_DIR}/${CMAKE_BUILD_TYPE} )
> include (${SOME_SOURCE_DIR}/${CMAKE_BUILD_TYPE}/Libraries.cmake)
>
> add_executable(MyExe ${srcs})
> target_link_libraries(MyExe ${MyLinkLibraries})
>
> #--- Libraries.cmake file
> set (MyLinkLibraries "Somelib1 SOmeLib2")
>
> Thoughts/comments from the community?
> ___________________________________________________________
> Mike Jackson                      www.bluequartz.net
> Principal Software Engineer       mike.jackson at bluequartz.net
> BlueQuartz Software               Dayton, Ohio
>
>
> On Apr 1, 2010, at 2:52 PM, Benoit Thomas wrote:
>
>> Hello,
>>
>> I'm trying to find a work around since target_link_libraries cannot 
>> be used per-configuration. I know that out-of-build could solve my 
>> problem, but my team is currently migrating from Visual Studio to 
>> cmake, so I need something which "feel" more like Visual Studio.
>>
>> My current project has around 20 configurations (debug, release, many 
>> many more, mostly combination of debug_something, release_something, 
>> etc.) and some of those configuration requires to include special 
>> external libraries, some not. Since I cannot classify all my 
>> configurations as debug or release, solution like 
>> target_link_libraries (target my_library debug|optimized) did not work.
>>
>> To put it simply, what I'm trying to achieve is something like:
>>
>> add_executable (exec)
>> add_library (my_lib)
>>
>> set_target_properties (exec PROPERTIES COMPILE_DEFINITIONS_CONFIG1 
>> USING_MY_LIB)
>> set_target_properties (exec PROPERTIES COMPILE_DEFINITIONS_CONFIG2 
>> NOT_USING_MY_LIB)
>>
>> # should only link the library under CONFIG1
>> target_link_libraries (exec my_library)
>>
>> Thank you,
>> Ben.
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at 
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: 
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>


More information about the CMake mailing list