<div dir="ltr">Hello,<div><br></div><div>Can someone confirm please if this is a bug and whether I should file a bug report?</div><div><br></div><div>Also, the "PRIVATE" workaround doesn't suit me (because it breaks transitivity of includes). Is there any other workaround I can use? I assume reverting to static libraries is the best thing to do in the meanwhile?<br></div><div><br></div><div>Thanks,</div><div>-- Giovanni</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 9, 2016 at 4:25 PM, Giovanni Funchal <span dir="ltr"><<a href="mailto:gio@cloudnc.co.uk" target="_blank">gio@cloudnc.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>PRIVATE works, but I don't understand why (the only difference between the two examples is using a subdirectory).</div><div><br></div><div>Using ${CMAKE_CURRENT_SOURCE_DIR} does not work.</div><div><br></div><div>Thanks,</div><div>-- Giovanni</div><div><div class="h5"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 9, 2016 at 4:17 PM, Chuck Atkins <span dir="ltr"><<a href="mailto:chuck.atkins@kitware.com" target="_blank">chuck.atkins@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Giovanni,<br>Does it work if you add lib1 as a private dependency of lib2?  i.e.:<br><span style="font-family:monospace,monospace">target_link_libraries(lib2 PRIVATE lib1)</span><br><br>Also, it shouldn't matter but what about in your original example if you use the full path to the source file instead while still keeping the public link dependency?  i.e.:<br><span style="font-family:monospace,monospace">add_library(lib1-obj OBJECT $(CMAKE_CURRENT_SOURCE_DIR}/li<wbr>b1.cpp).</span><br></div><div class="gmail_extra"><br clear="all"><div><div class="m_-6185478862421270697m_5844174973165701670m_-5799557117749818928gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">----------<br>Chuck Atkins<br>Staff R&D Engineer, Scientific Computing<br>Kitware, Inc.<br><br></div></div></div></div></div></div></div><div><div class="m_-6185478862421270697h5">
<br><div class="gmail_quote">On Fri, Dec 9, 2016 at 5:26 AM, Giovanni Funchal <span dir="ltr"><<a href="mailto:gio@cloudnc.co.uk" target="_blank">gio@cloudnc.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>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.</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 $<TARGET_OBJECTS:lib1-obj>)</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 $<TARGET_OBJECTS:lib1-obj>)</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 "cannot find source file lib1.cpp.o tried extensions...".</div><div><br></div><div>Thanks,</div><div>-- Giovanni</div><div><div class="m_-6185478862421270697m_5844174973165701670m_-5799557117749818928h5"><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"><<a href="mailto:steveire@gmail.com" target="_blank">steveire@gmail.com</a>></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="m_-6185478862421270697m_5844174973165701670m_-5799557117749818928m_3387639873968406080gmail-">Giovanni Funchal wrote:<br>
<br>
> Hi,<br>
><br>
> The help page [1] mentions that:<br>
><br>
>> Although object libraries may not be named directly in calls to the<br>
>> target_link_libraries() command, they can be “linked” indirectly by<br>
>> using an Interface Library whose INTERFACE_SOURCES target property<br>
>> is set to name $<TARGET_OBJECTS:objlib>.<br>
><br>
> However, I was unable to get this to work. Doing this:<br>
><br>
> add_library(lib-obj OBJECT test.cpp)<br>
> add_library(lib INTERFACE)<br>
> add_dependencies(lib lib-obj)<br>
> set_target_properties(lib PROPERTIES INTERFACE_SOURCES<br>
> $<TARGET_OBJECTS:lib-obj>)<br>
><br>
> And then trying to specify lib in link_libraries of an executable yields<br>
> an error message "Cannot find source file: ... Tried extensions:... ".<br>
><br>
> 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-ifac<wbr>e PROPERTIES<br>
<span class="m_-6185478862421270697m_5844174973165701670m_-5799557117749818928m_3387639873968406080gmail-">      INTERFACE_SOURCES $<TARGET_OBJECTS:lib-obj><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/CMak<wbr>e_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/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.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/opensou<wbr>rce/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/mail<wbr>man/listinfo/cmake</a></blockquote></div><br></div></div></div></div>
<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/CMak<wbr>e_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/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.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/opensou<wbr>rce/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/mail<wbr>man/listinfo/cmake</a><br></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div>