[cmake-developers] OBJECT library on left-hand-side of target_link_libraries
Tamás Kenéz
tamas.kenez at gmail.com
Wed Jul 8 13:53:31 EDT 2015
The documentation states that OBJECT libraries "may not be [...] used in the
right hand side of target_link_libraries()".
However it turns out that they can't be used on the left hand side either:
add_library(objlib OBJECT ...)
target_link_libraries(objlib dep-of-objlib)
Result:
CMake Error at CMakeLists.txt:13 (target_link_libraries):
Object library target "objlib" may not link to anything.
This makes it impossible to concisely specify if an OBJECT library has a
dependency which is an IMPORTED library.
Only the legacy way works:
add_library(objlib OBJECT ...)
target_include_directories(objlib ${ZLIB_INCLUDE_DIRS})
...
add_executable(maintarget $<TARGET_OBJECTS:objlib>)
target_link_libraries(maintarget ${ZLIB_LIBRARIES})
But it would be convenient if this would also work:
add_library(objlib OBJECT ...)
target_link_libraries(objlib ZLIB::ZLIB)
Question:
Is this restriction, that an OBJECT library can't be on the left hand side
of
target_link_libraries, is it a hard, final decision? Or is this issue
open for a possible improvement which would allow this and would forward
the link dependencies to the main target the OBJECT library is incorporated
into?
Tamas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150708/5067110c/attachment.html>
More information about the cmake-developers
mailing list