FetchContent: Populate directly without a sub-build

Fixes: #21703
This commit is contained in:
Craig Scott
2024-05-17 14:23:06 +10:00
parent 173daad58d
commit b2496bf14c
25 changed files with 761 additions and 96 deletions

View File

@@ -21,14 +21,14 @@ function(check_file_hash has_hash hash_is_good)
set("${has_hash}" TRUE PARENT_SCOPE)
message(STATUS "verifying file...
message(VERBOSE "verifying file...
file='@LOCAL@'")
file("@ALGO@" "@LOCAL@" actual_value)
if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
set("${hash_is_good}" FALSE PARENT_SCOPE)
message(STATUS "@ALGO@ hash of
message(VERBOSE "@ALGO@ hash of
@LOCAL@
does not match expected value
expected: '@EXPECT_VALUE@'
@@ -44,7 +44,7 @@ function(sleep_before_download attempt)
endif()
if(attempt EQUAL 1)
message(STATUS "Retrying...")
message(VERBOSE "Retrying...")
return()
endif()
@@ -66,7 +66,7 @@ function(sleep_before_download attempt)
set(sleep_seconds 1200)
endif()
message(STATUS "Retry after ${sleep_seconds} seconds (attempt #${attempt}) ...")
message(VERBOSE "Retry after ${sleep_seconds} seconds (attempt #${attempt}) ...")
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep "${sleep_seconds}")
endfunction()
@@ -75,17 +75,17 @@ if(EXISTS "@LOCAL@")
check_file_hash(has_hash hash_is_good)
if(has_hash)
if(hash_is_good)
message(STATUS "File already exists and hash match (skip download):
message(VERBOSE "File already exists and hash match (skip download):
file='@LOCAL@'
@ALGO@='@EXPECT_VALUE@'"
)
return()
else()
message(STATUS "File already exists but hash mismatch. Removing...")
message(VERBOSE "File already exists but hash mismatch. Removing...")
file(REMOVE "@LOCAL@")
endif()
else()
message(STATUS "File already exists but no hash specified (use URL_HASH):
message(VERBOSE "File already exists but no hash specified (use URL_HASH):
file='@LOCAL@'
Old file will be removed and new file downloaded from URL."
)
@@ -95,7 +95,7 @@ endif()
set(retry_number 5)
message(STATUS "Downloading...
message(VERBOSE "Downloading...
dst='@LOCAL@'
timeout='@TIMEOUT_MSG@'
inactivity timeout='@INACTIVITY_TIMEOUT_MSG@'"
@@ -109,7 +109,7 @@ foreach(i RANGE ${retry_number})
endif()
foreach(url IN ITEMS @REMOTE@)
if(NOT url IN_LIST skip_url_list)
message(STATUS "Using src='${url}'")
message(VERBOSE "Using src='${url}'")
@TLS_VERSION_CODE@
@TLS_VERIFY_CODE@
@@ -135,10 +135,10 @@ foreach(i RANGE ${retry_number})
if(status_code EQUAL 0)
check_file_hash(has_hash hash_is_good)
if(has_hash AND NOT hash_is_good)
message(STATUS "Hash mismatch, removing...")
message(VERBOSE "Hash mismatch, removing...")
file(REMOVE "@LOCAL@")
else()
message(STATUS "Downloading... done")
message(VERBOSE "Downloading... done")
return()
endif()
else()

View File

@@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.5)
get_filename_component(filename "@filename@" ABSOLUTE)
get_filename_component(directory "@directory@" ABSOLUTE)
message(STATUS "extracting...
message(VERBOSE "extracting...
src='${filename}'
dst='${directory}'"
)
@@ -28,21 +28,21 @@ file(MAKE_DIRECTORY "${ut_dir}")
# Extract it:
#
message(STATUS "extracting... [tar @args@]")
message(VERBOSE "extracting... [tar @args@]")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar @args@ ${filename} @options@
WORKING_DIRECTORY ${ut_dir}
RESULT_VARIABLE rv
)
if(NOT rv EQUAL 0)
message(STATUS "extracting... [error clean up]")
message(VERBOSE "extracting... [error clean up]")
file(REMOVE_RECURSE "${ut_dir}")
message(FATAL_ERROR "Extract of '${filename}' failed")
endif()
# Analyze what came out of the tar file:
#
message(STATUS "extracting... [analysis]")
message(VERBOSE "extracting... [analysis]")
file(GLOB contents "${ut_dir}/*")
list(REMOVE_ITEM contents "${ut_dir}/.DS_Store")
list(LENGTH contents n)
@@ -52,14 +52,14 @@ endif()
# Move "the one" directory to the final directory:
#
message(STATUS "extracting... [rename]")
message(VERBOSE "extracting... [rename]")
file(REMOVE_RECURSE ${directory})
get_filename_component(contents ${contents} ABSOLUTE)
file(RENAME ${contents} ${directory})
# Clean up:
#
message(STATUS "extracting... [clean up]")
message(VERBOSE "extracting... [clean up]")
file(REMOVE_RECURSE "${ut_dir}")
message(STATUS "extracting... done")
message(VERBOSE "extracting... done")

View File

@@ -5,16 +5,26 @@ cmake_minimum_required(VERSION 3.5)
if(EXISTS "@gitclone_stampfile@" AND EXISTS "@gitclone_infofile@" AND
"@gitclone_stampfile@" IS_NEWER_THAN "@gitclone_infofile@")
message(STATUS
message(VERBOSE
"Avoiding repeated git clone, stamp file is up to date: "
"'@gitclone_stampfile@'"
)
return()
endif()
# Even at VERBOSE level, we don't want to see the commands executed, but
# enabling them to be shown for DEBUG may be useful to help diagnose problems.
cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
if(active_log_level MATCHES "DEBUG|TRACE")
set(maybe_show_command "COMMAND_ECHO STDOUT")
else()
set(maybe_show_command "")
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to remove directory: '@source_dir@'")
@@ -29,11 +39,12 @@ while(error_code AND number_of_tries LESS 3)
clone @git_clone_options@ "@git_repository@" "@src_name@"
WORKING_DIRECTORY "@work_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
math(EXPR number_of_tries "${number_of_tries} + 1")
endwhile()
if(number_of_tries GREATER 1)
message(STATUS "Had to git clone more than once: ${number_of_tries} times.")
message(NOTICE "Had to git clone more than once: ${number_of_tries} times.")
endif()
if(error_code)
message(FATAL_ERROR "Failed to clone repository: '@git_repository@'")
@@ -44,6 +55,7 @@ execute_process(
checkout "@git_tag@" @git_checkout_explicit--@
WORKING_DIRECTORY "@work_dir@/@src_name@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '@git_tag@'")
@@ -56,6 +68,7 @@ if(init_submodules)
submodule update @git_submodules_recurse@ --init @git_submodules@
WORKING_DIRECTORY "@work_dir@/@src_name@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
endif()
if(error_code)
@@ -67,6 +80,7 @@ endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy "@gitclone_infofile@" "@gitclone_stampfile@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to copy script-last-run stamp file: '@gitclone_stampfile@'")

View File

@@ -3,12 +3,22 @@
cmake_minimum_required(VERSION 3.5)
# Even at VERBOSE level, we don't want to see the commands executed, but
# enabling them to be shown for DEBUG may be useful to help diagnose problems.
cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
if(active_log_level MATCHES "DEBUG|TRACE")
set(maybe_show_command "COMMAND_ECHO STDOUT")
else()
set(maybe_show_command "")
endif()
function(do_fetch)
message(VERBOSE "Fetching latest from the remote @git_remote_name@")
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git fetch --tags --force "@git_remote_name@"
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL LAST
${maybe_show_command}
)
endfunction()
@@ -34,6 +44,9 @@ if(head_sha STREQUAL "")
message(FATAL_ERROR "Failed to get the hash for HEAD:\n${error_msg}")
endif()
if("${can_fetch}" STREQUAL "")
set(can_fetch "@can_fetch_default@")
endif()
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git show-ref "@git_tag@"
@@ -97,7 +110,7 @@ else()
# because it can be confusing for users to see a failed git command.
# That failure is being handled here, so it isn't an error.
if(NOT error_msg STREQUAL "")
message(VERBOSE "${error_msg}")
message(DEBUG "${error_msg}")
endif()
do_fetch()
set(checkout_name "@git_tag@")
@@ -181,6 +194,7 @@ if(need_stash)
COMMAND "@git_EXECUTABLE@" --git-dir=.git stash save @git_stash_save_options@
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL ANY
${maybe_show_command}
)
endif()
@@ -189,6 +203,7 @@ if(git_update_strategy STREQUAL "CHECKOUT")
COMMAND "@git_EXECUTABLE@" --git-dir=.git checkout "${checkout_name}"
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL ANY
${maybe_show_command}
)
else()
execute_process(
@@ -203,6 +218,7 @@ else()
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git rebase --abort
WORKING_DIRECTORY "@work_dir@"
${maybe_show_command}
)
if(NOT git_update_strategy STREQUAL "REBASE_CHECKOUT")
@@ -211,6 +227,7 @@ else()
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
WORKING_DIRECTORY "@work_dir@"
${maybe_show_command}
)
endif()
message(FATAL_ERROR "\nFailed to rebase in: '@work_dir@'."
@@ -236,12 +253,14 @@ else()
${tag_name}
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL ANY
${maybe_show_command}
)
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git checkout "${checkout_name}"
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL ANY
${maybe_show_command}
)
endif()
endif()
@@ -252,27 +271,32 @@ if(need_stash)
COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
WORKING_DIRECTORY "@work_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
# Stash pop --index failed: Try again dropping the index
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git reset --hard --quiet
WORKING_DIRECTORY "@work_dir@"
${maybe_show_command}
)
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --quiet
WORKING_DIRECTORY "@work_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
# Stash pop failed: Restore previous state.
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git reset --hard --quiet ${head_sha}
WORKING_DIRECTORY "@work_dir@"
${maybe_show_command}
)
execute_process(
COMMAND "@git_EXECUTABLE@" --git-dir=.git stash pop --index --quiet
WORKING_DIRECTORY "@work_dir@"
${maybe_show_command}
)
message(FATAL_ERROR "\nFailed to unstash changes in: '@work_dir@'."
"\nYou will have to resolve the conflicts manually")
@@ -288,5 +312,6 @@ if(init_submodules)
submodule update @git_submodules_recurse@ --init @git_submodules@
WORKING_DIRECTORY "@work_dir@"
COMMAND_ERROR_IS_FATAL ANY
${maybe_show_command}
)
endif()

