summaryrefslogtreecommitdiff
path: root/Meta/CMake
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-25 18:36:40 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-26 00:22:53 +0000
commite805fce46e75113802e34144598327f9d73e7366 (patch)
treebc63a0de23a41ef61deb5f6526398366b21fec2c /Meta/CMake
parentb40308d0a4f6d228bbf01c1d5795967dce8df804 (diff)
downloadserenity-e805fce46e75113802e34144598327f9d73e7366.zip
Meta: Add a CMake function to download remote files during the build
This function will handle download failures. It doesn't support hashing for integrity yet, but if the download times out or otherwise fails, the build itself will fail. But default, file(DOWNLOAD) in CMake doesn't fail the build; we must pass in and check a STATUS variable.
Diffstat (limited to 'Meta/CMake')
-rw-r--r--Meta/CMake/utils.cmake16
1 files changed, 16 insertions, 0 deletions
diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake
index caee954fcd..6cddf3cb5a 100644
--- a/Meta/CMake/utils.cmake
+++ b/Meta/CMake/utils.cmake
@@ -194,3 +194,19 @@ function(invoke_generator name generator version_file prefix header implementati
add_custom_target("generate_${prefix}${name}" DEPENDS "${header}" "${implementation}")
add_dependencies(all_generated "generate_${prefix}${name}")
endfunction()
+
+function(download_file url path)
+ if (NOT EXISTS "${path}")
+ get_filename_component(file "${path}" NAME)
+ message(STATUS "Downloading file ${file} from ${url}")
+
+ file(DOWNLOAD "${url}" "${path}" INACTIVITY_TIMEOUT 10 STATUS download_result)
+ list(GET download_result 0 status_code)
+ list(GET download_result 1 error_message)
+
+ if (NOT status_code EQUAL 0)
+ file(REMOVE "${path}")
+ message(FATAL_ERROR "Failed to download ${url}: ${error_message}")
+ endif()
+ endif()
+endfunction()