123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #
- # Copyright (c) Contributors to the Open 3D Engine Project.
- # For complete copyright and license terms please see the LICENSE at the root of this distribution.
- #
- # SPDX-License-Identifier: Apache-2.0 OR MIT
- #
- #
- if(NOT PAL_TRAIT_BUILD_CPACK_SUPPORTED)
- return()
- endif()
- # public facing options will be used for conversion into cpack specific ones below.
- set(LY_INSTALLER_LICENSE_URL "" CACHE STRING "Optionally embed a link to the license instead of raw text")
- set(LY_INSTALLER_AUTO_GEN_TAG OFF CACHE BOOL
- "Automatically generate a build tag based on the git repo and append it to the download/upload URLs. \
- Format: <branch>/<commit_date>-<commit_hash>"
- )
- set(LY_INSTALLER_DOWNLOAD_URL "" CACHE STRING
- "Base URL embedded into the installer to download additional artifacts, the host target and version \
- number will automatically appended as '<version>/<host>'. If LY_INSTALLER_AUTO_GEN_TAG is set, the \
- full URL format will be: <base_url>/<build_tag>/<host>"
- )
- set(LY_INSTALLER_UPLOAD_URL "" CACHE STRING
- "Base URL used to upload the installer artifacts after generation, the host target and version number \
- will automatically appended as '<version>/<host>'. If LY_INSTALLER_AUTO_GEN_TAG is set, the full URL \
- format will be: <base_url>/<build_tag>/<host>. Can also be set via LY_INSTALLER_UPLOAD_URL environment \
- variable. Currently only accepts S3 URLs e.g. s3://<bucket>/<prefix>"
- )
- set(LY_INSTALLER_AWS_PROFILE "" CACHE STRING
- "AWS CLI profile for uploading artifacts. Can also be set via LY_INSTALLER_AWS_PROFILE environment variable."
- )
- set(CPACK_DESIRED_CMAKE_VERSION 3.20.2)
- # set all common cpack variable overrides first so they can be accessible via configure_file
- # when the platform specific settings are applied below. additionally, any variable with
- # the "CPACK_" prefix will automatically be cached for use in any phase of cpack namely
- # pre/post build
- set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
- set(CPACK_PACKAGE_FULL_NAME "Open3D Engine")
- set(CPACK_PACKAGE_VENDOR "O3DE Binary Project a Series of LF Projects, LLC")
- set(CPACK_PACKAGE_VERSION "${LY_VERSION_STRING}")
- set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Installation Tool")
- string(TOLOWER "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}" CPACK_PACKAGE_FILE_NAME)
- set(DEFAULT_LICENSE_NAME "Apache-2.0")
- set(DEFAULT_LICENSE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
- set(CPACK_RESOURCE_FILE_LICENSE ${DEFAULT_LICENSE_FILE})
- set(CPACK_LICENSE_URL ${LY_INSTALLER_LICENSE_URL})
- set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}/${CPACK_PACKAGE_VERSION}")
- # neither of the SOURCE_DIR variables equate to anything during execution of pre/post build scripts
- set(CPACK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
- set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR}/_CPack) # to match other CPack out dirs
- # this config file allows the dynamic setting of cpack variables at cpack-time instead of cmake configure
- set(CPACK_PROJECT_CONFIG_FILE ${CPACK_SOURCE_DIR}/PackagingConfig.cmake)
- set(CPACK_AUTO_GEN_TAG ${LY_INSTALLER_AUTO_GEN_TAG})
- # attempt to apply platform specific settings
- ly_get_absolute_pal_filename(pal_dir ${CPACK_SOURCE_DIR}/Platform/${PAL_HOST_PLATFORM_NAME})
- include(${pal_dir}/Packaging_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
- # if we get here and the generator hasn't been set, then a non fatal error occurred disabling packaging support
- if(NOT CPACK_GENERATOR)
- return()
- endif()
- if(${CPACK_DESIRED_CMAKE_VERSION} VERSION_LESS ${CMAKE_MINIMUM_REQUIRED_VERSION})
- message(FATAL_ERROR
- "The desired version of CMake to be included in the package is "
- "below the minimum required version of CMake to run")
- endif()
- # pull down the desired copy of CMake so it can be included in the package
- if(NOT (CPACK_CMAKE_PACKAGE_FILE AND CPACK_CMAKE_PACKAGE_HASH))
- message(FATAL_ERROR
- "Packaging is missing one or more following properties required to include CMake: "
- " CPACK_CMAKE_PACKAGE_FILE, CPACK_CMAKE_PACKAGE_HASH")
- endif()
- set(_cmake_package_dest ${CPACK_BINARY_DIR}/${CPACK_CMAKE_PACKAGE_FILE})
- if(EXISTS ${_cmake_package_dest})
- file(SHA256 ${_cmake_package_dest} hash_of_downloaded_file)
- if (NOT "${hash_of_downloaded_file}" STREQUAL "${CPACK_CMAKE_PACKAGE_HASH}")
- message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found at ${_cmake_package_dest} but expected hash missmatches, re-downloading...")
- file(REMOVE ${_cmake_package_dest})
- else()
- message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found")
- endif()
- endif()
- if(NOT EXISTS ${_cmake_package_dest})
- # download it
- string(REPLACE "." ";" _version_componets "${CPACK_DESIRED_CMAKE_VERSION}")
- list(GET _version_componets 0 _major_version)
- list(GET _version_componets 1 _minor_version)
- set(_url_version_tag "v${_major_version}.${_minor_version}")
- set(_package_url "https://cmake.org/files/${_url_version_tag}/${CPACK_CMAKE_PACKAGE_FILE}")
- message(STATUS "Downloading CMake ${CPACK_DESIRED_CMAKE_VERSION} for packaging...")
- download_file(
- URL ${_package_url}
- TARGET_FILE ${_cmake_package_dest}
- EXPECTED_HASH ${CPACK_CMAKE_PACKAGE_HASH}
- RESULTS _results
- )
- list(GET _results 0 _status_code)
- if (${_status_code} EQUAL 0 AND EXISTS ${_cmake_package_dest})
- message(STATUS "CMake ${CPACK_DESIRED_CMAKE_VERSION} found")
- else()
- file(REMOVE ${_cmake_package_dest})
- list(REMOVE_AT _results 0)
- set(_error_message "An error occurred, code ${_status_code}. URL ${_package_url} - ${_results}")
- if(${_status_code} EQUAL 1)
- string(APPEND _error_message
- " Please double check the CPACK_CMAKE_PACKAGE_FILE and "
- "CPACK_CMAKE_PACKAGE_HASH properties before trying again.")
- endif()
- message(FATAL_ERROR ${_error_message})
- endif()
- endif()
- install(CODE "if(NOT LY_CORE_COMPONENT_ALREADY_INCLUDED)")
- install(FILES ${_cmake_package_dest}
- DESTINATION ./Tools/Redistributables/CMake
- COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
- )
- install(CODE "endif()")
- # the version string and git tags are intended to be synchronized so it should be safe to use that instead
- # of directly calling into git which could get messy in certain scenarios
- if(${CPACK_PACKAGE_VERSION} VERSION_GREATER "0.0.0.0")
- set(_3rd_party_license_filename NOTICES.txt)
- set(_3rd_party_license_url "https://raw.githubusercontent.com/o3de/3p-package-source/${CPACK_PACKAGE_VERSION}/${_3rd_party_license_filename}")
- set(_3rd_party_license_dest ${CPACK_BINARY_DIR}/${_3rd_party_license_filename})
- # use the plain file downloader as we don't have the file hash available and using a dummy will
- # delete the file once it fails hash verification
- file(DOWNLOAD
- ${_3rd_party_license_url}
- ${_3rd_party_license_dest}
- STATUS _status
- TLS_VERIFY ON
- )
- list(POP_FRONT _status _status_code)
- if (${_status_code} EQUAL 0 AND EXISTS ${_3rd_party_license_dest})
- install(CODE "if(NOT LY_CORE_COMPONENT_ALREADY_INCLUDED)")
- install(FILES ${_3rd_party_license_dest}
- DESTINATION .
- COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
- )
- install(CODE "endif()")
- else()
- file(REMOVE ${_3rd_party_license_dest})
- message(FATAL_ERROR "Failed to acquire the 3rd Party license manifest file at ${_3rd_party_license_url}. Error: ${_status}")
- endif()
- endif()
- # checks for and removes trailing slash
- function(strip_trailing_slash in_url out_url)
- string(LENGTH ${in_url} _url_length)
- MATH(EXPR _url_length "${_url_length}-1")
- string(SUBSTRING ${in_url} 0 ${_url_length} _clean_url)
- if("${in_url}" STREQUAL "${_clean_url}/")
- set(${out_url} ${_clean_url} PARENT_SCOPE)
- else()
- set(${out_url} ${in_url} PARENT_SCOPE)
- endif()
- endfunction()
- if(NOT LY_INSTALLER_UPLOAD_URL AND DEFINED ENV{LY_INSTALLER_UPLOAD_URL})
- set(LY_INSTALLER_UPLOAD_URL $ENV{LY_INSTALLER_UPLOAD_URL})
- endif()
- if(LY_INSTALLER_UPLOAD_URL)
- ly_is_s3_url(${LY_INSTALLER_UPLOAD_URL} _is_s3_bucket)
- if(NOT _is_s3_bucket)
- message(FATAL_ERROR "Only S3 installer uploading is supported at this time")
- endif()
- if (LY_INSTALLER_AWS_PROFILE)
- set(CPACK_AWS_PROFILE ${LY_INSTALLER_AWS_PROFILE})
- elseif (DEFINED ENV{LY_INSTALLER_AWS_PROFILE})
- set(CPACK_AWS_PROFILE $ENV{LY_INSTALLER_AWS_PROFILE})
- endif()
- strip_trailing_slash(${LY_INSTALLER_UPLOAD_URL} LY_INSTALLER_UPLOAD_URL)
- set(CPACK_UPLOAD_URL ${LY_INSTALLER_UPLOAD_URL})
- endif()
- # IMPORTANT: required to be included AFTER setting all property overrides
- include(CPack REQUIRED)
- # configure ALL components here
- file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "
- set(CPACK_COMPONENTS_ALL ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
- set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISPLAY_NAME \"${PROJECT_NAME}\")
- set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DESCRIPTION \"${PROJECT_NAME} Headers, scripts and common files\")
- set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_REQUIRED TRUE)
- set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISABLED FALSE)
- include(CPackComponents.cmake)
- ")
- # Generate a file (CPackComponents.config) that we will include that defines the components
- # for this build permutation. This way we can get components for other permutations being passed
- # through LY_INSTALL_EXTERNAL_BUILD_DIRS
- unset(cpack_components_contents)
- set(required "FALSE")
- set(disabled "FALSE")
- if(${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
- set(required "TRUE")
- else()
- set(disabled "TRUE")
- endif()
- string(APPEND cpack_components_contents "
- list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISPLAY_NAME \"${PROJECT_NAME} (${LY_BUILD_PERMUTATION})\")
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DESCRIPTION \"${PROJECT_NAME} scripts and common files for ${LY_BUILD_PERMUTATION}\")
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DEPENDS ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_REQUIRED ${required})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISABLED ${disabled})
- ")
- foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
- string(TOUPPER ${conf} UCONF)
- set(required "FALSE")
- set(disabled "FALSE")
- if(${conf} STREQUAL profile AND ${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
- set(required "TRUE")
- else()
- set(disabled "TRUE")
- endif()
- unset(permutation_description)
- if(${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL MONOLITHIC)
- set(permutation_description "monolithic ")
- endif()
- # Inject a check to not declare components that have not been built. We are using AzCore since that is a
- # common target that will always be build, in every permutation and configuration
- string(APPEND cpack_components_contents "
- if(EXISTS \"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${conf}/${CMAKE_STATIC_LIBRARY_PREFIX}AzCore${CMAKE_STATIC_LIBRARY_SUFFIX}\")
- list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISPLAY_NAME \"${PROJECT_NAME} (${permutation_description}${conf})\")
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DESCRIPTION \"${PROJECT_NAME} Libraries and Applications in ${permutation_description}${conf}\")
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DEPENDS ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_REQUIRED ${required})
- set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISABLED ${disabled})
- endif()
- ")
- endforeach()
- file(WRITE "${CMAKE_BINARY_DIR}/CPackComponents.cmake" ${cpack_components_contents})
- # Inject other build directories
- foreach(external_dir ${LY_INSTALL_EXTERNAL_BUILD_DIRS})
- file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}"
- "include(${external_dir}/CPackComponents.cmake)\n"
- )
- endforeach()
- if(LY_INSTALLER_DOWNLOAD_URL)
- strip_trailing_slash(${LY_INSTALLER_DOWNLOAD_URL} LY_INSTALLER_DOWNLOAD_URL)
- # this will set the following variables: CPACK_DOWNLOAD_SITE, CPACK_DOWNLOAD_ALL, and CPACK_UPLOAD_DIRECTORY (local)
- cpack_configure_downloads(
- ${LY_INSTALLER_DOWNLOAD_URL}
- UPLOAD_DIRECTORY ${CMAKE_BINARY_DIR}/_CPack_Uploads # to match the _CPack_Packages directory
- ALL
- )
- endif()
|