CMakeDownload.cmake.in 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. set(LY_ROOT_FOLDER "@LY_ROOT_FOLDER@")
  9. set(CMAKE_SCRIPT_MODE_FILE TRUE)
  10. include(@LY_ROOT_FOLDER@/cmake/3rdPartyPackages.cmake)
  11. if(EXISTS "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@")
  12. file(SHA256 "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@" hash_of_downloaded_file)
  13. if (NOT "${hash_of_downloaded_file}" STREQUAL "@CPACK_CMAKE_PACKAGE_HASH@")
  14. message(STATUS "CMake @CPACK_DESIRED_CMAKE_VERSION@ found at @LY_CMAKE_PACKAGE_DOWNLOAD_PATH@ but expected hash missmatches, re-downloading...")
  15. file(REMOVE "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@")
  16. else()
  17. message(STATUS "CMake @CPACK_DESIRED_CMAKE_VERSION@ found")
  18. endif()
  19. endif()
  20. if(NOT EXISTS "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@")
  21. # download it
  22. string(REPLACE "." ";" _version_components "@CPACK_DESIRED_CMAKE_VERSION@")
  23. list(GET _version_components 0 _major_version)
  24. list(GET _version_components 1 _minor_version)
  25. set(_url_version_tag "v${_major_version}.${_minor_version}")
  26. set(_package_url "https://cmake.org/files/${_url_version_tag}/@CPACK_CMAKE_PACKAGE_FILE@")
  27. message(STATUS "Downloading CMake @CPACK_DESIRED_CMAKE_VERSION@ for packaging...")
  28. download_file(
  29. URL ${_package_url}
  30. TARGET_FILE @LY_CMAKE_PACKAGE_DOWNLOAD_PATH@
  31. EXPECTED_HASH @CPACK_CMAKE_PACKAGE_HASH@
  32. RESULTS _results
  33. )
  34. list(GET _results 0 _status_code)
  35. if (${_status_code} EQUAL 0 AND EXISTS "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@")
  36. message(STATUS "CMake @CPACK_DESIRED_CMAKE_VERSION@ found")
  37. else()
  38. file(REMOVE "@LY_CMAKE_PACKAGE_DOWNLOAD_PATH@")
  39. list(REMOVE_AT _results 0)
  40. set(_error_message "An error occurred, code ${_status_code}. URL ${_package_url} - ${_results}")
  41. if(${_status_code} EQUAL 1)
  42. string(APPEND _error_message
  43. " Please double check the CPACK_CMAKE_PACKAGE_FILE and "
  44. "CPACK_CMAKE_PACKAGE_HASH properties before trying again.")
  45. endif()
  46. message(FATAL_ERROR ${_error_message})
  47. endif()
  48. endif()