Skip to content

Commit 1184a6e

Browse files
author
haenkel
authored
get_cpm: Recover from failed download (#426)
* get_cpm: Recover from failed download If the download fails during the cmake config step an empty `CPM_<version>.cmake` file is created. So far the script only checks the files existence, so there is no second try until the empty file is deleted manually. This adds a check if the file is empty and resumes the download on next config if it is. * More descriptive function name
1 parent c53417b commit 1184a6e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmake/get_cpm.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@ endif()
1010

1111
# Expand relative path. This is important if the provided path contains a tilde (~)
1212
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
13-
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
13+
14+
function(download_cpm)
1415
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
1516
file(DOWNLOAD
1617
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
1718
${CPM_DOWNLOAD_LOCATION}
1819
)
20+
endfunction()
21+
22+
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
23+
download_cpm()
24+
else()
25+
# resume download if it previously failed
26+
file(READ ${CPM_DOWNLOAD_LOCATION} check)
27+
if("${check}" STREQUAL "")
28+
download_cpm()
29+
endif()
1930
endif()
2031

2132
include(${CPM_DOWNLOAD_LOCATION})

0 commit comments

Comments
 (0)