<div dir="ltr">Thank you for the explanation Robert.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 20, 2018 at 7:34 AM Robert Maynard <<a href="mailto:robert.maynard@kitware.com">robert.maynard@kitware.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You have defined 4 && 5 as public sources so that means that consumers<br>
of mylib_core and mylib_core will build them. If you want the sources<br>
to be part of mylib_core the sources should be private, if you want<br>
the sources to be part of mylib_thing use interface. In general don't<br>
use PUBLIC with target_sources.<br>
On Tue, Nov 20, 2018 at 9:19 AM Wesley Smith <<a href="mailto:wesley.hoke@gmail.com" target="_blank">wesley.hoke@gmail.com</a>> wrote:<br>
><br>
> I have a library target defined as<br>
><br>
><br>
> add_library(mylib_core<br>
> core_source1.cpp<br>
> core_source2.cpp<br>
> core_source3.cpp<br>
> )<br>
><br>
> if(UNIX)<br>
> target_sources(mylib_core PUBLIC<br>
> ${CMAKE_CURRENT_SOURCE_DIR}/core_source4.cpp<br>
> ${CMAKE_CURRENT_SOURCE_DIR}/core_source5.cpp<br>
> )<br>
> endif()<br>
><br>
><br>
> Then a target that uses it as a dependency:<br>
><br>
><br>
> add_library(mylib_thing<br>
> thing_source1.cpp<br>
> thing_source2.cpp<br>
> thing_source3.cpp<br>
> )<br>
><br>
> target_link_libraries(mylib_thing<br>
> PUBLIC<br>
> mylib_core<br>
> )<br>
><br>
> When building with static libs, I noticed that the sources defined on mylib_core with target_sources are building twice.<br>
><br>
><br>
> [ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source1.cpp.o<br>
> [ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source2.cpp.o<br>
> [ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source3.cpp.o<br>
> [ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/__/mylib_core/core_source4.cpp.o<br>
> [ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/__/mylib_core/core_source5.cpp.o<br>
><br>
> The last two source files were already built when mylib_core was built. Why are they being built again under mylib_thing? When these files were defined in the add_library() call, this didn't happen. Any thoughts? Is it related to the PUBLIC v. PRIVATE enum? If so, what is the setting on sources when defining them via add_library()?<br>
><br>
> thanks,<br>
> wes<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/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/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/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/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/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>