CMAKE_PROJECT_INCLUDE: Allow to run multiple files
Context
While making a compatibility Find<Package>.cmake
to merge the interface of find_package(CONFIG)
, pkg-config
and FetchContent
, I've found myself in the need to create relevant aliases like
add_library(Package::target ALIAS Local_Target)
This is because a different older Package
project might have been pulled due to FetchContent_Declare
, and in the context of the current project where FetchContent_MakeAvailable
is called, I want to make sure that the appropriate alias target are created.
I am experimenting with CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE
, but this seems to not accept a list variable. This would be a problem because the usage of this could be altered by other projects in the chain, or not be called in the relevant place of FetchContent_Declare
.
In retrospect though, this variable would not do what I was looking for because according to the documentation, it encloses project()
and not the FetchContent_MakeAvailable
call. Nevertheless there could be uses for this, e.g. I am making a CMake module that can generate the PROJECT_VERSION
dynamically from git
and git_archival.txt
like setuptools_scm
.
Proposal
Parse CMAKE_PROJECT_INCLUDE
and equivalent variables as lists.
Issues to explore
- Does
CMAKE_PROJECT_INCLUDE
work in a chain ofFetchContent_Declare
? In what order are these parsed? - If not, what is needed to inject
CMAKE_PROJECT_INCLUDE
(or equivalent) from a project included viaFethcContent
?