Packaging_Snapcraft.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. # Copy snapcraft file
  9. set(snap_file_name "o3de_${CPACK_PACKAGE_VERSION}_amd64")
  10. if(CPACK_SNAP_DISTRO)
  11. configure_file("${LY_ROOT_FOLDER}/cmake/Platform/Linux/Packaging/snapcraft_${CPACK_SNAP_DISTRO}.yaml.in"
  12. "${CPACK_TEMPORARY_DIRECTORY}/snapcraft.yaml"
  13. )
  14. set(snap_file_name "o3de_${CPACK_PACKAGE_VERSION}_${CPACK_SNAP_DISTRO}_amd64")
  15. else()
  16. configure_file("${LY_ROOT_FOLDER}/cmake/Platform/Linux/Packaging/snapcraft.yaml.in"
  17. "${CPACK_TEMPORARY_DIRECTORY}/snapcraft.yaml"
  18. )
  19. endif()
  20. execute_process (COMMAND lsb_release -a)
  21. # Download python before packaging. The python runtimes themselves will not be part of the packaging, but
  22. # the following script will also run through the scripts and create the necessary egg-link folders
  23. # which will be installed into the package
  24. execute_process (COMMAND bash ${CPACK_TEMPORARY_DIRECTORY}/O3DE/${CPACK_PACKAGE_VERSION}/python/get_python.sh)
  25. # Since snap is immutable, we will pre-compile all the python scripts that is packaged into python byte-codes
  26. set(O3DE_PY_SUBDIRS "Code;Gems;scripts;Tools")
  27. foreach(engine_subfolder ${O3DE_PY_SUBDIRS})
  28. file(GLOB_RECURSE pyfiles "${CPACK_TEMPORARY_DIRECTORY}/O3DE/${CPACK_PACKAGE_VERSION}/${engine_subfolder}/*.py")
  29. foreach(pyfile ${pyfiles})
  30. execute_process (COMMAND bash ${CPACK_TEMPORARY_DIRECTORY}/O3DE/${CPACK_PACKAGE_VERSION}/python/python.sh -m py_compile ${pyfile})
  31. endforeach()
  32. endforeach()
  33. # make sure that all files have the correct permissions
  34. execute_process (COMMAND chmod -R 755 O3DE
  35. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  36. )
  37. # clean then build snap
  38. execute_process (COMMAND snapcraft clean
  39. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  40. )
  41. execute_process (COMMAND snapcraft --verbose
  42. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  43. )
  44. set(snap_file "${CPACK_TEMPORARY_DIRECTORY}/o3de_${CPACK_PACKAGE_VERSION}_amd64.snap")
  45. # Manually copy the files, the CPACK_EXTERNAL_BUILT_PACKAGES process runs after our packaging post build script
  46. # which is too late to be uploaded.
  47. file(COPY_FILE
  48. ${snap_file}
  49. "${CPACK_TOPLEVEL_DIRECTORY}/${snap_file_name}.snap"
  50. )