<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">I have a library target defined as<div><br></div><div><br></div><div><div>add_library(mylib_core</div><div>    core_source1.cpp</div><div>    core_source2.cpp</div><div>    core_source3.cpp</div><div>)</div></div><div><br></div><div><div>if(UNIX)</div><div>    target_sources(mylib_core PUBLIC</div><div>        ${CMAKE_CURRENT_SOURCE_DIR}/core_source4.cpp</div><div>        ${CMAKE_CURRENT_SOURCE_DIR}/core_source5.cpp</div></div><div>    )</div><div>endif()<br></div><div><br></div><div><br></div><div>Then a target that uses it as a dependency:</div><div><br></div><div><br></div><div>add_library(mylib_thing</div><div><div>    thing_source1.cpp</div><div>    thing_source2.cpp</div><div>    thing_source3.cpp</div><div>)</div></div><div><br></div><div><div>target_link_libraries(mylib_thing</div><div>    PUBLIC</div><div>        mylib_core</div><div>)</div></div><div><br></div><div>When building with static libs, I noticed that the sources defined on mylib_core with target_sources are building twice.<br></div><div><br></div><div><br></div><div><div>[ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source1.cpp.o</div><div>[ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source2.cpp.o</div><div>[ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/thing_source3.cpp.o</div><div>[ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/__/mylib_core/core_source4.cpp.o</div><div>[ 60%] Building CXX object mylib_thing/CMakeFiles/mylib_thing.dir/__/mylib_core/core_source5.cpp.o</div><div><br></div><div>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()?</div><div><br></div><div>thanks,</div><div>wes</div><div><br></div></div></div></div></div></div></div></div>