CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # Cmake version 3.22 is the minimum version needed for all of Open 3D Engine's supported platforms
  9. cmake_minimum_required(VERSION 3.22)
  10. if(NOT ${CMAKE_VERSION} VERSION_LESS "3.24")
  11. # CMP0135 - controls whether, when unpacking an archive file, it should:
  12. # (OLD) set the file timestamps to what they are in the archive (not recommended)
  13. # (NEW) set the file timestamps to the time of extraction (recommended)
  14. cmake_policy(SET CMP0135 NEW)
  15. endif()
  16. include(cmake/LySet.cmake)
  17. include(cmake/GeneralSettings.cmake)
  18. include(cmake/FileUtil.cmake)
  19. include(cmake/Version.cmake)
  20. include(cmake/OutputDirectory.cmake)
  21. if(NOT PROJECT_NAME)
  22. include(cmake/CompilerSettings.cmake)
  23. project(O3DE
  24. LANGUAGES C CXX
  25. VERSION ${O3DE_INSTALL_VERSION_STRING}
  26. )
  27. endif()
  28. ################################################################################
  29. # Initialize
  30. ################################################################################
  31. include(CTest)
  32. include(cmake/PAL.cmake)
  33. include(cmake/PALTools.cmake)
  34. include(cmake/RuntimeDependencies.cmake)
  35. include(cmake/Configurations.cmake) # Requires to be after PAL so we get platform variable definitions
  36. include(cmake/Dependencies.cmake)
  37. include(cmake/Deployment.cmake)
  38. include(cmake/3rdParty.cmake)
  39. include(cmake/LYPython.cmake)
  40. include(cmake/Install.cmake)
  41. include(cmake/LYWrappers.cmake)
  42. include(cmake/Gems.cmake)
  43. include(cmake/UnitTest.cmake)
  44. include(cmake/TestImpactFramework/TestImpactTestTargetConfig.cmake) # LYTestWrappers dependency
  45. include(cmake/LYTestWrappers.cmake)
  46. include(cmake/Monolithic.cmake)
  47. include(cmake/SettingsRegistry.cmake)
  48. include(cmake/CMakeFiles.cmake)
  49. include(cmake/O3DEJson.cmake)
  50. include(cmake/Subdirectories.cmake)
  51. include(cmake/TestImpactFramework/LYTestImpactFramework.cmake) # Put at end as nothing else depends on it
  52. get_property(O3DE_SCRIPT_ONLY GLOBAL PROPERTY "O3DE_SCRIPT_ONLY")
  53. if (O3DE_SCRIPT_ONLY AND NOT INSTALLED_ENGINE)
  54. get_property(engine_root GLOBAL PROPERTY O3DE_ENGINE_ROOT_FOLDER)
  55. message(FATAL_ERROR "Script-only projects require pre-built versions of O3DE.\n\
  56. The project being compiled (${PROJECT_NAME}) is a script-only project (see project.json) \
  57. but the engine being used to build it is a compile-from-source engine using c++ code \
  58. (${engine_root}). Please use a pre-built (installer) O3DE to build script-only projects.")
  59. endif()
  60. # Gather the list of o3de_manifest external Subdirectories
  61. # into the O3DE_EXTERNAL_SUBDIRS_O3DE_MANIFEST_PROPERTY
  62. add_o3de_manifest_json_external_subdirectories()
  63. # Add the projects first so the Launcher can find them
  64. include(cmake/Projects.cmake)
  65. # Add external subdirectories listed in the engine.json.
  66. # O3DE_EXTERNAL_SUBDIRS is a cache variable so the user can add extra
  67. # external subdirectories.
  68. add_engine_json_external_subdirectories()
  69. if(NOT INSTALLED_ENGINE)
  70. # Add the rest of the targets
  71. add_subdirectory(Assets)
  72. add_subdirectory(Code)
  73. add_subdirectory(python)
  74. add_subdirectory(Registry)
  75. add_subdirectory(scripts)
  76. add_subdirectory(Templates)
  77. add_subdirectory(Tools)
  78. # Invoke add_subdirectory on all external subdirectories
  79. # that is in use by the union of projects specified by path in LY_PROJECTS
  80. add_subdirectory_on_external_subdirs()
  81. else()
  82. ly_find_o3de_packages()
  83. add_subdirectory_on_external_subdirs()
  84. endif()
  85. ################################################################################
  86. # Post-processing
  87. ################################################################################
  88. # The following steps have to be done after all targets are registered:
  89. # 1. Add any dependencies registered via ly_enable_gems
  90. ly_enable_gems_delayed()
  91. # 2. Defer generation of the StaticModules.inl file which is needed to create the AZ::Module derived class in monolithic
  92. # builds until after all the targets are known and all the gems are enabled
  93. ly_delayed_generate_static_modules_inl()
  94. # 3. generate a settings registry .setreg file for all ly_add_project_dependencies() and ly_add_target_dependencies() calls
  95. # to provide applications with the filenames of gem modules to load
  96. # This must be done before ly_delayed_target_link_libraries() as that inserts BUILD_DEPENDENCIES as MANUALLY_ADDED_DEPENDENCIES
  97. # if the build dependency is a MODULE_LIBRARY. That would cause a false load dependency to be generated
  98. ly_delayed_generate_settings_registry()
  99. # 4. link targets where the dependency was yet not declared, we need to have the declaration so we do different
  100. # linking logic depending on the type of target
  101. ly_delayed_target_link_libraries()
  102. # 5. generate a registry file for unit testing for platforms that support unit testing
  103. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  104. ly_delayed_generate_unit_test_module_registry()
  105. endif()
  106. # 5. inject runtime dependencies to the targets. We need to do this after (1) since we are going to walk through
  107. # the dependencies
  108. ly_delayed_generate_runtime_dependencies()
  109. # 6. Perform test impact framework post steps once all of the targets have been enumerated
  110. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  111. ly_test_impact_post_step()
  112. endif()
  113. # 7. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  114. if(LY_INSTALL_ENABLED)
  115. # 8. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  116. ly_setup_o3de_install()
  117. # 9. CPack information (to be included after install)
  118. include(cmake/Packaging.cmake)
  119. endif()