From b030a6af88a02b0237a00e6f3df4a5807f338823 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Sat, 3 Oct 2020 18:46:08 +1000 Subject: FetchContent: Raise error if manually given source dir does not exist Fixes: #21208 --- Modules/FetchContent.cmake | 6 ++++++ Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake | 8 ++++++++ .../RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt | 1 + .../RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt | 2 ++ Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake | 8 ++++++++ Tests/RunCMake/FetchContent/RunCMakeTest.cmake | 7 +++++++ 6 files changed, 32 insertions(+) create mode 100644 Tests/RunCMake/FetchContent/ManualSourceDirectory.cmake create mode 100644 Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-result.txt create mode 100644 Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing-stderr.txt create mode 100644 Tests/RunCMake/FetchContent/ManualSourceDirectoryMissing.cmake 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}") -- cgit v0.12