[CMake] replacement for link_directories that support generator expressions

Nils Gladitz nilsgladitz at gmail.com
Mon Sep 8 18:06:26 EDT 2014


On 08.09.2014 23:27, James Bigler wrote:
> Is there an equivalent command to link_directories that support 
> generator expressions?
>
>     link_directories( 
> $<$<CONFIG:Debug>:${PROG_LIBRARY_DIRS_RELWITHDEBCRT}> )
>     link_directories( $<NOT:$<CONFIG:Debug>>:${PROG_LIBRARY_DIRS}> )
>
> Basically I want to use PROG_LIBRARY_DIRS_RELWITHDEBCRT for Debug 
> builds and PROG_LIBRARY_DIRS for everything else.
>
> I'm sure I can go and use set_target_properties or something like 
> that, but I was wondering if there was some way I could make this 
> work, before I have to do a much larger change.
>

The documentation for link_directories() notes that the command is 
rarely necessary since target_link_libraries() takes absolute paths. 
target_link_libraries() itself understands generator expressions.

What is your use case for link_directories()?

If absolutely need be a viable though I guess not portable and possibly 
frowned upon workaround might be something like:

   target_link_libraries(foo PRIVATE -Lfoo/$<CONFIG>/bar) # assumes -L 
adds a linker directory

Given that target_link_libraries() also allows (non library) linker options.

Nils


More information about the CMake mailing list