Skip to content

Commit b224ce2

Browse files
Timestamps for URL downloads match the download time (#372)
* Timestamps for URL downloads match the download time By enabling CMake policy 135 we ensure that extracted files timestamp match that of the download time, instead of when the archive is created. This makes sure that if the URL changes to an older version we still rebuild everything as the timestamp stays newer. * Introduce CPM_SET_RECOMMENDED_CMAKE_POLICIES Enabling CPM_SET_RECOMMENDED_CMAKE_POLICIES will establish defaults for all CMake policies so that both CPM and added projects operate inline with CPM recommended best practices. * Fix style issues found by ci * Update README.md Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> * Update cmake/CPM.cmake Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com> * Set policies when CPM.cmake is included * CPM_SET_RECOMMENDED_CMAKE_POLICIES default is ON * Correct failing CI tests * CPM.cmake always sets policies to on Co-authored-by: Lars Melchior <TheLartians@users.noreply.github.com>
1 parent 49af958 commit b224ce2

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

cmake/CPM.cmake

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@
2828

2929
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
3030

31+
# the policy allows us to change options without caching
32+
cmake_policy(SET CMP0077 NEW)
33+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
34+
35+
# the policy allows us to change set(CACHE) without caching
36+
if(POLICY CMP0126)
37+
cmake_policy(SET CMP0126 NEW)
38+
set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
39+
endif()
40+
41+
# The policy uses the download time for timestamp, instead of the timestamp in the archive. This
42+
# allows for proper rebuilds when a projects url changes
43+
if(POLICY CMP0135)
44+
cmake_policy(SET CMP0135 NEW)
45+
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
46+
endif()
47+
3148
set(CURRENT_CPM_VERSION 1.0.0-development-version)
3249

3350
get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
@@ -477,6 +494,7 @@ endfunction()
477494

478495
# Download and add a package from source
479496
function(CPMAddPackage)
497+
480498
list(LENGTH ARGN argnLength)
481499
if(argnLength EQUAL 1)
482500
cpm_parse_add_package_single_arg("${ARGN}" ARGN)
@@ -906,16 +924,6 @@ function(
906924
set(addSubdirectoryExtraArgs "")
907925
endif()
908926
if(OPTIONS)
909-
# the policy allows us to change options without caching
910-
cmake_policy(SET CMP0077 NEW)
911-
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
912-
913-
# the policy allows us to change set(CACHE) without caching
914-
if(POLICY CMP0126)
915-
cmake_policy(SET CMP0126 NEW)
916-
set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
917-
endif()
918-
919927
foreach(OPTION ${OPTIONS})
920928
cpm_parse_option("${OPTION}")
921929
set(${OPTION_KEY} "${OPTION_VALUE}")

0 commit comments

Comments
 (0)