Avoid name clashes from targets in multiple dune modules
Summary
When compiling multiple dune modules, e.g., by using cmakes add_subdirectory
command, or FetchContent
utilities, it happes that two modules are added that define the same cmake targets. CMake will complain about that. We have started to fix a few of these names, e.g. extensions/dune-alugrid!183 (merged) or dune-fem/dune-fem!683 (merged) but there are more. I wanted to open this issue to discuss possible solution.
Related issues discussed somewhere else
- https://stackoverflow.com/questions/70381809/how-can-i-avoid-target-name-collisions-when-using-cmake-fetchcontent-add-subdire
- https://stackoverflow.com/questions/45688707/isolating-gitsubmodule-projects-in-cmake
- https://stackoverflow.com/questions/76254605/how-can-i-avoid-target-name-clashes-when-add-subdirectorying-both-the-mainstre
- https://stackoverflow.com/questions/69630202/how-to-remove-delete-a-cmake-target
- https://gitlab.kitware.com/cmake/cmake/-/issues/22687
Possible solution
- We add a naming convention for our targets, e.g.,
<dune_module>_<target_name>
- We modify the utilities
dune_add_test
correspondingly to automatically prefix all test targets with the dune module name, maybe we export the generated target name in an output variable - We could add another utility
dune_add_executable
that does the same for executable targets