Files
CMake/Tests/RunCMake/FetchContent/DisableSourceChanges.cmake
Craig Scott 0cc1b550dd 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
2024-05-31 18:01:27 +10:00

19 lines
758 B
CMake

cmake_policy(SET CMP0168 NEW)
# Undocumented variable used to catch attempts to write to anywhere under the
# source directory that isn't under the build directory. In order for this
# code path to be checked for direct population mode, we need a non-empty
# download, update, or patch command so that the population code path is used.
# Custom commands might not write to the source directory and instead just
# print messages or other non-modifying tasks, like is done here.
set(CMAKE_DISABLE_SOURCE_CHANGES TRUE)
include(FetchContent)
FetchContent_Declare(
WithProject
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/WithProject # This exists
DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo "Download command executed"
)
FetchContent_MakeAvailable(WithProject)