Packaging.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. if(NOT PAL_TRAIT_BUILD_CPACK_SUPPORTED)
  9. return()
  10. endif()
  11. # public facing options will be used for conversion into cpack specific ones below.
  12. set(LY_INSTALLER_LICENSE_URL "" CACHE STRING "Optionally embed a link to the license instead of raw text")
  13. set(LY_INSTALLER_AUTO_GEN_TAG OFF CACHE BOOL
  14. "Automatically generate a build tag based on the git repo and append it to the download/upload URLs. \
  15. Format: <branch>/<commit_date>-<commit_hash>"
  16. )
  17. set(LY_INSTALLER_DOWNLOAD_URL "" CACHE STRING
  18. "Base URL embedded into the installer to download additional artifacts, the host target and version \
  19. number will automatically appended as '<version>/<host>'. If LY_INSTALLER_AUTO_GEN_TAG is set, the \
  20. full URL format will be: <base_url>/<build_tag>/<host>"
  21. )
  22. set(CPACK_UPLOAD_URL "" CACHE STRING
  23. "URL used to upload the installer artifacts after generation, the host target and version number \
  24. will automatically appended as '<version>/<host>'. If LY_INSTALLER_AUTO_GEN_TAG is set, the full URL \
  25. format will be: <base_url>/<build_tag>/<host>. Currently only accepts S3 URLs e.g. s3://<bucket>/<prefix>"
  26. )
  27. set(CPACK_AWS_PROFILE "" CACHE STRING
  28. "AWS CLI profile for uploading artifacts."
  29. )
  30. set(CPACK_SNAP_DISTRO "" CACHE STRING
  31. "Sets the base snap OS distro (core20, 22, etc) for the snap build"
  32. )
  33. set(CPACK_THREADS 0)
  34. set(CPACK_DESIRED_CMAKE_VERSION 3.22.0)
  35. if(${CPACK_DESIRED_CMAKE_VERSION} VERSION_LESS ${CMAKE_MINIMUM_REQUIRED_VERSION})
  36. message(FATAL_ERROR
  37. "The desired version of CMake to be included in the package is "
  38. "below the minimum required version of CMake to run")
  39. endif()
  40. # set all common cpack variable overrides first so they can be accessible via configure_file
  41. # when the platform specific settings are applied below. additionally, any variable with
  42. # the "CPACK_" prefix will automatically be cached for use in any phase of cpack namely
  43. # pre/post build
  44. set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
  45. set(CPACK_PACKAGE_FULL_NAME "Open3D Engine")
  46. set(CPACK_PACKAGE_VENDOR "O3DE Binary Project a Series of LF Projects, LLC")
  47. set(CPACK_PACKAGE_CONTACT "[email protected]")
  48. # prefer the display engine version if available.
  49. # during development, the display version will be "00.00" or "" in which case we want
  50. # to use the actual engine version
  51. if(NOT ((${O3DE_INSTALL_DISPLAY_VERSION_STRING} STREQUAL "00.00") OR (${O3DE_INSTALL_DISPLAY_VERSION_STRING} STREQUAL "")))
  52. set(CPACK_PACKAGE_VERSION "${O3DE_INSTALL_DISPLAY_VERSION_STRING}")
  53. else()
  54. set(CPACK_PACKAGE_VERSION "${O3DE_INSTALL_VERSION_STRING}")
  55. endif()
  56. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Installation Tool")
  57. string(TOLOWER "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}" CPACK_PACKAGE_FILE_NAME)
  58. set(DEFAULT_LICENSE_NAME "Apache-2.0")
  59. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
  60. set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  61. set(CPACK_LICENSE_URL ${LY_INSTALLER_LICENSE_URL})
  62. set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}/${CPACK_PACKAGE_VERSION}")
  63. # neither of the SOURCE_DIR variables equate to anything during execution of pre/post build scripts
  64. set(CPACK_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  65. set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR}/_CPack) # to match other CPack out dirs
  66. set(CPACK_OUTPUT_FILE_PREFIX CPackUploads)
  67. # this config file allows the dynamic setting of cpack variables at cpack-time instead of cmake configure
  68. set(CPACK_PROJECT_CONFIG_FILE ${CPACK_SOURCE_DIR}/PackagingConfig.cmake)
  69. set(CPACK_AUTO_GEN_TAG ${LY_INSTALLER_AUTO_GEN_TAG})
  70. # attempt to apply platform specific settings
  71. o3de_pal_dir(pal_dir ${CPACK_SOURCE_DIR}/Platform/${PAL_HOST_PLATFORM_NAME} "${O3DE_ENGINE_RESTRICTED_PATH}" "${LY_ROOT_FOLDER}")
  72. include(${pal_dir}/Packaging_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  73. # if we get here and the generator hasn't been set, then a non fatal error occurred disabling packaging support
  74. if(NOT CPACK_GENERATOR)
  75. return()
  76. endif()
  77. # We will download the desired copy of CMake so it can be included in the package, we defer the downloading
  78. # to the install process, to do so we generate a script that will perform the download and execute such script
  79. # during the install process (before packaging)
  80. if(NOT (CPACK_CMAKE_PACKAGE_FILE AND CPACK_CMAKE_PACKAGE_HASH))
  81. message(FATAL_ERROR
  82. "Packaging is missing one or more following properties required to include CMake: "
  83. " CPACK_CMAKE_PACKAGE_FILE, CPACK_CMAKE_PACKAGE_HASH")
  84. endif()
  85. # We download it to a different location because CPACK_PACKAGING_INSTALL_PREFIX will be removed during
  86. # cpack generation. CPACK_BINARY_DIR persists across cpack invocations
  87. set(LY_CMAKE_PACKAGE_DOWNLOAD_PATH ${CPACK_BINARY_DIR}/${CPACK_CMAKE_PACKAGE_FILE})
  88. # Scan the source and 3p packages for licenses, then add the generated license results to the binary output folder.
  89. # These results will be installed to the root of the install folder and copied to the S3 bucket specific to each platform
  90. set(CPACK_3P_LICENSE_FILE "${CPACK_BINARY_DIR}/NOTICES.txt")
  91. set(CPACK_3P_MANIFEST_FILE "${CPACK_BINARY_DIR}/SPDX-License.json")
  92. configure_file(${LY_ROOT_FOLDER}/cmake/Packaging/LicenseScan.cmake.in
  93. ${CPACK_BINARY_DIR}/LicenseScan.cmake
  94. @ONLY
  95. )
  96. ly_install(SCRIPT ${CPACK_BINARY_DIR}/LicenseScan.cmake
  97. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  98. )
  99. cmake_path(SET _destination_normalized NORMALIZE .)
  100. ly_install(FILES ${CPACK_3P_LICENSE_FILE} ${CPACK_3P_MANIFEST_FILE}
  101. DESTINATION ${_destination_normalized}
  102. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  103. )
  104. configure_file(${LY_ROOT_FOLDER}/cmake/Packaging/CMakeDownload.cmake.in
  105. ${CPACK_BINARY_DIR}/CMakeDownload.cmake
  106. @ONLY
  107. )
  108. ly_install(SCRIPT ${CPACK_BINARY_DIR}/CMakeDownload.cmake
  109. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  110. )
  111. ly_install(FILES ${LY_CMAKE_PACKAGE_DOWNLOAD_PATH}
  112. DESTINATION Tools/Redistributables/CMake
  113. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  114. )
  115. # Set common CPACK variables to all platforms/generators
  116. set(CPACK_STRIP_FILES TRUE) # always strip symbols on packaging
  117. set(CPACK_PACKAGE_CHECKSUM SHA256) # Generate checksum file
  118. set(CPACK_PRE_BUILD_SCRIPTS ${pal_dir}/PackagingPreBuild_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  119. set(CPACK_POST_BUILD_SCRIPTS ${pal_dir}/PackagingPostBuild_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  120. set(CPACK_CODESIGN_SCRIPT ${pal_dir}/PackagingCodeSign_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  121. set(CPACK_LY_PYTHON_CMD ${LY_PYTHON_CMD})
  122. # IMPORTANT: required to be included AFTER setting all property overrides
  123. include(CPack REQUIRED)
  124. # configure ALL components here
  125. file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "
  126. set(CPACK_COMPONENTS_ALL ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  127. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISPLAY_NAME \"Common files\")
  128. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DESCRIPTION \"${PROJECT_NAME} Headers, scripts and common files\")
  129. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_REQUIRED TRUE)
  130. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISABLED FALSE)
  131. include(CPackComponents.cmake)
  132. ")
  133. # Generate a file (CPackComponents.config) that we will include that defines the components
  134. # for this build permutation. This way we can get components for other permutations being passed
  135. # through LY_INSTALL_EXTERNAL_BUILD_DIRS
  136. unset(cpack_components_contents)
  137. set(required "FALSE")
  138. set(disabled "FALSE")
  139. if(${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
  140. set(required "TRUE")
  141. else()
  142. set(disabled "TRUE")
  143. endif()
  144. string(APPEND cpack_components_contents "
  145. list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT})
  146. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISPLAY_NAME \"${LY_BUILD_PERMUTATION} common files\")
  147. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DESCRIPTION \"${PROJECT_NAME} scripts and common files for ${LY_BUILD_PERMUTATION}\")
  148. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DEPENDS ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  149. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_REQUIRED ${required})
  150. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISABLED ${disabled})
  151. ")
  152. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  153. string(TOUPPER ${conf} UCONF)
  154. set(required "FALSE")
  155. set(disabled "FALSE")
  156. if(${conf} STREQUAL profile AND ${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
  157. set(required "TRUE")
  158. else()
  159. set(disabled "TRUE")
  160. endif()
  161. # Inject a check to not declare components that have not been built. We are using AzCore since that is a
  162. # common target that will always be build, in every permutation and configuration
  163. string(APPEND cpack_components_contents "
  164. if(EXISTS \"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${conf}/${CMAKE_STATIC_LIBRARY_PREFIX}AzCore${CMAKE_STATIC_LIBRARY_SUFFIX}\")
  165. list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF})
  166. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISPLAY_NAME \"Binaries for ${LY_BUILD_PERMUTATION} ${conf}\")
  167. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DESCRIPTION \"${PROJECT_NAME} libraries and applications for ${LY_BUILD_PERMUTATION} ${conf}\")
  168. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DEPENDS ${LY_INSTALL_PERMUTATION_COMPONENT})
  169. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_REQUIRED ${required})
  170. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISABLED ${disabled})
  171. endif()
  172. ")
  173. endforeach()
  174. file(WRITE "${CMAKE_BINARY_DIR}/CPackComponents.cmake" ${cpack_components_contents})
  175. # Inject other build directories
  176. foreach(external_dir ${LY_INSTALL_EXTERNAL_BUILD_DIRS})
  177. file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}"
  178. "include(${external_dir}/CPackComponents.cmake)\n"
  179. )
  180. endforeach()
  181. # checks for and removes trailing slash
  182. function(strip_trailing_slash in_url out_url)
  183. string(LENGTH ${in_url} _url_length)
  184. MATH(EXPR _url_length "${_url_length}-1")
  185. string(SUBSTRING ${in_url} 0 ${_url_length} _clean_url)
  186. if("${in_url}" STREQUAL "${_clean_url}/")
  187. set(${out_url} ${_clean_url} PARENT_SCOPE)
  188. else()
  189. set(${out_url} ${in_url} PARENT_SCOPE)
  190. endif()
  191. endfunction()
  192. if(LY_INSTALLER_DOWNLOAD_URL)
  193. strip_trailing_slash(${LY_INSTALLER_DOWNLOAD_URL} LY_INSTALLER_DOWNLOAD_URL)
  194. # this will set the following variables: CPACK_DOWNLOAD_SITE, CPACK_DOWNLOAD_ALL, and CPACK_UPLOAD_DIRECTORY (local)
  195. cpack_configure_downloads(
  196. ${LY_INSTALLER_DOWNLOAD_URL}
  197. UPLOAD_DIRECTORY ${CMAKE_BINARY_DIR}/CPackUploads # to match the _CPack_Packages directory
  198. ALL
  199. )
  200. endif()