DownloadFile.cmake 829 B

12345678910111213141516171819202122232425262728293031
  1. #
  2. # Use 'cmake -Dremote=${url} -Dlocal=${filename} -Dtimeout=${seconds}
  3. # -P DownloadFile.cmake' to call this script...
  4. #
  5. if(NOT DEFINED remote)
  6. message(FATAL_ERROR "error: required variable 'remote' not defined...")
  7. endif()
  8. if(NOT DEFINED local)
  9. message(FATAL_ERROR "error: required variable 'local' not defined...")
  10. endif()
  11. if(NOT DEFINED timeout)
  12. set(timeout 30)
  13. endif(NOT DEFINED timeout)
  14. message(STATUS "info: downloading '${remote}'...")
  15. file(DOWNLOAD "${remote}" "${local}" TIMEOUT ${timeout} STATUS status LOG log)
  16. list(GET status 0 status_code)
  17. list(GET status 1 status_string)
  18. if(NOT status_code EQUAL 0)
  19. message(FATAL_ERROR "error: download of '${remote}' failed
  20. status_code: ${status_code}
  21. status_string: ${status_string}
  22. log: ${log}
  23. ")
  24. endif()
  25. message(STATUS "info: done downloading '${remote}'...")