summaryrefslogtreecommitdiffstats
path: root/Modules/FetchContent.cmake
diff options
context:
space:
mode:
authorCraig Scott <craig.scott@crascit.com>2020-08-23 08:38:47 (GMT)
committerCraig Scott <craig.scott@crascit.com>2020-08-23 08:38:47 (GMT)
commitb972e25276186ea43879dccfab50f43024f44390 (patch)
tree9541ac0c0c4f316e3e1a2aab0491a695ae39212b /Modules/FetchContent.cmake
parent269d1a86249ea037a2884133daffc8c44a38d926 (diff)
downloadCMake-b972e25276186ea43879dccfab50f43024f44390.zip
CMake-b972e25276186ea43879dccfab50f43024f44390.tar.gz
CMake-b972e25276186ea43879dccfab50f43024f44390.tar.bz2
FetchContent: Fix SOURCE_DIR, BUILD_DIR when disconnected or overridden
Fixes: #21123
Diffstat (limited to 'Modules/FetchContent.cmake')
-rw-r--r--Modules/FetchContent.cmake41
1 files changed, 31 insertions, 10 deletions
diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake
index c85e2d8..acf2a94 100644
--- a/Modules/FetchContent.cmake
+++ b/Modules/FetchContent.cmake
@@ -1038,6 +1038,11 @@ function(FetchContent_Populate contentName)
message(FATAL_ERROR "Content ${contentName} already populated in ${${contentNameLower}_SOURCE_DIR}")
endif()
+ __FetchContent_getSavedDetails(${contentName} contentDetails)
+ if("${contentDetails}" STREQUAL "")
+ message(FATAL_ERROR "No details have been set for content: ${contentName}")
+ endif()
+
string(TOUPPER ${contentName} contentNameUpper)
set(FETCHCONTENT_SOURCE_DIR_${contentNameUpper}
"${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}"
@@ -1045,14 +1050,35 @@ function(FetchContent_Populate contentName)
if(FETCHCONTENT_SOURCE_DIR_${contentNameUpper})
# The source directory has been explicitly provided in the cache,
- # so no population is required
+ # so no population is required. The build directory may still be specified
+ # by the declared details though.
set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
- set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
+
+ cmake_parse_arguments(savedDetails "" "BINARY_DIR" "" ${contentDetails})
+
+ if(savedDetails_BINARY_DIR)
+ set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR})
+ else()
+ set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
+ endif()
elseif(FETCHCONTENT_FULLY_DISCONNECTED)
- # Bypass population and assume source is already there from a previous run
- set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
- set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
+ # Bypass population and assume source is already there from a previous run.
+ # Declared details may override the default source or build directories.
+
+ cmake_parse_arguments(savedDetails "" "SOURCE_DIR;BINARY_DIR" "" ${contentDetails})
+
+ if(savedDetails_SOURCE_DIR)
+ set(${contentNameLower}_SOURCE_DIR ${savedDetails_SOURCE_DIR})
+ else()
+ set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
+ endif()
+
+ if(savedDetails_BINARY_DIR)
+ set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR})
+ else()
+ set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
+ endif()
else()
# Support both a global "disconnect all updates" and a per-content
@@ -1072,11 +1098,6 @@ function(FetchContent_Populate contentName)
unset(quietFlag)
endif()
- __FetchContent_getSavedDetails(${contentName} contentDetails)
- if("${contentDetails}" STREQUAL "")
- message(FATAL_ERROR "No details have been set for content: ${contentName}")
- endif()
-
set(__detailsQuoted)
foreach(__item IN LISTS contentDetails)
string(APPEND __detailsQuoted " [==[${__item}]==]")