summaryrefslogtreecommitdiff
path: root/Modules/ExternalProject.cmake
diff options
context:
space:
mode:
authorChris Wright <chris@inkyspider.co.uk>2023-04-21 16:47:19 +1000
committerCraig Scott <craig.scott@crascit.com>2023-04-26 16:30:36 +0800
commit550f63447d4c7d2db6ccbeaf1f6378aa6f7af4ed (patch)
tree2f9dca56e1a6891f614c52c78d8884f71c7e84ed /Modules/ExternalProject.cmake
parente256e35daa79732a200883cef398fcd0f8227a3d (diff)
downloadcmake-550f63447d4c7d2db6ccbeaf1f6378aa6f7af4ed.tar.gz
ExternalProject/FetchContent: Support relative remote URLs
Teach `ExternalProject_Add` and `FetchContent_Declare` to resolve relative remote URLs provided via `GIT_REPOSITORY`. Add policy CMP0150 to maintain compatibility. Fixes: #24211 Co-Authored-By: Craig Scott <craig.scott@crascit.com>
Diffstat (limited to 'Modules/ExternalProject.cmake')
-rw-r--r--Modules/ExternalProject.cmake20
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 9a6cbd6bc4..e2cc497a65 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -278,6 +278,13 @@ External Project Definition
URL of the git repository. Any URL understood by the ``git`` command
may be used.
+ .. versionchanged:: 3.27
+ A relative URL will be resolved based on the parent project's
+ remote, subject to :policy:`CMP0150`. See the policy documentation
+ for how the remote is selected, including conditions where the
+ remote selection can fail. Local filesystem remotes should
+ always use absolute paths.
+
``GIT_TAG <tag>``
Git branch name, tag or commit hash. Note that branch names and tags
should generally be specified as remote names (i.e. ``origin/myBranch``
@@ -1188,6 +1195,8 @@ The custom step could then be triggered from the main build like so::
#]=======================================================================]
+include(${CMAKE_CURRENT_LIST_DIR}/ExternalProject/shared_internal_commands.cmake)
+
cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST
@@ -4159,6 +4168,17 @@ function(ExternalProject_Add name)
set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
endif()
+ get_property(repo TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
+ if(NOT repo STREQUAL "")
+ cmake_policy(GET CMP0150 cmp0150
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
+ get_filename_component(work_dir "${source_dir}" PATH)
+ _ep_resolve_git_remote(resolved_git_repository "${repo}" "${cmp0150}" "${work_dir}")
+ set_property(TARGET ${name} PROPERTY _EP_GIT_REPOSITORY ${resolved_git_repository})
+ endif()
+
# The 'complete' step depends on all other steps and creates a
# 'done' mark. A dependent external project's 'configure' step
# depends on the 'done' mark so that it rebuilds when this project