[CMake] Print download error (#4529)
authorSaulo Aldighieri Moraes/Security R&D /SRBR/Assistant Engineer/삼성전자 <s.moraes@samsung.com>
Mon, 4 Mar 2019 02:07:15 +0000 (23:07 -0300)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 4 Mar 2019 02:07:15 +0000 (11:07 +0900)
Improvement on cmake script to print detailed status message when download fails.
Example of new message format:

[ 11s] CMake Error at cmake/modules/ExternalSourceTools.cmake:39 (message):
[ 11s] error: downloading
[ 11s] 'https://github.com/ARM-software/ComputeLibrary/archive/v18.11.tar.gz'
[ 11s] failed
[ 11s]
[ 11s] status_code: 1
[ 11s] status_string: "Unsupported protocol"
[ 11s] log: Protocol "https" not supported or disabled in libcurl
[ 11s]
[ 11s] Closing connection -1

Signed-off-by: Saulo A. Moraes <s.moraes@samsung.com>
cmake/modules/ExternalSourceTools.cmake

index 76ebb55..9aa5372 100644 (file)
@@ -28,7 +28,19 @@ function(ExternalSource_Download PREFIX URL)
     file(MAKE_DIRECTORY "${TMP_DIR}")
 
     message("-- Download ${PREFIX} from ${URL}")
-    file(DOWNLOAD ${URL} "${DOWNLOAD_PATH}")
+    file(DOWNLOAD ${URL} "${DOWNLOAD_PATH}"
+                  STATUS status
+                  LOG log)
+
+    list(GET status 0 status_code)
+    list(GET status 1 status_string)
+
+    if(NOT status_code EQUAL 0)
+      message(FATAL_ERROR "error: downloading '${URL}' failed
+              status_code: ${status_code}
+              status_string: ${status_string}
+              log: ${log}")
+    endif()
     message("-- Download ${PREFIX} from ${URL} - done")
 
     message("-- Extract ${PREFIX}")