Daniel
Daniel

Reputation: 23

CMake - Linking different libraries for Debug and Release builds with variable from find_package

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?

Upvotes: 2

Views: 1224

Answers (1)

sakra
sakra

Reputation: 65751

Use a loop:

foreach (_lib ${Cairomm_LIBRARIES})
    target_link_libraries(Paint debug ${_lib})
endforeach()

Upvotes: 2

Related Questions