2
0

CMakeLists.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. # Output some useful-for-debugging information in case something goes wrong and the user sends a log.
  29. # this cannot be done until project() is called.
  30. get_property(O3DE_SCRIPT_ONLY GLOBAL PROPERTY "O3DE_SCRIPT_ONLY")
  31. if (O3DE_SCRIPT_ONLY)
  32. message(STATUS "Basic Configuration Information (Script-only mode):\n"
  33. " CMAKE_VERSION: ${CMAKE_VERSION}\n"
  34. " CMAKE_GENERATOR: ${CMAKE_GENERATOR}"
  35. )
  36. else()
  37. message(STATUS "Basic Configuration Information:\n"
  38. " CMAKE_VERSION: ${CMAKE_VERSION}\n"
  39. " CMAKE_GENERATOR: ${CMAKE_GENERATOR}\n"
  40. " CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}\n"
  41. " CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}\n"
  42. " O3DE_INSTALL_VERSION_STRING: ${O3DE_INSTALL_VERSION_STRING}\n"
  43. " INSTALLED_ENGINE: ${INSTALLED_ENGINE}"
  44. )
  45. endif()
  46. ################################################################################
  47. # Initialize
  48. ################################################################################
  49. message(STATUS "Initializing O3DE CMake system...")
  50. list(APPEND CMAKE_MESSAGE_INDENT " ")
  51. include(CTest)
  52. include(cmake/PAL.cmake)
  53. include(cmake/PALTools.cmake)
  54. include(cmake/RuntimeDependencies.cmake)
  55. include(cmake/Configurations.cmake) # Requires to be after PAL so we get platform variable definitions
  56. include(cmake/Dependencies.cmake)
  57. include(cmake/Deployment.cmake)
  58. include(cmake/3rdParty.cmake)
  59. include(cmake/LYPython.cmake)
  60. include(cmake/Install.cmake)
  61. include(cmake/LYWrappers.cmake)
  62. include(cmake/Gems.cmake)
  63. include(cmake/UnitTest.cmake)
  64. include(cmake/TestImpactFramework/TestImpactTestTargetConfig.cmake) # LYTestWrappers dependency
  65. include(cmake/LYTestWrappers.cmake)
  66. include(cmake/Monolithic.cmake)
  67. include(cmake/SettingsRegistry.cmake)
  68. include(cmake/CMakeFiles.cmake)
  69. include(cmake/O3DEJson.cmake)
  70. include(cmake/Subdirectories.cmake)
  71. include(cmake/TestImpactFramework/LYTestImpactFramework.cmake) # Put at end as nothing else depends on it
  72. if (O3DE_SCRIPT_ONLY AND NOT INSTALLED_ENGINE)
  73. get_property(engine_root GLOBAL PROPERTY O3DE_ENGINE_ROOT_FOLDER)
  74. message(FATAL_ERROR "Script-only projects require pre-built versions of O3DE.\n\
  75. The project being compiled (${PROJECT_NAME}) is a script-only project (see project.json) \
  76. but the engine being used to build it is a compile-from-source engine using c++ code \
  77. (${engine_root}). Please use a pre-built (installer) O3DE to build script-only projects.")
  78. endif()
  79. # Gather the list of o3de_manifest external Subdirectories
  80. # into the O3DE_EXTERNAL_SUBDIRS_O3DE_MANIFEST_PROPERTY
  81. add_o3de_manifest_json_external_subdirectories()
  82. list(POP_BACK CMAKE_MESSAGE_INDENT)
  83. message(STATUS "Executing CMake scripts...")
  84. list(APPEND CMAKE_MESSAGE_INDENT " ")
  85. # Add the projects first so the Launcher can find them
  86. include(cmake/Projects.cmake)
  87. # Add external subdirectories listed in the engine.json.
  88. # O3DE_EXTERNAL_SUBDIRS is a cache variable so the user can add extra
  89. # external subdirectories.
  90. add_engine_json_external_subdirectories()
  91. if(NOT INSTALLED_ENGINE)
  92. # Add the rest of the targets
  93. add_subdirectory(Assets)
  94. add_subdirectory(Code)
  95. add_subdirectory(python)
  96. add_subdirectory(Registry)
  97. add_subdirectory(scripts)
  98. add_subdirectory(Templates)
  99. add_subdirectory(Tools)
  100. # Invoke add_subdirectory on all external subdirectories
  101. # that is in use by the union of projects specified by path in LY_PROJECTS
  102. add_subdirectory_on_external_subdirs()
  103. else()
  104. ly_find_o3de_packages()
  105. add_subdirectory_on_external_subdirs()
  106. endif()
  107. ################################################################################
  108. # Post-processing
  109. ################################################################################
  110. # The following steps have to be done after all targets are registered:
  111. list(POP_BACK CMAKE_MESSAGE_INDENT)
  112. message(STATUS "Finishing up configuration...")
  113. list(APPEND CMAKE_MESSAGE_INDENT " ")
  114. # Most of these post processing steps are nearly instantaneous, so no point in displaying a message
  115. # but if any of them take a time, we can add a message.
  116. # 1. Add any dependencies registered via ly_enable_gems
  117. ly_enable_gems_delayed()
  118. # 2. Defer generation of the StaticModules.inl file which is needed to create the AZ::Module derived class in monolithic
  119. # builds until after all the targets are known and all the gems are enabled
  120. ly_delayed_generate_static_modules_inl()
  121. # 3. generate a settings registry .setreg file for all ly_add_project_dependencies() and ly_add_target_dependencies() calls
  122. # to provide applications with the filenames of gem modules to load
  123. # This must be done before ly_delayed_target_link_libraries() as that inserts BUILD_DEPENDENCIES as MANUALLY_ADDED_DEPENDENCIES
  124. # if the build dependency is a MODULE_LIBRARY. That would cause a false load dependency to be generated
  125. ly_delayed_generate_settings_registry()
  126. # 4. link targets where the dependency was yet not declared, we need to have the declaration so we do different
  127. # linking logic depending on the type of target
  128. ly_delayed_target_link_libraries()
  129. # 5. generate a registry file for unit testing for platforms that support unit testing
  130. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  131. ly_delayed_generate_unit_test_module_registry()
  132. endif()
  133. # 5. inject runtime dependencies to the targets. We need to do this after (1) since we are going to walk through
  134. # the dependencies
  135. # This step takes a bit of time, so we display a message
  136. message(STATUS "Computing Runtime Dependencies (files to copy to the target's output directory)...")
  137. ly_delayed_generate_runtime_dependencies()
  138. # 6. Perform test impact framework post steps once all of the targets have been enumerated
  139. if(O3DE_TEST_IMPACT_NATIVE_TEST_TARGETS_ENABLED OR O3DE_TEST_IMPACT_PYTHON_TEST_TARGETS_ENABLED)
  140. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  141. ly_test_impact_post_step()
  142. endif()
  143. endif()
  144. list(POP_BACK CMAKE_MESSAGE_INDENT)
  145. # 7. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  146. if(LY_INSTALL_ENABLED)
  147. # 8. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  148. ly_setup_o3de_install()
  149. # 9. CPack information (to be included after install)
  150. include(cmake/Packaging.cmake)
  151. endif()