[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    Re: [CMake] OBJECT libraries and INTERFACE_SOURCES
From:       Giovanni Funchal <gio () cloudnc ! co ! uk>
Date:       2016-12-09 10:26:21
Message-ID: CACs7uvaBh=t-KkxQFEbvrzqgZjXGsnFH=1xrhMp+sZiCKJ8ZJQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

Apologies, the problem wasn't properly minimised because I had some trouble
wrapping my head around it. Here's two complete examples which I hope can
explain the problem better this time.

1) This works:

[CMakeLists.txt]
    cmake_minimum_required(VERSION 3.6)
    project(Test)
    add_library(lib1-obj OBJECT lib1.cpp)
    add_library(lib1 INTERFACE)
    set_target_properties(lib1 PROPERTIES INTERFACE_SOURCES
$<TARGET_OBJECTS:lib1-obj>)
    add_library(lib2 lib2.cpp)
    target_link_libraries(lib2 lib1)
    add_executable(main main.cpp)
    target_link_libraries(main lib2)

2) But this does not:

[CMakeLists.txt]
    cmake_minimum_required(VERSION 3.6)
    project(Test)
    add_library(lib1-obj OBJECT lib1.cpp)
    add_library(lib1 INTERFACE)
    set_target_properties(lib1 PROPERTIES INTERFACE_SOURCES
$<TARGET_OBJECTS:lib1-obj>)
    add_library(lib2 lib2.cpp)
    target_link_libraries(lib2 lib1)
    add_subdirectory(main)

[main/CMakeLists.txt]
    add_executable(main main.cpp)
    target_link_libraries(main lib2)

With the second example, I get an error "cannot find source file lib1.cpp.o
tried extensions...".

Thanks,
-- Giovanni


On Thu, Dec 8, 2016 at 9:56 PM, Stephen Kelly <steveire@gmail.com> wrote:

> Giovanni Funchal wrote:
>
> > Hi,
> >
> > The help page [1] mentions that:
> >
> >> Although object libraries may not be named directly in calls to the
> >> target_link_libraries() command, they can be "linked" indirectly by
> >> using an Interface Library whose INTERFACE_SOURCES target property
> >> is set to name $<TARGET_OBJECTS:objlib>.
> >
> > However, I was unable to get this to work. Doing this:
> >
> > add_library(lib-obj OBJECT test.cpp)
> > add_library(lib INTERFACE)
> > add_dependencies(lib lib-obj)
> > set_target_properties(lib PROPERTIES INTERFACE_SOURCES
> > $<TARGET_OBJECTS:lib-obj>)
> >
> > And then trying to specify lib in link_libraries of an executable yields
> > an error message "Cannot find source file: ... Tried extensions:... ".
> >
> > Am I doing something wrong?
>
> This works for me:
>
>     cmake_minimum_required(VERSION 3.3)
>
>     project(testit CXX)
>
>     add_library(lib-obj OBJECT foo.cpp)
>     add_library(lib-iface INTERFACE)
>     set_target_properties(lib-iface PROPERTIES
>       INTERFACE_SOURCES $<TARGET_OBJECTS:lib-obj>
>     )
>     add_executable(main foo-user.cpp)
>     target_link_libraries(main lib-iface)
>
>
> Thanks,
>
> Steve.
>
>
> --
>
> 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

