summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-02-22 16:05:39 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-02-22 16:05:45 (GMT)
commite9efa04d8da2b17f34a70d7b4be0d91a1c7574dc (patch)
treed97b8b6e4f1e63cc1345f4073c41654d0efa57b0 /Modules
parent33d93089ef25d39e335ccc63c9e27c91a39e7bb1 (diff)
parentb0da6712439fe44d84a158dceb5f946cc30ef68a (diff)
downloadCMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.zip
CMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.tar.gz
CMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.tar.bz2
Merge topic 'fix-IS_NEWER_THAN-usage' into release-3.20
b0da671243 FetchContent: Don't update timestamps if files don't change 404cddb7bb ExternalProject: Fix misuse of IS_NEWER_THAN in timestamp checks Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5825
Diffstat (limited to 'Modules')
-rw-r--r--Modules/ExternalProject.cmake26
-rw-r--r--Modules/ExternalProject/gitclone.cmake.in3
-rw-r--r--Modules/ExternalProject/hgclone.cmake.in3
3 files changed, 26 insertions, 6 deletions
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 4a9809b..987b69a 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -2579,11 +2579,24 @@ function(_ep_write_command_script
endif()
if(genex_supported)
- # Only written at generation phase
+ # Only written at generation phase. This will only change the file's
+ # timestamp if the contents change.
file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_content}")
else()
- # Written immediately, needed if script has to be invoked in configure phase
- file(WRITE "${script_filename}" "${script_content}")
+ # Update the file immediately, needed if script has to be invoked in the
+ # configure phase (e.g. via FetchContent). We need to be careful to avoid
+ # updating the timestamp if the file contents don't change. The file(WRITE)
+ # command always updates the file, so avoid it if we don't need to call it.
+ set(doWrite TRUE)
+ if(EXISTS "${script_filename}")
+ file(READ "${script_filename}" existing_content)
+ if(existing_content STREQUAL script_content)
+ set(doWrite FALSE)
+ endif()
+ endif()
+ if(doWrite)
+ file(WRITE "${script_filename}" "${script_content}")
+ endif()
endif()
endfunction()
@@ -3916,7 +3929,12 @@ function(_ep_do_preconfigure_steps_now name)
if(NOT need_to_run)
foreach(dep_file ${script_file} ${_EPdepends_${STEP}})
- if(NOT EXISTS ${dep_file} OR ${dep_file} IS_NEWER_THAN ${stamp_file})
+ # IS_NEWER_THAN is also true if the timestamps are the same. On some
+ # file systems, we only have second resolution timestamps and the
+ # likelihood of having the same timestamp is high. Use the negative
+ # form to ensure we actually get a true "is newer than" test.
+ if(NOT EXISTS ${dep_file} OR
+ NOT ${stamp_file} IS_NEWER_THAN ${dep_file})
set(need_to_run TRUE)
break()
endif()
diff --git a/Modules/ExternalProject/gitclone.cmake.in b/Modules/ExternalProject/gitclone.cmake.in
index a2e900c..edbdd72 100644
--- a/Modules/ExternalProject/gitclone.cmake.in
+++ b/Modules/ExternalProject/gitclone.cmake.in
@@ -7,7 +7,8 @@ set(quiet "@quiet@")
set(script_dir "@CMAKE_CURRENT_FUNCTION_LIST_DIR@/ExternalProject")
include(${script_dir}/captured_process_setup.cmake)
-if(NOT "@gitclone_infofile@" IS_NEWER_THAN "@gitclone_stampfile@")
+if(EXISTS "@gitclone_stampfile@" AND EXISTS "@gitclone_infofile@" AND
+ "@gitclone_stampfile@" IS_NEWER_THAN "@gitclone_infofile@")
if(NOT quiet)
message(STATUS
"Avoiding repeated git clone, stamp file is up to date: "
diff --git a/Modules/ExternalProject/hgclone.cmake.in b/Modules/ExternalProject/hgclone.cmake.in
index 5561955..9a574d2 100644
--- a/Modules/ExternalProject/hgclone.cmake.in
+++ b/Modules/ExternalProject/hgclone.cmake.in
@@ -7,7 +7,8 @@ set(quiet "@quiet@")
set(script_dir "@CMAKE_CURRENT_FUNCTION_LIST_DIR@/ExternalProject")
include(${script_dir}/captured_process_setup.cmake)
-if(NOT "@hgclone_infofile@" IS_NEWER_THAN "@hgclone_stampfile@")
+if(EXISTS "@hgclone_stampfile@" AND EXISTS "@hgclone_infofile@" AND
+ "@hgclone_stampfile@" IS_NEWER_THAN "@hgclone_infofile@")
if(NOT quiet)
message(STATUS
"Avoiding repeated hg clone, stamp file is up to date: "