From b224ce280d76ff2bc45f57954630a3de275ec076 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 3 Aug 2022 18:22:50 -0400 Subject: [PATCH] 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 * Update cmake/CPM.cmake Co-authored-by: Lars Melchior * 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 --- cmake/CPM.cmake | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index f4e7e00..5e943ae 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -28,6 +28,23 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) +# the policy allows us to change options without caching +cmake_policy(SET CMP0077 NEW) +set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + +# the policy allows us to change set(CACHE) without caching +if(POLICY CMP0126) + cmake_policy(SET CMP0126 NEW) + set(CMAKE_POLICY_DEFAULT_CMP0126 NEW) +endif() + +# The policy uses the download time for timestamp, instead of the timestamp in the archive. This +# allows for proper rebuilds when a projects url changes +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) + set(CMAKE_POLICY_DEFAULT_CMP0135 NEW) +endif() + set(CURRENT_CPM_VERSION 1.0.0-development-version) get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH) @@ -477,6 +494,7 @@ endfunction() # Download and add a package from source function(CPMAddPackage) + list(LENGTH ARGN argnLength) if(argnLength EQUAL 1) cpm_parse_add_package_single_arg("${ARGN}" ARGN) @@ -906,16 +924,6 @@ function( set(addSubdirectoryExtraArgs "") endif() if(OPTIONS) - # the policy allows us to change options without caching - cmake_policy(SET CMP0077 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) - - # the policy allows us to change set(CACHE) without caching - if(POLICY CMP0126) - cmake_policy(SET CMP0126 NEW) - set(CMAKE_POLICY_DEFAULT_CMP0126 NEW) - endif() - foreach(OPTION ${OPTIONS}) cpm_parse_option("${OPTION}") set(${OPTION_KEY} "${OPTION_VALUE}")