[Attachment #5 (text/html)]

<div dir="ltr">Hi,<div><br></div><div>Apologies, the problem wasn&#39;t properly \
minimised because I had some trouble wrapping my head around it. Here&#39;s two \
complete examples which I hope can explain the problem better this \
time.</div><div><br></div><div>1) This \
works:</div><div><br></div><div>[CMakeLists.txt]</div><div><div>      \
cmake_minimum_required(VERSION 3.6)</div><div>      project(Test)</div><div>      \
add_library(lib1-obj OBJECT lib1.cpp)<br></div><div>      add_library(lib1 \
INTERFACE)<br></div><div>      set_target_properties(lib1 PROPERTIES \
INTERFACE_SOURCES $&lt;TARGET_OBJECTS:lib1-obj&gt;)</div><div>      add_library(lib2 \
lib2.cpp)<br></div><div>      target_link_libraries(lib2 lib1)</div><div>      \
add_executable(main main.cpp)<br></div><div>      target_link_libraries(main \
lib2)</div></div><div><br></div><div>2) But this does \
not:</div><div><br></div><div><div>[CMakeLists.txt]</div><div></div><div>      \
cmake_minimum_required(VERSION 3.6)</div><div>      project(Test)</div><div>      \
add_library(lib1-obj OBJECT lib1.cpp)<br></div><div>      add_library(lib1 \
INTERFACE)<br></div><div>      set_target_properties(lib1 PROPERTIES \
INTERFACE_SOURCES $&lt;TARGET_OBJECTS:lib1-obj&gt;)</div><div>      add_library(lib2 \
lib2.cpp)<br></div><div>      target_link_libraries(lib2 lib1)</div><div>      \
add_subdirectory(main)<br></div></div><div><br></div><div>[main/CMakeLists.txt]</div><div><div> \
add_executable(main main.cpp)<br></div><div>      target_link_libraries(main \
lib2)</div></div><div><br></div><div>With the second example, I get an error \
&quot;cannot find source file lib1.cpp.o tried \
extensions...&quot;.</div><div><br></div><div>Thanks,</div><div>-- \
Giovanni</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On \
Thu, Dec 8, 2016 at 9:56 PM, Stephen Kelly <span dir="ltr">&lt;<a \
href="mailto:steveire@gmail.com" target="_blank">steveire@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span \
class="gmail-">Giovanni Funchal wrote:<br> <br>
&gt; Hi,<br>
&gt;<br>
&gt; The help page [1] mentions that:<br>
&gt;<br>
&gt;&gt; Although object libraries may not be named directly in calls to the<br>
&gt;&gt; target_link_libraries() command, they can be "linked" indirectly by<br>
&gt;&gt; using an Interface Library whose INTERFACE_SOURCES target property<br>
&gt;&gt; is set to name $&lt;TARGET_OBJECTS:objlib&gt;.<br>
&gt;<br>
&gt; However, I was unable to get this to work. Doing this:<br>
&gt;<br>
&gt; add_library(lib-obj OBJECT test.cpp)<br>
&gt; add_library(lib INTERFACE)<br>
&gt; add_dependencies(lib lib-obj)<br>
&gt; set_target_properties(lib PROPERTIES INTERFACE_SOURCES<br>
&gt; $&lt;TARGET_OBJECTS:lib-obj&gt;)<br>
&gt;<br>
&gt; And then trying to specify lib in link_libraries of an executable yields<br>
&gt; an error message &quot;Cannot find source file: ... Tried extensions:... \
&quot;.<br> &gt;<br>
&gt; Am I doing something wrong?<br>
<br>
</span>This works for me:<br>
<br>
      cmake_minimum_required(VERSION 3.3)<br>
<br>
      project(testit CXX)<br>
<br>
      add_library(lib-obj OBJECT foo.cpp)<br>
      add_library(lib-iface INTERFACE)<br>
      set_target_properties(lib-<wbr>iface PROPERTIES<br>
<span class="gmail-">         INTERFACE_SOURCES $&lt;TARGET_OBJECTS:lib-obj&gt;<br>
      )<br>
</span>      add_executable(main foo-user.cpp)<br>
      target_link_libraries(main lib-iface)<br>
<br>
<br>
Thanks,<br>
<br>
Steve.<br>
<br>
<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" \
target="_blank">www.kitware.com</a><br> <br>
Please keep messages on-topic and check the CMake FAQ at: <a \
href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" \
target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br> <br>
Kitware offers various services to support the CMake community. For more information \
on each offering, please visit:<br> <br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" \
target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br> CMake \
Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" \
target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br> CMake \
Training Courses: <a href="http://cmake.org/cmake/help/training.html" \
rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
 <br>
Visit other Kitware open-source projects at <a \
href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" \
target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br> <br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" \
target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/cmake</a></blockquote></div><br></div></div>




-- 

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



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic