[CMake] Feature request: generic (config-like) selector on target_link_libraries

Michael Wild themiwi at gmail.com
Tue Mar 24 08:42:51 EDT 2009


On 24. Mar, 2009, at 12:30, Alexandre Feblot wrote:
>
> Dependency graph example: "->" means "depends on"
>
>
>
> exe1-A -> lib1 -> lib3 -> lib4-A -> lib5 -> lib7
>
> exe1-B -> lib1 -> lib3 -> lib4-B -> lib6 -> lib8
>
> exe2-A -> lib2 -> lib3 -> lib4-A -> lib5 -> lib7
>
> exe2-B -> lib2 -> lib3 -> lib4-B -> lib6 -> lib8
>
>
>
>
>
> I'd like to keep using the standard cmake mechanism of dependency
> description in which every lib only defines on which other libs it
> depends, and let cmake compute the final link line.
>
>

I also fail to see why this would be a problem, especially if all  
libraries are static, as you say (Static libraries are simply archives  
of object files, so no symbols have to be resolved while they are  
created since no linking happens). Simply don't have lib3 depend on  
any of the lib4-X, but add those lib4-X directly to the link-commands  
of exeY-X.

E.g.:

# Establish dependencies between static libraries.
target_link_libraries( lib1 lib3 )
target_link_libraries( lib2 lib3 )
target_link_libraries( lib5 lib7 )
target_link_libraries( lib6 lib8 )
target_link_libraries( lib4-A lib5 )
target_link_libraries( lib4-B lib6 )

# Link the executables
target_link_libraries( exe1-A lib1 lib4-A )
target_link_libraries( exe1-B lib1 lib4-B )
target_link_libraries( exe2-A lib2 lib4-A )
target_link_libraries( exe2-B lib2 lib4-B )

Hope this helps

Michael


More information about the CMake mailing list