summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2020-10-04 21:02:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-10-04 21:02:11 (GMT)
commita771e2146a6954fd1ef6739fd4f73ef108cfe2bc (patch)
tree40ca94cd8f5059cd0531872ff8a67445fab73d5a
parent3ae3b352d1b67ec2ca8bce0a74a74381d05b9f04 (diff)
parentb030a6af88a02b0237a00e6f3df4a5807f338823 (diff)
downloadCMake-a771e2146a6954fd1ef6739fd4f73ef108cfe2bc.zip
CMake-a771e2146a6954fd1ef6739fd4f73ef108cfe2bc.tar.gz
CMake-a771e2146a6954fd1ef6739fd4f73ef108cfe2bc.tar.bz2
Merge topic 'FetchContent_missing_SOURCE_DIR'
b030a6af88 FetchContent: Raise error if manually given source dir does not exist Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5317
-rw-r--r--Modules/FetchContent.cmake6
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake8
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt1
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt2
-rw-r--r--Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake8
-rw-r--r--Tests/RunCMake/FetchContent/RunCMakeTest.cmake7
6 files changed, 32 insertions, 0 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index acf2a94..40cc362 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -1052,6 +1052,12 @@ function(FetchContent_Populate contentName)
# The source directory has been explicitly provided in the cache,
# so no population is required. The build directory may still be specified
# by the declared details though.
+
+ if(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()
+
set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
cmake_parse_arguments(savedDetails "" "BINARY_DIR" "" ${contentDetails})
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake b/Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake
new file mode 100644
index 0000000..83fcc4b
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake
@@ -0,0 +1,8 @@
+include(FetchContent)
+
+FetchContent_Declare(
+ WithProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/ADirThatDoesNotExist
+)
+
+FetchContent_MakeAvailable(WithProject)
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt
new file mode 100644
index 0000000..7ecb06b
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt
@@ -0,0 +1,2 @@
+ *Manually specified source directory is missing:
++ *FETCHCONTENT_SOURCE_DIR_WITHPROJECT --> .*/ADirThatDoesNotExist
diff --git a/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake
new file mode 100644
index 0000000..0e24c1a
--- /dev/null
+++ b/Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake
@@ -0,0 +1,8 @@
+include(FetchContent)
+
+FetchContent_Declare(
+ WithProject
+ SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/WithProject
+)
+
+FetchContent_MakeAvailable(WithProject)
diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
index ad9e48e..3eb331f 100644
--- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake
@@ -15,6 +15,13 @@ run_cmake(MakeAvailable)
run_cmake(MakeAvailableTwice)
run_cmake(MakeAvailableUndeclared)
+run_cmake_with_options(ManualSourceDirectory
+ -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT=${CMAKE_CURRENT_LIST_DIR}/WithProject"
+)
+run_cmake_with_options(ManualSourceDirectoryMissing
+ -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT=${CMAKE_CURRENT_LIST_DIR}/ADirThatDoesNotExist"
+)
+
function(run_FetchContent_DirOverrides)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DirOverrides-build)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")