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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to