I have two projects sharing some code. Both have their own tools for generating almost the same boilerplate code, which are defined as a CMake target that runs everything when imported (or used as dependency). Let's assume that it is called generator_A
in project A and generator_B
in project B.
There are components that are shared "cloned" in both projects that use this boilerplate code, so for component_1
the CMakeLists.txt on each project would have something like:
# In project A
find_package(generator_A)
add_library(component_1 ...)
target_link_libraries(component_1 generator_A)
# In project B
find_package(generator_B)
add_library(component_1 ...)
target_link_libraries(component_1 generator_B)
Apart from this and other small differences regarding the generated code, component_1
would work in both projects.
I would like to define some intermediate layer for the generators on each project, so that its usage is independent of the project and look like:
find_package(generator_unified)
add_library(component_1 ...)
target_link_libraries(component_1 generator_unified)
For reasons not under my control, I cannot change anything about the generators (e.g. names, how they work, generated code/products).
I have no idea what is the best way to do this. Some ideas that I've found searching docs and the internet:
- Create a
Findgenerator_unified.cmake
file that defines agenerator_unified::generator_unified
from the products ofgenerator_X
inproject_X
(library, headers, other properties?). I am not really how this can be achieved, though.- Does
generator_unified
needs its ownCMakeLists.txt
file, or is it enough with theFind<>.cmake
. - How can I make sure that the
Find<>.cmake
file is available for others?
- Does
- Create some kind of alias that can be used project-wide. This doesn't look possible according to docs .
Is this a better way to achieve this? If 1st alternative is the correct,