Feature: `FETCHCONTENT_INCLUDE`: Equivalent to `CMAKE_PROJECT_INCLUDE` for `FetchContent_MakeAvailable`
Concept
The functions FETCHCONTENT_INCLUDE
, FETCHCONTENT_INCLUDE_BEFORE
, FETCHCONTENT_<ProjectName>_INCLUDE
and FETCHCONTENT_<ProjectName>_INCLUDE_BEFORE
would be the equivalents of CMAKE_PROJECT_INCLUDE
variables, but:
-
INCLUDE_BEFORE
are included before the calls ofFetchContent_Declare
, potentially having a pre-definedcmake_parser_arguments
interface of the arguments used - Alternatively, the include could be before
FetchContent_MakeAvailable
such that the scope of the variables are limited -
INCLUDE
are included after the calls ofFetchContent_MakeAvailable
, with a pre-defined variable that holds the name of the project. This should be called with the context of the project that was effectively called withadd_subdirectory
.
Usage
Currently I do not have a killer usecase for this, but the one I have right now is: Injecting set_package_properties
and set_property(PACKAGES_FOUND)
for #25322. This is because the name as found in FetchContent_Declare
is needed, and the inclusion of these files should be conditional to if FetchContent
is used as opposed to if find_package
override is called.
This would be different from simply calling include()
in that the interface is a bit cleaner and it would contain the context of the inner project with add_subdirectory
.
Issues
- How would this interact with chained
FetchContent
? The simplest approach is that it does not interact, and simply the current variable scope is used. This would mean that it is hard to have one project that inject a script in all subprojects (likeset_package_properties
)
Edited by Cristian Le