1

My question is related to Link library based on build configuration and Debug and Release Library Linking with CMAKE (VISUAL STUDIO), however the answers were not satisfying.

My goal is to have one variable where to specify the path to libraries similar to

SET(LINK_LIBRARY optimized Foo debug Foo_d)
target_link_libraries(MyEXE ${LINK_LIBRARY})

But what I want is to have one variable for a bunch of libraries, that I can dispatch to a single call to target_link_libaries(). So something like

SET(LINK_LIBRARIES optimized Foo Foo1 Foo2 debug Foo_d Foo1_d Foo2_d)
target_link_libraries(MyEXE ${LINK_LIBRARIES})

But all over the internet I find that this is not possible in this way, i.e. that I always have to write

target_link_libraries(MyEXE optimized Foo optimized Foo1 debug Foo_d debug Foo1_d)

which means I can't just put all the libraries in one single variable LINK_LIBRARIES, but need FOO_LIBRARY, FOO1_LIBRARY aso.

Is there a way to do this or do I always have to create one variable per single library?

Community
  • 1
  • 1
bobbel
  • 461
  • 6
  • 18
  • It is unclear what problem you have so I assume your problem is scope. I mean I only create 1 variable for this in my root CMakeLists.txt and use in all of my executables. – drescherjm Aug 11 '14 at 13:50
  • Oh ok, I added a more verbose description, hopefully now it is more clear what I mean. – bobbel Aug 11 '14 at 14:05
  • ***But all over the internet I find that this is not possible in this way*** This is wrong. Or at least I have done it that way. – drescherjm Aug 11 '14 at 14:11
  • 2
    lol you're totally right, it works this way, should have just tried it. – bobbel Aug 11 '14 at 14:22
  • 1
    BTW, these days I am migrating from this method to using IMPORTED / EXPORTED targets like this: http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets – drescherjm Aug 11 '14 at 14:25
  • Cool, thank you for the comment, I'll investigate that :) – bobbel Aug 12 '14 at 07:34

0 Answers0