[build] Add error message when downloading files in CMake (#5593)

CMake's file(DOWNLOAD) function fails silently, leading to an error occurring due to a missing file later in the build. This fails quickly and produces a better error message.
This commit is contained in:
Ryan Blue
2023-08-31 00:16:48 -04:00
committed by GitHub
parent 4e0d785356
commit 45e7720ec1
3 changed files with 23 additions and 10 deletions

View File

@@ -0,0 +1,11 @@
macro(download_and_check source destination)
file(DOWNLOAD ${source} ${destination} STATUS download_status)
list(GET download_status 0 status_code)
list(GET download_status 1 status_message)
if(${status_code} EQUAL 0)
message(VERBOSE "Download of \"${source}\" successful.")
else()
message(FATAL_ERROR "Download of \"${source}\" failed: ${status_message}")
endif()
endmacro()