<div dir="ltr">I think option 2 (keeping track on transitive dependencies) should be out of the question.<div>It is bound to fail.</div><div><br></div><div>Superbuild setup makes sense where all the components are part of a bigger whole.</div><div>But if each application may depend on a different "flavor" of a dependency library, I think it should be reflected in your project structure, E.g each application in a separate repository, with all the dependencies as submodules.</div><div><br></div><div>alternatively, you can create a multi-root setup, where you have a project-root-directory for each application, with a top-level CMakeLists that adds all the necessary subdirectories.</div><div>This way, you get the best of all worlds:</div><div>1. Each component's source code is kept only once, and changes are immediately affecting all products.</div><div>2. You can compile each application independently from one another.</div><div><br></div><div>Consider the following structure:</div><div><br></div><div>-top/</div><div> - app1_root/</div><div> - CMakeLists.txt</div><div> - app2_root/<br></div><div> - CMakeLists.txt<br></div><div> - app3_root/<br></div><div> - CMakeLists.txt<br></div><div> - components/</div><div> - CMakeLists.txt<br></div><div> - libA/<br></div><div> - libB/<br></div><div> - libC/<br></div><div><br></div><div>The only issue I can think of is that in each application's top-level CMakeLists.txt you have to add_subdirectory(../components) and the ".." is kind of ugly.</div><div>Other than that I think it should work</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 27, 2019 at 7:00 PM Marek Vojtko <<a href="mailto:marek.vojtko@oxidegames.com">marek.vojtko@oxidegames.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Using add_subdirectory() in a "superbuild" setup is straightforward: Create a root CMakeLists.txt which calls add_subdirectory() on all directories of your project and each target can then use target_link_libraries() without worrying where the target came from.<br>
<br>
Unfortunately the "superbuild" setup also means that each target is compiled exactly once, which means that you cannot change a target's build environment per-application (e.g. preprocessor definitions that change the sizes of stack arrays).<br>
<br>
If I need per-application control of its dependencies' build environment I can have each application's CMakeLists.txt call add_subdirectory() for all of its dependencies. However, that means that each application now has to know all of its *transitive* dependencies and the application's CMakeLists.txt has to be kept up-to-date with any changes in its dependency tree, no matter how deep. So if AppA depends on LibA, which depends on LibB, which depends on LibC. Not only does AppA's CMakeLists.txt have to call add_subdirectory() on LibA, LibB, and LibC, but if LibC is modified to depend on LibX, now AppA's CMakeLists.txt has to also be modified to call add_subdirectory() on LibX.<br>
<br>
Having each target call add_subdirectory() on its own dependencies seems silly, because that would create an insane number of duplicated targets. If LibA depends on LibB and LibC, and both LibB and LibC depend on LibD, this approach would result in both LibB and LibC calling add_subdirectory() on LibD, creating the target twice, which would likely not compile.<br>
<br>
Are these my only two options? Either:<br>
- use a superbuild to have CMake handle my transitive dependencies, but give up per-application build environment changes, or<br>
- track all transitive dependencies manually in each application's CMakeLists.txt, but retain the ability to change the build environment per application.<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>