Packaging_Snapcraft.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. # Generate the files needed for the desktop icon
  34. file(MAKE_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}/snap/gui/")
  35. string(JOIN "\n" O3DE_DESKTOP_CONTENT
  36. "[Desktop Entry]"
  37. "Version=${CPACK_PACKAGE_VERSION}"
  38. "Name=O3DE"
  39. "Comment=O3DE Project Manager"
  40. "Type=Application"
  41. "Exec=o3de"
  42. "Icon=\${SNAP}/meta/gui/o3de.svg"
  43. "Terminal=false"
  44. "StartupWMClass=O3DE-Snap"
  45. "StartupNotify=true"
  46. "X-GNOME-Autostart-enabled=true"
  47. )
  48. file(WRITE "${CPACK_TEMPORARY_DIRECTORY}/snap/gui/o3de.desktop" ${O3DE_DESKTOP_CONTENT})
  49. file(COPY_FILE
  50. "${LY_ROOT_FOLDER}/Code/Tools/ProjectManager/Resources/o3de.svg"
  51. "${CPACK_TEMPORARY_DIRECTORY}/snap/gui/o3de.svg"
  52. )
  53. # make sure that all files have the correct permissions
  54. execute_process (COMMAND chmod -R 755 O3DE
  55. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  56. )
  57. # clean then build snap
  58. execute_process (COMMAND snapcraft clean
  59. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  60. )
  61. execute_process (COMMAND snapcraft --verbose
  62. WORKING_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}
  63. )
  64. set(snap_file "${CPACK_TEMPORARY_DIRECTORY}/o3de_${CPACK_PACKAGE_VERSION}_amd64.snap")
  65. # Manually copy the files, the CPACK_EXTERNAL_BUILT_PACKAGES process runs after our packaging post build script
  66. # which is too late to be uploaded.
  67. file(COPY_FILE
  68. ${snap_file}
  69. "${CPACK_TOPLEVEL_DIRECTORY}/${snap_file_name}.snap"
  70. )