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

Adolfo Rodríguez dofo79 at gmail.com
Tue Mar 24 07:56:53 EDT 2009


Just curious, what would be the inconvenience of using an if statement
around  target_link_libraries to link against one or another target?

On Tue, Mar 24, 2009 at 12:30 PM, Alexandre Feblot <
Alexandre.Feblot at thomsonreuters.com> wrote:

>  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.
>
> _______________________________________________
> 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
>



-- 
Adolfo Rodríguez Tsouroukdissian

Robotics engineer
PAL ROBOTICS S.L
http://www.pal-robotics.com
Tel. +34.93.414.53.47
Fax.+34.93.209.11.09
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090324/b4edf70f/attachment.htm>


More information about the CMake mailing list