In src/foo I create lib foo linked with -lwhatever
add_library(foo foo.cpp)
target_link_libraries(foo -lwhatever)
In src/bar I use foo
add_executable (bar bar.cpp)
target_link_libraries(bar foo)
Might be thanks to LTO, but I need to add -lwhatever to target_link_libraries of bar otherwise I have missing symbols at compile time.
target_link_libraries(bar foo -lwhatever)
Can't it be done transparently?
As of CMake 3.0, CMake is missing the
INTERFACE_LINK_FLAGS
target property which would make this possible.The problem here is really that using
target_link_libraries
to specify linker flags was not the smartest design decision in the first place. A separate command in the spirit oftarget_compile_options
would have been desirable.I consider this an oversight in CMake. If you have a relevant use case, you might be able to argue for the inclusion of a
target_link_flags
command in a future CMake version. Feel free to contact the developer's mailing list if this is a major concern for you.An alternative for now would be to use the
LINK_FLAGS
target property offoo
to specify the link flags. You can then also inspect that property at the point where you specifybar
to avoid having to hardcode the options twice, effectively turning it into anINTERFACE_*
property manually. But that's about as good as it gets.