mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-21 23:00:50 +08:00
@@ -1159,9 +1159,12 @@ function(FetchContent_Declare contentName)
|
|||||||
|
|
||||||
set(options "")
|
set(options "")
|
||||||
set(oneValueArgs
|
set(oneValueArgs
|
||||||
|
SVN_REPOSITORY
|
||||||
|
DOWNLOAD_NO_EXTRACT
|
||||||
|
DOWNLOAD_EXTRACT_TIMESTAMP
|
||||||
|
URL
|
||||||
BINARY_DIR
|
BINARY_DIR
|
||||||
SOURCE_DIR
|
SOURCE_DIR
|
||||||
SVN_REPOSITORY
|
|
||||||
)
|
)
|
||||||
set(multiValueArgs "")
|
set(multiValueArgs "")
|
||||||
|
|
||||||
@@ -1188,13 +1191,47 @@ function(FetchContent_Declare contentName)
|
|||||||
string(SHA1 urlSHA ${ARG_SVN_REPOSITORY})
|
string(SHA1 urlSHA ${ARG_SVN_REPOSITORY})
|
||||||
string(SUBSTRING ${urlSHA} 0 7 urlSHA)
|
string(SUBSTRING ${urlSHA} 0 7 urlSHA)
|
||||||
string(APPEND ARG_SOURCE_DIR "-${urlSHA}")
|
string(APPEND ARG_SOURCE_DIR "-${urlSHA}")
|
||||||
list(PREPEND ARG_UNPARSED_ARGUMENTS SVN_REPOSITORY "${ARG_SVN_REPOSITORY}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(PREPEND ARG_UNPARSED_ARGUMENTS
|
# The ExternalProject_Add() call in the sub-build won't see the CMP0135
|
||||||
SOURCE_DIR "${ARG_SOURCE_DIR}"
|
# policy setting of our caller. Work out if that policy will be needed and
|
||||||
BINARY_DIR "${ARG_BINARY_DIR}"
|
# explicitly set the relevant option if not already provided. The condition
|
||||||
|
# here is essentially an abbreviated version of the logic in
|
||||||
|
# ExternalProject's _ep_add_download_command() function.
|
||||||
|
if(ARG_URL AND
|
||||||
|
NOT IS_DIRECTORY "${ARG_URL}" AND
|
||||||
|
NOT ARG_DOWNLOAD_NO_EXTRACT AND
|
||||||
|
NOT DEFINED ARG_DOWNLOAD_EXTRACT_TIMESTAMP)
|
||||||
|
cmake_policy(GET CMP0135 _FETCHCONTENT_CMP0135
|
||||||
|
PARENT_SCOPE # undocumented, do not use outside of CMake
|
||||||
)
|
)
|
||||||
|
if(_FETCHCONTENT_CMP0135 STREQUAL "")
|
||||||
|
message(AUTHOR_WARNING
|
||||||
|
"The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy "
|
||||||
|
"CMP0135 is not set. The policy's OLD behavior will be used. "
|
||||||
|
"When using a URL download, the timestamps of extracted files "
|
||||||
|
"should preferably be that of the time of extraction, otherwise "
|
||||||
|
"code that depends on the extracted contents might not be "
|
||||||
|
"rebuilt if the URL changes. The OLD behavior preserves the "
|
||||||
|
"timestamps from the archive instead, but this is usually not "
|
||||||
|
"what you want. Update your project to the NEW behavior or "
|
||||||
|
"specify the DOWNLOAD_EXTRACT_TIMESTAMP option with a value of "
|
||||||
|
"true to avoid this robustness issue."
|
||||||
|
)
|
||||||
|
set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
|
||||||
|
elseif(_FETCHCONTENT_CMP0135 STREQUAL "NEW")
|
||||||
|
set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP FALSE)
|
||||||
|
else()
|
||||||
|
set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add back in the keyword args we pulled out and potentially tweaked/added
|
||||||
|
foreach(key IN LISTS oneValueArgs)
|
||||||
|
if(DEFINED ARG_${key})
|
||||||
|
list(PREPEND ARG_UNPARSED_ARGUMENTS ${key} "${ARG_${key}}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
set(__argsQuoted)
|
set(__argsQuoted)
|
||||||
foreach(__item IN LISTS ARG_UNPARSED_ARGUMENTS)
|
foreach(__item IN LISTS ARG_UNPARSED_ARGUMENTS)
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
|
#==============================================================================
|
||||||
|
# ExternalProject
|
||||||
|
#==============================================================================
|
||||||
|
set(stamp_dir "${CMAKE_CURRENT_BINARY_DIR}/stamps-ep")
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
|
|
||||||
set(stamp_dir "${CMAKE_CURRENT_BINARY_DIR}/stamps")
|
|
||||||
|
|
||||||
ExternalProject_Add(fake_ext_proj
|
ExternalProject_Add(fake_ext_proj
|
||||||
# We don't actually do a build, so we never try to download from this URL
|
# We don't actually do a build, so we never try to download from this URL
|
||||||
URL https://example.com/something.zip
|
URL https://example.com/something.zip
|
||||||
@@ -12,7 +13,33 @@ ExternalProject_Add(fake_ext_proj
|
|||||||
set(extraction_script "${stamp_dir}/extract-fake_ext_proj.cmake")
|
set(extraction_script "${stamp_dir}/extract-fake_ext_proj.cmake")
|
||||||
file(STRINGS "${extraction_script}" results REGEX "--touch")
|
file(STRINGS "${extraction_script}" results REGEX "--touch")
|
||||||
if("${results}" STREQUAL "")
|
if("${results}" STREQUAL "")
|
||||||
message(STATUS "Using timestamps from archive")
|
message(STATUS "ExternalProject: Using timestamps from archive")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Using extraction time for the timestamps")
|
message(STATUS "ExternalProject: Using extraction time for the timestamps")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#==============================================================================
|
||||||
|
# FetchContent
|
||||||
|
#==============================================================================
|
||||||
|
set(stamp_dir "${CMAKE_CURRENT_BINARY_DIR}/stamps-fc")
|
||||||
|
set(archive_file ${CMAKE_CURRENT_BINARY_DIR}/test_archive.7z)
|
||||||
|
file(ARCHIVE_CREATE
|
||||||
|
OUTPUT ${archive_file}
|
||||||
|
PATHS ${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
FORMAT 7zip
|
||||||
|
)
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(fake_fc_proj
|
||||||
|
URL file://${archive_file}
|
||||||
|
STAMP_DIR ${stamp_dir}
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(fake_fc_proj)
|
||||||
|
|
||||||
|
# Report whether the --touch option was added to the extraction script
|
||||||
|
set(extraction_script "${stamp_dir}/extract-fake_fc_proj-populate.cmake")
|
||||||
|
file(STRINGS "${extraction_script}" results REGEX "--touch")
|
||||||
|
if("${results}" STREQUAL "")
|
||||||
|
message(STATUS "FetchContent: Using timestamps from archive")
|
||||||
|
else()
|
||||||
|
message(STATUS "FetchContent: Using extraction time for the timestamps")
|
||||||
endif()
|
endif()
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
Using extraction time for the timestamps
|
-- ExternalProject: Using extraction time for the timestamps
|
||||||
|
-- FetchContent: Using extraction time for the timestamps
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
Using timestamps from archive
|
-- ExternalProject: Using timestamps from archive
|
||||||
|
-- FetchContent: Using timestamps from archive
|
||||||
|
@@ -8,3 +8,14 @@ CMake Warning \(dev\) at .*/Modules/ExternalProject.cmake:[0-9]+ \(message\):
|
|||||||
what you want\. Update your project to the NEW behavior or specify the
|
what you want\. Update your project to the NEW behavior or specify the
|
||||||
DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
|
DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
|
||||||
robustness issue\.
|
robustness issue\.
|
||||||
|
.*
|
||||||
|
CMake Warning \(dev\) at .*/Modules/FetchContent.cmake:[0-9]+ \(message\):
|
||||||
|
The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
|
||||||
|
not set\. The policy's OLD behavior will be used\. When using a URL
|
||||||
|
download, the timestamps of extracted files should preferably be that of
|
||||||
|
the time of extraction, otherwise code that depends on the extracted
|
||||||
|
contents might not be rebuilt if the URL changes\. The OLD behavior
|
||||||
|
preserves the timestamps from the archive instead, but this is usually not
|
||||||
|
what you want\. Update your project to the NEW behavior or specify the
|
||||||
|
DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
|
||||||
|
robustness issue\.
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
Using timestamps from archive
|
-- ExternalProject: Using timestamps from archive
|
||||||
|
-- FetchContent: Using timestamps from archive
|
||||||
|
Reference in New Issue
Block a user