[CMake] help with OBJECT libraries hierarchy

Petr Kmoch petr.kmoch at gmail.com
Wed Jun 22 07:09:48 EDT 2016


Ahoj Miro,

object libraries are not intended for linking. The way it works is you
expand the $<TARGET_OBJECTS> genex into the list of *sources* of the
consuming target. In other words, the string '$<TARGET_OBJECTS:main>' needs
to go into the add_executable(foo) or add_library(foo) command, not into
target_link_libraries(foo).

Petr

On 22 June 2016 at 12:47, Ilias Miroslav <Miroslav.Ilias at umb.sk> wrote:

> Dear experts,
>
>
> I am trying to introduce OBJECT libraries into our project,
> http://www.diracprogram.org. <http://www.diracprogram.org>
>
>
> Into local src/functionality1/CMakeLists.txt I changed
>
>
> add_library(main ${local_sources})
>
>                     to
>
> add_library(main  OBJECT ${local_sources})
>
>
> at  higher level, in src/CMakeLists.txt I changed
>
>
> add_subdirectory(${PROJECT_SOURCE_DIR}/src/functionality1)
> set(EXTERNAL_LIBS main ${EXTERNAL_LIBS})
>
>                                    to
>
> add_subdirectory(${PROJECT_SOURCE_DIR}/src/functionality1)
> set(EXTERNAL_LIBS  $<TARGET_OBJECTS:main> ${EXTERNAL_LIBS})
>
>
> and at the highest level of our CMake infrastructure I have linking of all
> object libraries for given  executable(s) :
>
>
>  target_link_libraries( ${_executable}  ${EXTERNAL_LIBS}  )
>
>
> However, during configuration I am getting repeating error messages  of
> type
>
>
> "CMake Error at cmake/custom/core.cmake:75 (target_link_libraries):
>   Error evaluating generator expression:
>
>     $<TARGET_OBJECTS:main>
>
>   The evaluation of the TARGET_OBJECTS generator expression is only
> suitable
>   for consumption by CMake.  It is not suitable for writing out elsewhere.
> Call Stack (most recent call first):
>   CMakeLists.txt:77 (include)"
>
> Any help please how to best arrange OBJECT libraries ? I have cmake
> version 3.5.0 .
>
>
> Yours, Miro
>
>
>
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160622/a50e9c89/attachment.html>


More information about the CMake mailing list