Skip to content

FetchContent: Populate directly without a sub-build

Craig Scott requested to merge craig.scott/cmake:fetchcontent-direct into master

!5749 (merged) was the first attempt at this, but it ultimately had to be reverted. It did a lot of refactoring, and that changed how ExternalProject handled generator expressions and GNU Make variable expansions. This second attempt here suffers from neither of those problems, and it tries to disturb the existing ExternalProject logic much less. We also provide a policy to ease the transition to the new behavior instead of forcing the switch on all projects immediately.

There's quite a bit of code that was moved into Modules/ExternalProject/shared_internal_commands.cmake, but the logic for ExternalProject is much as it was before. The main change for ExternalProject is the shift from getting information from target properties to getting them from variables instead. Importantly, the target properties are still populated, which means projects will continue to work if they were relying on those properties to exist (which they shouldn't be, since they are internal implementation details, but inevitably some projects will be doing that).

I recommend reviewing each commit individually. I've endeavoured to make each change a more manageable review, making it easier to follow the actual change at each step. Where large chunks of code moved, I tried to make that a pure move with no actual change to the implementation as much as possible. Apart from the moved code having NEW policies up to CMake 3.25 instead of being at the mercy of the includer, I don't believe there are any consequential changes in the "ExternalProject: Move more internal commands out of main file" commit.

Fixes: #21703 (closed)

Merge request reports