View File

@@ -5,16 +5,26 @@ cmake_minimum_required(VERSION 3.5)
if(EXISTS "@hgclone_stampfile@" AND EXISTS "@hgclone_infofile@" AND
"@hgclone_stampfile@" IS_NEWER_THAN "@hgclone_infofile@")
message(STATUS
message(VERBOSE
"Avoiding repeated hg clone, stamp file is up to date: "
"'@hgclone_stampfile@'"
)
return()
endif()
# Even at VERBOSE level, we don't want to see the commands executed, but
# enabling them to be shown for DEBUG may be useful to help diagnose problems.
cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
if(active_log_level MATCHES "DEBUG|TRACE")
set(maybe_show_command "COMMAND_ECHO STDOUT")
else()
set(maybe_show_command "")
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to remove directory: '@source_dir@'")
@@ -24,6 +34,7 @@ execute_process(
COMMAND "@hg_EXECUTABLE@" clone -U "@hg_repository@" "@src_name@"
WORKING_DIRECTORY "@work_dir@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to clone repository: '@hg_repository@'")
@@ -33,6 +44,7 @@ execute_process(
COMMAND "@hg_EXECUTABLE@" update @hg_tag@
WORKING_DIRECTORY "@work_dir@/@src_name@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '@hg_tag@'")
@@ -43,6 +55,7 @@ endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy "@hgclone_infofile@" "@hgclone_stampfile@"
RESULT_VARIABLE error_code
${maybe_show_command}
)
if(error_code)
message(FATAL_ERROR "Failed to copy script-last-run stamp file: '@hgclone_stampfile@'")

