mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
The mkdir, download, update and patch steps are used by FetchContent during the configure phase of the main build. Because these steps need a target, this has so far required a sub-build to be set up. The changes here factor out the preparation of the scripts from the creation of the targets, allowing future work to leverage these steps without a sub-build (see #21703). As part of the refactoring, some rationalisation of the stamp files, repository info files and script names was done to make things more consistent between download methods and step implementations. Every download method now records its own specific repository info in a file and that file is a dependency of the download step. The source directory is also written to that file, so if the SOURCE_DIR changes, the download will be retriggered (the existing implementation fails in this scenario). Each download method now also has just one driver script that implements the whole step (it may pull in other scripts to do its task though). The patch step gained support for USES_TERMINAL as a result of generalising the implementation for custom commands. Fixes: #21748
46 lines
1.3 KiB
CMake
46 lines
1.3 KiB
CMake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
if(NOT "@hgclone_infofile@" IS_NEWER_THAN "@hgclone_stampfile@")
|
|
message(STATUS "Avoiding repeated hg clone, stamp file is up to date: '@hgclone_stampfile@'")
|
|
return()
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E rm -rf "@source_dir@"
|
|
RESULT_VARIABLE error_code
|
|
)
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to remove directory: '@source_dir@'")
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND "@hg_EXECUTABLE@" clone -U "@hg_repository@" "@src_name@"
|
|
WORKING_DIRECTORY "@work_dir@"
|
|
RESULT_VARIABLE error_code
|
|
)
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to clone repository: '@hg_repository@'")
|
|
endif()
|
|
|
|
execute_process(
|
|
COMMAND "@hg_EXECUTABLE@" update @hg_tag@
|
|
WORKING_DIRECTORY "@work_dir@/@src_name@"
|
|
RESULT_VARIABLE error_code
|
|
)
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to checkout tag: '@hg_tag@'")
|
|
endif()
|
|
|
|
# Complete success, update the script-last-run stamp file:
|
|
#
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} -E copy "@hgclone_infofile@" "@hgclone_stampfile@"
|
|
RESULT_VARIABLE error_code
|
|
)
|
|
if(error_code)
|
|
message(FATAL_ERROR "Failed to copy script-last-run stamp file: '@hgclone_stampfile@'")
|
|
endif()
|