<div dir="ltr">That is roughly what I am saying. In my head you had a layout that looked like<div><br></div><div>-> root_dir</div><div>--> module_A</div><div>--> tests_A</div><div>--> module_B</div><div>--> tests_B</div><div><div><br></div><div>So while it is tedious to have module_A explicitly add tests_A it would be a possible solution. The problem is one of graph building. Currently the CMake 'all' graph properly represents building the active module and all dependencies it needs. Separately you have a pool of smaller graphs that represent all tests and targets that are from sub-directories that had EXCLUDE_FROM_ALL applied. Nothing is quickly coming to me that will allow you to add more components to the 'all' graph after the fact.</div><div><div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 17, 2018 at 6:19 AM Job Noorman <<a href="mailto:job@noorman.info">job@noorman.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not sure I completely understand what you mean but I think your <br>
suggestion would be to list *all* needed subdirectories in the active <br>
project. This is not what a want. The active project simply lists its <br>
*direct* dependencies (via target_link_libraries) and CMake then figures <br>
out all the needed transitive dependencies.<br>
<br>
Please correct me if i missed your point :-)<br>
<br>
<br>
On 15/05/18 23:29, Robert Maynard wrote:<br>
><br>
> Have you thought about not doing anything in the root CMakeLists for <br>
> your testing directories but instead inside the active project you use <br>
> add_subdirectory ( it supports relative paths to handle directories <br>
> not physically nested inside it ).<br>
><br>
> On Wed, May 9, 2018 at 8:56 AM Job Noorman <<a href="mailto:job@noorman.info" target="_blank">job@noorman.info</a> <br>
> <mailto:<a href="mailto:job@noorman.info" target="_blank">job@noorman.info</a>>> wrote:<br>
><br>
> Hi all,<br>
><br>
> We have a large codebase consisting of 200+ modules. Each module is<br>
> defined in its own subdirectory and compiled as a static library.<br>
><br>
> These modules are not final products on their own but are combined to<br>
> create "projects". We have about 15 projects that all use a subset of<br>
> the modules to implement their functionality. The projects are<br>
> independent in the sense that they cannot be built together; when<br>
> running cmake, we select the project to build.<br>
><br>
> To ensure that only the modules that are needed by the selected<br>
> project<br>
> are built, we took the following approach: all modules have a common<br>
> root directory which is included using add_subdirectory with the<br>
> EXCLUDE_FROM_ALL flag. Then, the current project's root directory is<br>
> added without this flag. This ensures that the targets defined by the<br>
> project and the modules that they need (but no other) are added to<br>
> the<br>
> build system. This works very well and is much nicer than having to<br>
> define options for all optional modules to be able to disable them.<br>
><br>
> There is one catch, however: each module defines an executable<br>
> that runs<br>
> its unit tests. What should happen is that if a module is built by a<br>
> project, its unit tests are also built. However, there seems to be no<br>
> way to define this relationship in CMake. What we would like to<br>
> express<br>
> is that "if library A is built, then executable ATest should also be<br>
> built". Since ATest obviously links against A, we cannot use<br>
> add_dependencies(A ATest) since this creates a circular dependency<br>
> between an executable and a library.<br>
><br>
> Note that the "option" approach briefly mentioned above would<br>
> allow us<br>
> to express this but this would be completely unwieldy in our case.<br>
><br>
> Is there currently a way in CMake to express this relation between a<br>
> library and an executable?<br>
><br>
> If not, would the following suggestion make sense?: A target property<br>
> "INTERFACE_DEPENDENCIES" could be added that would set the<br>
> MANUALLY_ADDED_DEPENDENCIES target property of dependents. Setting<br>
> this<br>
> property on A with ATest as value would then solve my problem<br>
> (note that<br>
> I proposed adding this property for a different use case here:<br>
> <a href="https://gitlab.kitware.com/cmake/cmake/issues/14633" rel="noreferrer" target="_blank">https://gitlab.kitware.com/cmake/cmake/issues/14633</a>).<br>
><br>
> Regards,<br>
> Job<br>
><br>
> -- <br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" rel="noreferrer" target="_blank">http://www.kitware.com</a>><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at:<br>
> <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.<br>
> 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<br>
> <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>
><br>
<br>
</blockquote></div>