33# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
44
55set (CPM_DOWNLOAD_VERSION 1.0.0-development-version )
6+ set (CPM_HASH_SUM "HASH_SUM_PLACEHOLDER" )
67
78if (CPM_SOURCE_CACHE)
89 set (CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE} /cpm/CPM_${CPM_DOWNLOAD_VERSION} .cmake" )
@@ -15,23 +16,20 @@ endif()
1516# Expand relative path. This is important if the provided path contains a tilde (~)
1617get_filename_component (CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE )
1718
18- function (download_cpm)
19- message (STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION} " )
20- file (DOWNLOAD
21- https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION} /CPM.cmake
22- ${CPM_DOWNLOAD_LOCATION}
23- )
24- endfunction ()
25-
26- if (NOT (EXISTS ${CPM_DOWNLOAD_LOCATION} ))
27- download_cpm()
19+ message (STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION} " )
20+ file (
21+ DOWNLOAD
22+ https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION} /CPM.cmake
23+ ${CPM_DOWNLOAD_LOCATION}
24+ STATUS CPM_DOWNLOAD_STATUS
25+ EXPECTED_HASH SHA256=${CPM_HASH_SUM}
26+ )
27+ list (GET CPM_DOWNLOAD_STATUS 0 CPM_DOWNLOAD_STATUS_CODE)
28+ list (GET CPM_DOWNLOAD_STATUS 1 CPM_DOWNLOAD_ERROR_MESSAGE)
29+ if (${CPM_DOWNLOAD_STATUS_CODE} EQUAL 0)
30+ message (STATUS "CPM: Download completed successfully." )
2831else ()
29- # resume download if it previously failed
30- file (READ ${CPM_DOWNLOAD_LOCATION} check)
31- if ("${check} " STREQUAL "" )
32- download_cpm()
33- endif ()
34- unset (check)
32+ message (FATAL_ERROR "CPM: Error occurred during download: ${CPM_DOWNLOAD_ERROR_MESSAGE} " )
3533endif ()
3634
3735include (${CPM_DOWNLOAD_LOCATION} )
0 commit comments