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
This commit is contained in:
Craig Scott
2020-10-04 21:02:02 +00:00
committed by Kitware Robot
6 changed files with 32 additions and 0 deletions

View File

@@ -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})

View File

@@ -0,0 +1,8 @@
include(FetchContent)
FetchContent_Declare(
WithProject
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/ADirThatDoesNotExist
)
FetchContent_MakeAvailable(WithProject)

View File

@@ -0,0 +1,2 @@
*Manually specified source directory is missing:
+ *FETCHCONTENT_SOURCE_DIR_WITHPROJECT --> .*/ADirThatDoesNotExist

View File

@@ -0,0 +1,8 @@
include(FetchContent)
FetchContent_Declare(
WithProject
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/WithProject
)
FetchContent_MakeAvailable(WithProject)

View File

@@ -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}")