PackagingPostBuild_windows.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. file(REAL_PATH "${CPACK_SOURCE_DIR}/.." LY_ROOT_FOLDER)
  9. include(${LY_ROOT_FOLDER}/cmake/Platform/Common/PackagingPostBuild_common.cmake)
  10. include(${CPACK_CODESIGN_SCRIPT})
  11. # convert the path to a windows style path using string replace because TO_NATIVE_PATH
  12. # only works on real paths
  13. string(REPLACE "/" "\\" _fixed_package_install_dir ${CPACK_PACKAGE_INSTALL_DIRECTORY})
  14. # directory where the auto generated files live e.g <build>/_CPack_Package/win64/WIX
  15. set(_cpack_wix_out_dir ${CPACK_TOPLEVEL_DIRECTORY})
  16. set(_bootstrap_out_dir "${CPACK_TOPLEVEL_DIRECTORY}/bootstrap")
  17. set(_bootstrap_filename "${CPACK_PACKAGE_FILE_NAME}_installer.exe")
  18. set(_bootstrap_output_file ${_cpack_wix_out_dir}/${_bootstrap_filename})
  19. set(_ext_flags
  20. -ext WixBalExtension
  21. )
  22. set(_addtional_defines
  23. -dCPACK_BOOTSTRAP_THEME_FILE=${CPACK_BINARY_DIR}/BootstrapperTheme
  24. -dCPACK_BOOTSTRAP_UPGRADE_GUID=${CPACK_WIX_BOOTSTRAP_UPGRADE_GUID}
  25. -dCPACK_DOWNLOAD_SITE=${CPACK_DOWNLOAD_SITE}
  26. -dCPACK_LOCAL_INSTALLER_DIR=${_cpack_wix_out_dir}
  27. -dCPACK_PACKAGE_FILE_NAME=${CPACK_PACKAGE_FILE_NAME}
  28. -dCPACK_PACKAGE_INSTALL_DIRECTORY=${_fixed_package_install_dir}
  29. -dCPACK_WIX_PRODUCT_LOGO=${CPACK_WIX_PRODUCT_LOGO}
  30. -dCPACK_RESOURCE_PATH=${CPACK_SOURCE_DIR}/Platform/Windows/Packaging
  31. )
  32. if(CPACK_LICENSE_URL)
  33. list(APPEND _addtional_defines -dCPACK_LICENSE_URL=${CPACK_LICENSE_URL})
  34. endif()
  35. set(_candle_command
  36. ${CPACK_WIX_CANDLE_EXECUTABLE}
  37. -nologo
  38. -arch x64
  39. "-I${_cpack_wix_out_dir}" # to include cpack_variables.wxi
  40. ${_addtional_defines}
  41. ${_ext_flags}
  42. "${CPACK_SOURCE_DIR}/Platform/Windows/Packaging/Bootstrapper.wxs"
  43. -o "${_bootstrap_out_dir}/"
  44. )
  45. set(_light_command
  46. ${CPACK_WIX_LIGHT_EXECUTABLE}
  47. -nologo
  48. ${_ext_flags}
  49. ${_bootstrap_out_dir}/*.wixobj
  50. -o "${_bootstrap_output_file}"
  51. )
  52. if(CPACK_UPLOAD_URL) # Skip signing if we are not uploading the package
  53. ly_sign_binaries("${_cpack_wix_out_dir}" "packagePath")
  54. endif()
  55. message(STATUS "Creating Bootstrap Installer...")
  56. execute_process(
  57. COMMAND ${_candle_command}
  58. RESULT_VARIABLE _candle_result
  59. ERROR_VARIABLE _candle_errors
  60. )
  61. if(NOT ${_candle_result} EQUAL 0)
  62. message(FATAL_ERROR "An error occurred invoking candle.exe. ${_candle_errors}")
  63. endif()
  64. execute_process(
  65. COMMAND ${_light_command}
  66. RESULT_VARIABLE _light_result
  67. ERROR_VARIABLE _light_errors
  68. )
  69. if(NOT ${_light_result} EQUAL 0)
  70. message(FATAL_ERROR "An error occurred invoking light.exe. ${_light_errors}")
  71. endif()
  72. message(STATUS "Bootstrap installer generated to ${_bootstrap_output_file}")
  73. if(CPACK_UPLOAD_URL) # Skip signing if we are not uploading the package
  74. ly_sign_binaries("${_bootstrap_output_file}" "bootstrapPath")
  75. endif()
  76. # use the internal default path if somehow not specified from cpack_configure_downloads
  77. if(NOT CPACK_UPLOAD_DIRECTORY)
  78. set(CPACK_UPLOAD_DIRECTORY ${CPACK_PACKAGE_DIRECTORY}/CPackUploads)
  79. endif()
  80. # Copy the artifacts intended to be uploaded to a remote server into the folder specified
  81. # through CPACK_UPLOAD_DIRECTORY. This mimics the same process cpack does natively for
  82. # some other frameworks that have built-in online installer support.
  83. message(STATUS "Copying packaging artifacts to upload directory...")
  84. file(REMOVE_RECURSE ${CPACK_UPLOAD_DIRECTORY})
  85. file(GLOB _artifacts
  86. "${_cpack_wix_out_dir}/*.msi"
  87. "${_cpack_wix_out_dir}/*.cab"
  88. "${_cpack_wix_out_dir}/*.exe"
  89. "${CPACK_3P_LICENSE_FILE}"
  90. "${CPACK_3P_MANIFEST_FILE}"
  91. )
  92. file(COPY ${_artifacts}
  93. DESTINATION ${CPACK_UPLOAD_DIRECTORY}
  94. )
  95. message(STATUS "Artifacts copied to ${CPACK_UPLOAD_DIRECTORY}")
  96. if(CPACK_UPLOAD_URL)
  97. ly_upload_to_url(
  98. ${CPACK_UPLOAD_URL}
  99. ${CPACK_UPLOAD_DIRECTORY}
  100. ".*(.cab|.exe|.msi|.txt|.json)$"
  101. )
  102. # for auto tagged builds, we will also upload a second copy of just the boostrapper
  103. # to a special "Latest" folder under the branch in place of the commit date/hash
  104. if(CPACK_AUTO_GEN_TAG)
  105. ly_upload_to_latest(${CPACK_UPLOAD_URL} ${_bootstrap_output_file})
  106. endif()
  107. endif()