HPCW 3.0
Loading...
Searching...
No Matches
fetchURL.cmake
Go to the documentation of this file.
1# Copyright (c) 2020 - 2024 David Guibert
2# All rights reserved.
3#
4# SPDX-License-Identifier: Apache-2.0
5
6# https://cmake.org/cmake/help/latest/module/ExternalData.html#custom-fetch-scripts
7#ExternalData_CUSTOM_LOCATION
8# When a custom fetch script is loaded, this variable is set to the location part of the URL, which will contain the substituted hash algorithm name and content hash value.
9#
10#ExternalData_CUSTOM_FILE
11# When a custom fetch script is loaded, this variable is set to the full path to a file in which the script must store the fetched content. The name of the file is unspecified and should not be interpreted in any way.
12# The custom fetch script is expected to store fetched content in the file or set a variable:
13# ExternalData_CUSTOM_ERROR
14# When a custom fetch script fails to fetch the requested content, it must set this variable to a short one-line message describing the reason for failure.
15
16cmake_path(GET ExternalData_CUSTOM_SCRIPT_fetchURL PARENT_PATH SOURCE_DIR)
17include(${SOURCE_DIR}/../versions.cmake)
18
19list(FIND fetchurl_list ${ExternalData_CUSTOM_LOCATION} hash_pos)
20
21math(EXPR url_pos "${hash_pos} + 1")
22
23if(url_pos GREATER "0")
24 list(GET fetchurl_list ${url_pos} url)
25 list(GET fetchurl_list ${hash_pos} hash)
26 string(REGEX REPLACE "/" "=" hash "${hash}")
27
28 message(STATUS "fetchURL: ${url}...")
29 file(DOWNLOAD ${url} ${ExternalData_CUSTOM_FILE} STATUS status SHOW_PROGRESS TIMEOUT 0 EXPECTED_HASH ${hash})
30
31 list(GET status 0 code)
32 if(NOT code EQUAL 0)
33 list(GET status 1 ExternalData_CUSTOM_ERROR)
34 endif()
35else()
36 message(DEBUG "FetchURL: unknown hash ${ExternalData_CUSTOM_LOCATION}")
37
38 # touch the file to allow other custom scripts (if any)
39 cmake_path(GET ExternalData_CUSTOM_FILE PARENT_PATH STORE_DIR)
40 file(MAKE_DIRECTORY ${STORE_DIR})
41 file(TOUCH ${ExternalData_CUSTOM_FILE})
42endif()