As the error message states an OBJECT library can't consume other
OBJECT libraries. When creating the actual library you will have to
explicitly state what $<TARGET_OBJECTS:?> you need.

If you are just looking at a way to simplify the logic for the
consuming library you should look at doing the following:

1. Use a global property to store what OBJECT targets should be consumed

2. Wait for https://gitlab.kitware.com/cmake/cmake/merge_requests/1524
to be finished.

On Fri, Feb 16, 2018 at 12:29 PM, Simone Atzeni <satz...@nvidia.com> wrote:
> Hi,
>
>
>
> I am trying to merge together two “OBJECT” libraries.
>
> I am following the tutorial at:
> https://cmake.org/Wiki/CMake/Tutorials/Object_Library
>
>
>
> However, in my case I have more level of folder nesting, and at the parent
> level I would like to merge two “OBJECT” libraries and only at the top I
> want to create the actual library.
>
>
>
> I tried with:
>
>
>
> add_library(common OBJECT "$<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B>
> $<TARGET_OBJECTS:C>")
>
>
>
> But I get the following error:
>
>
>
> -----------------------------------------------------------------------------------------------------
>
> CMake Error at lib/common/CMakeLists.txt:31 (add_library):
>
>   OBJECT library "common" contains:
>
>
>
>     file1.cpp.o
>
>     file2.cpp.o
>
>     file3.cpp.o
>
>     …
>
>
>
>   but may contain only sources that compile, header files, and other files
>
>   that would not affect linking of a normal library.
>
>
>
> CMake Error at lib/common/CMakeLists.txt:31 (add_library):
>
>   Only executables and non-OBJECT libraries may reference target objects.
>
>
>
> What’s the correct way to do this?
>
>
>
> Thanks.
>
> Simone
>
>
>
> ________________________________
> This email message is for the sole use of the intended recipient(s) and may
> contain confidential information.  Any unauthorized review, use, disclosure
> or distribution is prohibited.  If you are not the intended recipient,
> please contact the sender by reply email and destroy all copies of the
> original message.
> ________________________________
>
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
>
-- 

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:
https://cmake.org/mailman/listinfo/cmake

Reply via email to