View File

@@ -764,7 +764,62 @@ function(_ep_get_git_submodules_recurse git_submodules_recurse)
endfunction()
function(_ep_add_script_commands script_var work_dir cmd)
# We only support a subset of what ep_replace_location_tags() handles
set(location_tags
SOURCE_DIR
SOURCE_SUBDIR
BINARY_DIR
TMP_DIR
DOWNLOAD_DIR
DOWNLOADED_FILE
)
# There can be multiple COMMANDs, but we have to split those up to
# one command per call to execute_process()
set(execute_process_cmd
"execute_process(\n"
" WORKING_DIRECTORY \"${work_dir}\"\n"
" COMMAND_ERROR_IS_FATAL LAST\n"
)
cmake_language(GET_MESSAGE_LOG_LEVEL active_log_level)
if(active_log_level MATCHES "VERBOSE|DEBUG|TRACE")
string(APPEND execute_process_cmd " COMMAND_ECHO STDOUT\n")
endif()
string(APPEND execute_process_cmd " COMMAND ")
string(APPEND ${script_var} "${execute_process_cmd}")
foreach(cmd_arg IN LISTS cmd)
if(cmd_arg STREQUAL "COMMAND")
string(APPEND ${script_var} "\n)\n${execute_process_cmd}")
else()
if(_EP_LIST_SEPARATOR)
string(REPLACE "${_EP_LIST_SEPARATOR}" "\\;" cmd_arg "${cmd_arg}")
endif()
foreach(dir IN LISTS location_tags)
string(REPLACE "<${dir}>" "${_EP_${dir}}" cmd_arg "${cmd_arg}")
endforeach()
string(APPEND ${script_var} " [====[${cmd_arg}]====]")
endif()
endforeach()
string(APPEND ${script_var} "\n)")
set(${script_var} "${${script_var}}" PARENT_SCOPE)
endfunction()
function(_ep_add_download_command name)
set(noValueOptions )
set(singleValueOptions
SCRIPT_FILE # These should only be used by FetchContent
DEPENDS_VARIABLE #
)
set(multiValueOptions )
cmake_parse_arguments(PARSE_ARGV 1 arg
"${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
)
# The various _EP_... variables mentioned here and throughout this function
# are expected to already have been set by the caller via a call to
# _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
@@ -787,6 +842,7 @@ function(_ep_add_download_command name)
# TODO: Perhaps file:// should be copied to download dir before extraction.
string(REGEX REPLACE "file://" "" url "${url}")
set(step_script_contents)
set(depends)
set(comment)
set(work_dir)
@@ -795,6 +851,14 @@ function(_ep_add_download_command name)
if(DEFINED _EP_DOWNLOAD_COMMAND)
set(work_dir ${download_dir})
set(method custom)
if(NOT "x${cmd}" STREQUAL "x" AND arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(cvs_repository)
set(method cvs)
find_package(CVS QUIET)
@@ -819,6 +883,13 @@ function(_ep_add_download_command name)
-d ${src_name}
${cvs_module}
)
if(arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(svn_repository)
set(method svn)
@@ -862,6 +933,13 @@ function(_ep_add_download_command name)
${svn_user_pw_args}
${src_name}
)
if(arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(git_repository)
set(method git)
@@ -928,8 +1006,9 @@ CMP0097=${_EP_CMP0097}
# create a cmake script to invoke as download command.
# The script will delete the source directory and then call git clone.
#
set(clone_script ${tmp_dir}/${name}-gitclone.cmake)
_ep_write_gitclone_script(
${tmp_dir}/${name}-gitclone.cmake
${clone_script}
${source_dir}
${GIT_EXECUTABLE}
${git_repository}
@@ -949,7 +1028,15 @@ CMP0097=${_EP_CMP0097}
"${tls_verify}"
)
set(comment "Performing download step (git clone) for '${name}'")
set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
set(cmd ${CMAKE_COMMAND}
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${clone_script}
)
if(arg_SCRIPT_FILE)
set(step_script_contents "include(\"${clone_script}\")")
list(APPEND depends ${clone_script})
endif()
elseif(hg_repository)
set(method hg)
@@ -978,8 +1065,9 @@ CMP0097=${_EP_CMP0097}
# create a cmake script to invoke as download command.
# The script will delete the source directory and then call hg clone.
#
set(clone_script ${tmp_dir}/${name}-hgclone.cmake)
_ep_write_hgclone_script(
${tmp_dir}/${name}-hgclone.cmake
${clone_script}
${source_dir}
${HG_EXECUTABLE}
${hg_repository}
@@ -990,7 +1078,15 @@ CMP0097=${_EP_CMP0097}
${stamp_dir}/${name}-hgclone-lastrun.txt
)
set(comment "Performing download step (hg clone) for '${name}'")
set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
set(cmd ${CMAKE_COMMAND}
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${clone_script}
)
if(arg_SCRIPT_FILE)
set(step_script_contents "include(\"${clone_script}\")")
list(APPEND depends ${clone_script})
endif()
elseif(url)
set(method url)
@@ -1045,9 +1141,21 @@ hash=${hash}
${CMAKE_COMMAND} -E rm -rf ${source_dir}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir}
)
if(arg_SCRIPT_FILE)
# While it may be tempting to implement the two operations directly
# with file(), the behavior is different. file(COPY) preserves input
# file timestamps, which we don't want. Therefore, still use the same
# external commands so that we get the same behavior.
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
else()
set(no_extract "${_EP_DOWNLOAD_NO_EXTRACT}")
string(APPEND extra_repo_info "no_extract=${no_extract}\n")
set(verify_script "${stamp_dir}/verify-${name}.cmake")
if("${url}" MATCHES "^[a-z]+://")
# TODO: Should download and extraction be different steps?
if("x${fname}" STREQUAL "x")
@@ -1097,9 +1205,15 @@ hash=${hash}
"${netrc_file}"
)
set(cmd
${CMAKE_COMMAND} -P "${download_script}"
${CMAKE_COMMAND}
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P "${download_script}"
COMMAND
)
if(arg_SCRIPT_FILE)
set(step_script_contents "include(\"${download_script}\")\n")
endif()
if (no_extract)
set(steps "download and verify")
else ()
@@ -1107,7 +1221,7 @@ hash=${hash}
endif ()
set(comment "Performing download step (${steps}) for '${name}'")
# already verified by 'download_script'
file(WRITE "${stamp_dir}/verify-${name}.cmake" "")
file(WRITE "${verify_script}" "")
# Rather than adding everything to the RepositoryInfo.txt file, it is
# more robust to just depend on the download script. That way, we will
@@ -1122,12 +1236,19 @@ hash=${hash}
endif ()
set(comment "Performing download step (${steps}) for '${name}'")
_ep_write_verifyfile_script(
"${stamp_dir}/verify-${name}.cmake"
"${verify_script}"
"${file}"
"${hash}"
)
endif()
list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake)
list(APPEND cmd ${CMAKE_COMMAND}
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${verify_script}
)
if(arg_SCRIPT_FILE)
string(APPEND step_script_contents "include(\"${verify_script}\")\n")
list(APPEND depends ${verify_script})
endif()
set(extract_timestamp "${_EP_DOWNLOAD_EXTRACT_TIMESTAMP}")
if(no_extract)
if(DEFINED _EP_DOWNLOAD_EXTRACT_TIMESTAMP)
@@ -1136,7 +1257,24 @@ hash=${hash}
"DOWNLOAD_NO_EXTRACT TRUE"
)
endif()
set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
if(arg_SCRIPT_FILE)
# There's no target to record the location of the downloaded file.
# Instead, we copy it to the source directory within the script,
# which is what FetchContent always does in this situation.
cmake_path(SET safe_file NORMALIZE "${file}")
cmake_path(GET safe_file FILENAME filename)
string(APPEND step_script_contents
"file(COPY_FILE\n"
" \"${file}\"\n"
" \"${source_dir}/${filename}\"\n"
" ONLY_IF_DIFFERENT\n"
" INPUT_MAY_BE_RECENT\n"
")"
)
list(APPEND depends ${source_dir}/${filename})
else()
set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
endif()
else()
if(NOT DEFINED _EP_DOWNLOAD_EXTRACT_TIMESTAMP)
# Default depends on policy CMP0135
@@ -1165,16 +1303,23 @@ hash=${hash}
else()
set(options "--touch")
endif()
set(extract_script "${stamp_dir}/extract-${name}.cmake")
_ep_write_extractfile_script(
"${stamp_dir}/extract-${name}.cmake"
"${extract_script}"
"${name}"
"${file}"
"${source_dir}"
"${options}"
)
list(APPEND cmd
COMMAND ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake
COMMAND ${CMAKE_COMMAND}
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${extract_script}
)
if(arg_SCRIPT_FILE)
string(APPEND step_script_contents "include(\"${extract_script}\")\n")
list(APPEND depends ${extract_script})
endif()
endif ()
endif()
else()
@@ -1194,6 +1339,9 @@ hash=${hash}
" * CVS_REPOSITORY and CVS_MODULE"
)
endif()
if(arg_SCRIPT_FILE)
set(step_script_contents "message(VERBOSE [[Using SOURCE_DIR as is]])")
endif()
endif()
# We use configure_file() to write the repo_info_file so that the file's
@@ -1207,6 +1355,20 @@ hash=${hash}
@ONLY
)
if(arg_SCRIPT_FILE)
set(step_name download)
configure_file(
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
"${arg_SCRIPT_FILE}"
@ONLY
)
set(${arg_DEPENDS_VARIABLE} "${depends}" PARENT_SCOPE)
return()
endif()
# Nothing below this point is applicable when we've been asked to put the
# download step in a script file (which is the FetchContent case).
if(_EP_LOG_DOWNLOAD)
set(log LOG 1)
else()
@@ -1253,6 +1415,16 @@ function(_ep_get_update_disconnected var name)
endfunction()
function(_ep_add_update_command name)
set(noValueOptions )
set(singleValueOptions
SCRIPT_FILE # These should only be used by FetchContent
DEPEND_VARIABLE #
)
set(multiValueOptions )
cmake_parse_arguments(PARSE_ARGV 1 arg
"${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
)
# The various _EP_... variables mentioned here and throughout this function
# are expected to already have been set by the caller via a call to
# _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
@@ -1280,7 +1452,13 @@ function(_ep_add_update_command name)
set(work_dir ${source_dir})
if(NOT "x${cmd}" STREQUAL "x")
set(always 1)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(cvs_repository)
if(NOT CVS_EXECUTABLE)
message(FATAL_ERROR "error: could not find cvs for update of ${name}")
@@ -1290,6 +1468,15 @@ function(_ep_add_update_command name)
set(cvs_tag "${_EP_CVS_TAG}")
set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
set(always 1)
if(arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(svn_repository)
if(NOT Subversion_SVN_EXECUTABLE)
message(FATAL_ERROR "error: could not find svn for update of ${name}")
@@ -1326,6 +1513,15 @@ function(_ep_add_update_command name)
${svn_user_pw_args}
)
set(always 1)
if(arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
elseif(git_repository)
# FetchContent gives us these directly, so don't try to recompute them
if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
@@ -1393,9 +1589,27 @@ function(_ep_add_update_command name)
"${tls_version}"
"${tls_verify}"
)
set(cmd ${CMAKE_COMMAND} -Dcan_fetch=YES -P ${update_script})
set(cmd_disconnected ${CMAKE_COMMAND} -Dcan_fetch=NO -P ${update_script})
set(cmd ${CMAKE_COMMAND}
-Dcan_fetch=YES
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${update_script}
)
set(cmd_disconnected ${CMAKE_COMMAND}
-Dcan_fetch=NO
-DCMAKE_MESSAGE_LOG_LEVEL=VERBOSE
-P ${update_script}
)
set(always 1)
if(arg_SCRIPT_FILE)
if(update_disconnected)
set(can_fetch_default NO)
else()
set(can_fetch_default YES)
endif()
set(step_script_contents "include(\"${update_script}\")")
endif()
elseif(hg_repository)
if(NOT HG_EXECUTABLE)
message(FATAL_ERROR "error: could not find hg for pull of ${name}")
@@ -1427,6 +1641,28 @@ Update to Mercurial >= 2.1.1.
)
set(cmd_disconnected ${HG_EXECUTABLE} update ${hg_tag})
set(always 1)
if(arg_SCRIPT_FILE)
# These commands are simple, and we know whether updates need to be
# disconnected or not for this case, so write them directly instead of
# forming them from "cmd" and "cmd_disconnected".
if(NOT update_disconnected)
string(APPEND step_script_contents
"execute_process(\n"
" WORKING_DIRECTORY \"${work_dir}\"\n"
" COMMAND_ERROR_IS_FATAL LAST\n"
" COMMAND \"${HG_EXECUTABLE}\" pull\n"
")"
)
endif()
string(APPEND step_script_contents
"execute_process(\n"
" WORKING_DIRECTORY \"${work_dir}\"\n"
" COMMAND_ERROR_IS_FATAL LAST\n"
" COMMAND \"${HG_EXECUTABLE}\" update \"${hg_tag}\"\n"
")"
)
endif()
endif()
# We use configure_file() to write the update_info_file so that the file's
@@ -1442,6 +1678,20 @@ Update to Mercurial >= 2.1.1.
@ONLY
)
if(arg_SCRIPT_FILE)
set(step_name update)
configure_file(
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
"${arg_SCRIPT_FILE}"
@ONLY
)
set(${arg_DEPENDS_VARIABLE} "${file_deps}" PARENT_SCOPE)
return()
endif()
# Nothing below this point is applicable when we've been asked to put the
# update step in a script file (which is the FetchContent case).
if(_EP_LOG_UPDATE)
set(log LOG 1)
else()
@@ -1499,6 +1749,15 @@ endfunction()
function(_ep_add_patch_command name)
set(noValueOptions )
set(singleValueOptions
SCRIPT_FILE # These should only be used by FetchContent
)
set(multiValueOptions )
cmake_parse_arguments(PARSE_ARGV 1 arg
"${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
)
# The various _EP_... variables mentioned here and throughout this function
# are expected to already have been set by the caller via a call to
# _ep_parse_arguments() or ep_parse_arguments_to_vars(). Other variables
@@ -1509,10 +1768,18 @@ function(_ep_add_patch_command name)
set(stamp_dir "${_EP_STAMP_DIR}")
set(cmd "${_EP_PATCH_COMMAND}")
set(step_script_contents "")
set(work_dir)
if(DEFINED _EP_PATCH_COMMAND)
set(work_dir ${source_dir})
if(arg_SCRIPT_FILE)
_ep_add_script_commands(
step_script_contents
"${work_dir}"
"${cmd}" # Must be a single quoted argument
)
endif()
endif()
# We use configure_file() to write the patch_info_file so that the file's
@@ -1524,6 +1791,19 @@ function(_ep_add_patch_command name)
@ONLY
)
if(arg_SCRIPT_FILE)
set(step_name patch)
configure_file(
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stepscript.cmake.in"
"${arg_SCRIPT_FILE}"
@ONLY
)
return()
endif()
# Nothing below this point is applicable when we've been asked to put the
# patch step in a script file (which is the FetchContent case).
if(_EP_LOG_PATCH)
set(log LOG 1)
else()

View File

@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.29)
message(VERBOSE "Executing @step_name@ step for @name@")
block(SCOPE_FOR VARIABLES)
@step_script_contents@
endblock()

View File

@@ -12,7 +12,7 @@ if(NOT EXISTS "@LOCAL@")
endif()
if("@ALGO@" STREQUAL "")
message(WARNING "File will not be verified since no URL_HASH specified")
message(WARNING "File cannot be verified since no URL_HASH specified")
return()
endif()
@@ -20,7 +20,7 @@ if("@EXPECT_VALUE@" STREQUAL "")
message(FATAL_ERROR "EXPECT_VALUE can't be empty")
endif()
message(STATUS "verifying file...
message(VERBOSE "verifying file...
file='@LOCAL@'")
file("@ALGO@" "@LOCAL@" actual_value)
@@ -34,4 +34,4 @@ does not match expected value
")
endif()
message(STATUS "verifying file... done")
message(VERBOSE "verifying file... done")