Packaging.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 "info@o3debinaries.org")
  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. ly_install(FILES ${CPACK_3P_LICENSE_FILE} ${CPACK_3P_MANIFEST_FILE}
  100. DESTINATION .
  101. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  102. )
  103. configure_file(${LY_ROOT_FOLDER}/cmake/Packaging/CMakeDownload.cmake.in
  104. ${CPACK_BINARY_DIR}/CMakeDownload.cmake
  105. @ONLY
  106. )
  107. ly_install(SCRIPT ${CPACK_BINARY_DIR}/CMakeDownload.cmake
  108. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  109. )
  110. ly_install(FILES ${LY_CMAKE_PACKAGE_DOWNLOAD_PATH}
  111. DESTINATION Tools/Redistributables/CMake
  112. COMPONENT ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}
  113. )
  114. # Set common CPACK variables to all platforms/generators
  115. set(CPACK_STRIP_FILES TRUE) # always strip symbols on packaging
  116. set(CPACK_PACKAGE_CHECKSUM SHA256) # Generate checksum file
  117. set(CPACK_PRE_BUILD_SCRIPTS ${pal_dir}/PackagingPreBuild_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  118. set(CPACK_POST_BUILD_SCRIPTS ${pal_dir}/PackagingPostBuild_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  119. set(CPACK_CODESIGN_SCRIPT ${pal_dir}/PackagingCodeSign_${PAL_HOST_PLATFORM_NAME_LOWERCASE}.cmake)
  120. set(CPACK_LY_PYTHON_CMD ${LY_PYTHON_CMD})
  121. # IMPORTANT: required to be included AFTER setting all property overrides
  122. include(CPack REQUIRED)
  123. # configure ALL components here
  124. file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "
  125. set(CPACK_COMPONENTS_ALL ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  126. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISPLAY_NAME \"Common files\")
  127. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DESCRIPTION \"${PROJECT_NAME} Headers, scripts and common files\")
  128. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_REQUIRED TRUE)
  129. set(CPACK_COMPONENT_${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME}_DISABLED FALSE)
  130. include(CPackComponents.cmake)
  131. ")
  132. # Generate a file (CPackComponents.config) that we will include that defines the components
  133. # for this build permutation. This way we can get components for other permutations being passed
  134. # through LY_INSTALL_EXTERNAL_BUILD_DIRS
  135. unset(cpack_components_contents)
  136. set(required "FALSE")
  137. set(disabled "FALSE")
  138. if(${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
  139. set(required "TRUE")
  140. else()
  141. set(disabled "TRUE")
  142. endif()
  143. string(APPEND cpack_components_contents "
  144. list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT})
  145. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISPLAY_NAME \"${LY_BUILD_PERMUTATION} common files\")
  146. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DESCRIPTION \"${PROJECT_NAME} scripts and common files for ${LY_BUILD_PERMUTATION}\")
  147. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DEPENDS ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
  148. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_REQUIRED ${required})
  149. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_DISABLED ${disabled})
  150. ")
  151. foreach(conf IN LISTS CMAKE_CONFIGURATION_TYPES)
  152. string(TOUPPER ${conf} UCONF)
  153. set(required "FALSE")
  154. set(disabled "FALSE")
  155. if(${conf} STREQUAL profile AND ${LY_INSTALL_PERMUTATION_COMPONENT} STREQUAL DEFAULT)
  156. set(required "TRUE")
  157. else()
  158. set(disabled "TRUE")
  159. endif()
  160. # Inject a check to not declare components that have not been built. We are using AzCore since that is a
  161. # common target that will always be build, in every permutation and configuration
  162. string(APPEND cpack_components_contents "
  163. if(EXISTS \"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${conf}/${CMAKE_STATIC_LIBRARY_PREFIX}AzCore${CMAKE_STATIC_LIBRARY_SUFFIX}\")
  164. list(APPEND CPACK_COMPONENTS_ALL ${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF})
  165. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISPLAY_NAME \"Binaries for ${LY_BUILD_PERMUTATION} ${conf}\")
  166. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DESCRIPTION \"${PROJECT_NAME} libraries and applications for ${LY_BUILD_PERMUTATION} ${conf}\")
  167. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DEPENDS ${LY_INSTALL_PERMUTATION_COMPONENT})
  168. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_REQUIRED ${required})
  169. set(CPACK_COMPONENT_${LY_INSTALL_PERMUTATION_COMPONENT}_${UCONF}_DISABLED ${disabled})
  170. endif()
  171. ")
  172. endforeach()
  173. file(WRITE "${CMAKE_BINARY_DIR}/CPackComponents.cmake" ${cpack_components_contents})
  174. # Inject other build directories
  175. foreach(external_dir ${LY_INSTALL_EXTERNAL_BUILD_DIRS})
  176. file(APPEND "${CPACK_OUTPUT_CONFIG_FILE}"
  177. "include(${external_dir}/CPackComponents.cmake)\n"
  178. )
  179. endforeach()
  180. # checks for and removes trailing slash
  181. function(strip_trailing_slash in_url out_url)
  182. string(LENGTH ${in_url} _url_length)
  183. MATH(EXPR _url_length "${_url_length}-1")
  184. string(SUBSTRING ${in_url} 0 ${_url_length} _clean_url)
  185. if("${in_url}" STREQUAL "${_clean_url}/")
  186. set(${out_url} ${_clean_url} PARENT_SCOPE)
  187. else()
  188. set(${out_url} ${in_url} PARENT_SCOPE)
  189. endif()
  190. endfunction()
  191. if(LY_INSTALLER_DOWNLOAD_URL)
  192. strip_trailing_slash(${LY_INSTALLER_DOWNLOAD_URL} LY_INSTALLER_DOWNLOAD_URL)
  193. # this will set the following variables: CPACK_DOWNLOAD_SITE, CPACK_DOWNLOAD_ALL, and CPACK_UPLOAD_DIRECTORY (local)
  194. cpack_configure_downloads(
  195. ${LY_INSTALLER_DOWNLOAD_URL}
  196. UPLOAD_DIRECTORY ${CMAKE_BINARY_DIR}/CPackUploads # to match the _CPack_Packages directory
  197. ALL
  198. )
  199. endif()