2

I would like to link to certain libraries only in Debug builds, not in Release ones. Using the debug flag in target_link_libraries as mentioned here only applies to the library immediately following the flag. However, I would like to apply it to all libraries specified in a variable from find_package, like so:

find_package(Cairomm)
add_library(Paint Painter.cpp)
target_link_libraries(Paint
  debug ${Cairomm_LIBRARIES}

Checking the resulting binary with ldd shows, that the first library specified in Cairomm_LIBRARIES is indeed omitted, the following however are linked.

Can I somehow apply the debug flag to all libraries in the variable?

Community
  • 1
  • 1
Daniel
  • 23
  • 3

1 Answers1

2

Use a loop:

foreach (_lib ${Cairomm_LIBRARIES})
    target_link_libraries(Paint debug ${_lib})
endforeach()
sakra
  • 62,199
  • 16
  • 168
  • 151
  • Thanks a lot, that did the trick. After some refactoring, I pulled all the Cairo related stuff in its own .cpp and created a separate library target for it that I could then use with debug in target_link_library. – Daniel Mar 25 '15 at 13:21