Brief:
Does anyone know if it possible to add a custom_target in CMake that is included in all submodules? An example would be how the Install/Run_Tests/Package targets are added to every submodule in a build.
More Detail:
My scenario is that for a directory structure such as:
Project
--CMakeLists.txt
--SubMod A
--CMakeListsA.txt
--SubMod B
--CMakeListsB.txt
I would like to add a custom_target for doxygen generation to the top level CMakeLists.txt file and have that included in Sub Module A and B. The command will be exactly the same between all modules.
I could add the custom_target to each sub-module’s cmake file but this seems wrong. The other issue with this is if I have CMake generate a Visual Studio solution there will be conflicts with a “doc” project already existing (if opening the top level solution). CMake provided targets are however smart enough to not be included twice.
I think the best you can do is wrap the
add_custom_targetin a function defined in your top-level CMakeLists.txt and use it in each CMakeLists.txt.To avoid the problem of repeating target names, you could define the function something like:
This depends on each submodule’s CMakeLists.txt having a
projectcommand. If not, you could use each subdirectory’s name: