summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2020-12-22 20:49:28 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-12-22 20:49:37 (GMT)
commitce9a9e00a8d7a5117719ce2238bcf995e69c820d (patch)
treed8377468ed6ab3e4a8cd5b876482263a4bd869d4
parent3e05e26296fc506b9deef357708a48dac8598d33 (diff)
parent51595e5f014be2a948e2e3c3ab5a5ce165deabdf (diff)
downloadCMake-ce9a9e00a8d7a5117719ce2238bcf995e69c820d.zip
CMake-ce9a9e00a8d7a5117719ce2238bcf995e69c820d.tar.gz
CMake-ce9a9e00a8d7a5117719ce2238bcf995e69c820d.tar.bz2
Merge topic 'fc-relative-SOURCE_DIR' into release-3.19
51595e5f01 FetchContent: Relative SOURCE_DIR override cannot be a hard error Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5641
-rw-r--r--Modules/FetchContent.cmake9
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative-stderr.txt3
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative.cmake1
-rw-r--r--Tests/RunCMake/FetchContent/RunCMakeTest.cmake5
4 files changed, 17 insertions, 1 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index 40cc362..c81b371 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -1053,7 +1053,14 @@ function(FetchContent_Populate contentName)
# so no population is required. The build directory may still be specified
# by the declared details though.
- if(NOT EXISTS "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
+ if(NOT IS_ABSOLUTE "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
+ # Don't check this directory because we don't know what location it is
+ # expected to be relative to. We can't make this a hard error for backward
+ # compatibility reasons.
+ message(WARNING "Relative source directory specified. This is not safe, "
+ "as it depends on the calling directory scope.\n"
+ " FETCHCONTENT_SOURCE_DIR_${contentNameUpper} --> ${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
+ elseif(NOT EXISTS "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
message(FATAL_ERROR "Manually specified source directory is missing:\n"
" FETCHCONTENT_SOURCE_DIR_${contentNameUpper} --> ${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
endif()
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative-stderr.txt b/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative-stderr.txt
new file mode 100644
index 0000000..3defcb4
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative-stderr.txt
@@ -0,0 +1,3 @@
+ *Relative source directory specified. This is not safe, as it depends on
+ *the calling directory scope.
++ *FETCHCONTENT_SOURCE_DIR_WITHPROJECT --> WithProject
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative.cmake b/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative.cmake
new file mode 100644
index 0000000..d8b42ba
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectoryRelative.cmake
@@ -0,0 +1 @@
+include(ManualSourceDirectory.cmake)
diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
index 3eb331f..9baeab7 100644
--- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
@@ -21,6 +21,11 @@ run_cmake_with_options(ManualSourceDirectory
run_cmake_with_options(ManualSourceDirectoryMissing
-D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT=${CMAKE_CURRENT_LIST_DIR}/ADirThatDoesNotExist"
)
+# Need to use :STRING to prevent CMake from automatically converting it to an
+# absolute path
+run_cmake_with_options(ManualSourceDirectoryRelative
+ -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT:STRING=WithProject"
+)
function(run_FetchContent_DirOverrides)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DirOverrides-build)