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

Alexandre Feblot Alexandre.Feblot at thomsonreuters.com
Tue Mar 24 07:30:13 EDT 2009


Hi,

 

I'm facing an issue while trying to port my current build system to
cmake, and it seems there is no way to solve it currently. At least,
nobody in the mailing list found one. The only suggestion was to totally
recode the dependency mechanism with macros instead of relying on the
Cmake standard mechanism (as done in Boost), which doesn't really look
like an optimal use of cmake.

Let me explain the problem again, and propose the cmake api to solve it:

 

----- PROBLEM:

 

It's a typical application of the C++ link time variation idiom:

 

In our project, we build a bunch of static libs (about 360) and several
executables on them.

 

* one library, in the middle of the lib dependency chain, has in fact 2
different implementations. That is to say, there are 2 different libs
with the exact same interface, but they don't use the same back-end,
have different source code, and don't have the same dependencies.

* only one of them has to be used in every executable, the
implementation to use is determined by the executable.

 

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.

 

----- SOLUTION : Feature request:

 

Adding a SELECTOR keyword (working a bit like debug|optimized) to
target_link_libraries to specify that the given dependency is only
required when this selector has a given value.

The selector will be defined when building the executable.

 

target_link_libraries(<target> [item1 [item2 [...]]]

                        [[SELECTOR <selectorName>
<selectorValue>][debug|optimized|general] <item>] ...)

 

 

* lib3 CMakeLists.txt:

add_library(lib3  some source)

target_link_libraries(lib3,

SELECTOR  A_OR_B  A  lib4-A

SELECTOR  A_OR_B  B  lib4-B

      )

 

* exe1-A CmakeLists.txt

      add_executable(exe1-A  some sources)

      set (A_OR_B  A)

      target_link_libraries(exe1-A  lib1)  # will link with lib4-A

 

* exe1-B CmakeLists.txt

      add_executable(exe1-A  some sources)

      set (A_OR_B  B)

      target_link_libraries(exe1-A  lib1)  # will link with lib4-B

 

 

Would you see this feature in a future official release?

Would you include a patch if we code it with your help, as we don't know
much about cmake sources.

 

Thanks,

 



This email was sent to you by Thomson Reuters, the global news and information company.
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090324/9f9d196f/attachment-0001.htm>


More information about the CMake mailing list