mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-23 14:48:19 -05:00
ExternalProject,FetchContent: Avoid CMAKE_DISABLE_SOURCE_CHANGES error
The file(MAKE_DIRECTORY) implementation checks whether a path is allowed to be written to before it checks if it already exists. For the scenario where a SOURCE_DIR is an existing directory within the main project's source directory, this triggers a fatal error if CMAKE_DISABLE_SOURCE_CHANGES is set to true for ExternalProject, and some FetchContent scenarios. Therefore, add an explicit check for existence first to avoid making such error-triggering calls. Fixes: #21872
This commit is contained in:
@@ -3,8 +3,13 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# If CMAKE_DISABLE_SOURCE_CHANGES is set to true and the source directory is an
|
||||
# existing directory in our source tree, calling file(MAKE_DIRECTORY) on it
|
||||
# would cause a fatal error, even though it would be a no-op.
|
||||
if(NOT EXISTS "@source_dir@")
|
||||
file(MAKE_DIRECTORY "@source_dir@")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY
|
||||
"@source_dir@"
|
||||
"@binary_dir@"
|
||||
"@install_dir@"
|
||||
"@tmp_dir@"
|
||||
|
||||
@@ -1657,8 +1657,13 @@ function(__FetchContent_populateDirect)
|
||||
set(_EP_TMP_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-tmp")
|
||||
set(_EP_DOWNLOAD_DIR "${_EP_TMP_DIR}")
|
||||
|
||||
# If CMAKE_DISABLE_SOURCE_CHANGES is set to true and _EP_SOURCE_DIR is an
|
||||
# existing directory in our source tree, calling file(MAKE_DIRECTORY) on it
|
||||
# would cause a fatal error, even though it would be a no-op.
|
||||
if(NOT EXISTS "${_EP_SOURCE_DIR}")
|
||||
file(MAKE_DIRECTORY "${_EP_SOURCE_DIR}")
|
||||
endif()
|
||||
file(MAKE_DIRECTORY
|
||||
"${_EP_SOURCE_DIR}"
|
||||
"${_EP_BINARY_DIR}"
|
||||
"${_EP_STAMP_DIR}"
|
||||
"${_EP_TMP_DIR}"
|
||||
|
||||
Reference in New Issue
Block a user