From e1b582cb4c58e61ef7b7e44f1756ff3fa9490d8a Mon Sep 17 00:00:00 2001 From: Arniiiii Date: Sat, 25 Jan 2025 00:06:54 +0000 Subject: [PATCH] Make CPM_DOWNLOAD_LOCATION overridable I found that useful if you use installed/placed somewhere CPM.cmake and want to use it. --- cmake/get_cpm.cmake | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake index 2a9d6c03..d218c410 100644 --- a/cmake/get_cpm.cmake +++ b/cmake/get_cpm.cmake @@ -1,24 +1,27 @@ # SPDX-License-Identifier: MIT # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors +if(NOT DEFINED CPM_DOWNLOAD_LOCATION) -set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) -set(CPM_HASH_SUM "CPM_HASH_SUM_PLACEHOLDER") + set(CPM_DOWNLOAD_VERSION 1.0.0-development-version) + set(CPM_HASH_SUM "CPM_HASH_SUM_PLACEHOLDER") -if(CPM_SOURCE_CACHE) - set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") -elseif(DEFINED ENV{CPM_SOURCE_CACHE}) - set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") -else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") -endif() + if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + endif() + + # Expand relative path. This is important if the provided path contains a tilde (~) + get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -# Expand relative path. This is important if the provided path contains a tilde (~) -get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} + ) -file(DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake - ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} -) +endif() include(${CPM_DOWNLOAD_LOCATION})