CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.20 is the minimum version needed for all of Open 3D Engine's supported platforms
  9. cmake_minimum_required(VERSION 3.20)
  10. include(cmake/LySet.cmake)
  11. include(cmake/Version.cmake)
  12. include(cmake/OutputDirectory.cmake)
  13. if(NOT PROJECT_NAME)
  14. project(O3DE
  15. LANGUAGES C CXX
  16. VERSION ${LY_VERSION_STRING}
  17. )
  18. endif()
  19. ################################################################################
  20. # Initialize
  21. ################################################################################
  22. include(cmake/GeneralSettings.cmake)
  23. include(cmake/FileUtil.cmake)
  24. include(cmake/PAL.cmake)
  25. include(cmake/PALTools.cmake)
  26. include(cmake/RuntimeDependencies.cmake)
  27. include(cmake/Configurations.cmake) # Requires to be after PAL so we get platform variable definitions
  28. include(cmake/Dependencies.cmake)
  29. include(cmake/Deployment.cmake)
  30. include(cmake/3rdParty.cmake)
  31. include(cmake/LYPython.cmake)
  32. include(cmake/Install.cmake)
  33. include(cmake/LYWrappers.cmake)
  34. include(cmake/Gems.cmake)
  35. include(cmake/UnitTest.cmake)
  36. include(cmake/LYTestWrappers.cmake)
  37. include(cmake/Monolithic.cmake)
  38. include(cmake/SettingsRegistry.cmake)
  39. include(cmake/TestImpactFramework/LYTestImpactFramework.cmake)
  40. include(cmake/CMakeFiles.cmake)
  41. include(cmake/O3DEJson.cmake)
  42. ################################################################################
  43. # Subdirectory processing
  44. ################################################################################
  45. function(add_engine_json_external_subdirectories)
  46. read_json_external_subdirs(external_subdis ${LY_ROOT_FOLDER}/engine.json)
  47. foreach(external_subdir ${external_subdis})
  48. file(REAL_PATH ${external_subdir} real_external_subdir BASE_DIRECTORY ${LY_ROOT_FOLDER})
  49. list(APPEND engine_external_subdirs ${real_external_subdir})
  50. endforeach()
  51. set_property(GLOBAL APPEND PROPERTY LY_EXTERNAL_SUBDIRS ${engine_external_subdirs})
  52. endfunction()
  53. # Add the projects first so the Launcher can find them
  54. include(cmake/Projects.cmake)
  55. if(NOT INSTALLED_ENGINE)
  56. # Add the rest of the targets
  57. add_subdirectory(Assets)
  58. add_subdirectory(Code)
  59. add_subdirectory(python)
  60. add_subdirectory(Registry)
  61. add_subdirectory(scripts)
  62. add_subdirectory(Templates)
  63. add_subdirectory(Tools)
  64. # Add external subdirectories listed in the engine.json. LY_EXTERNAL_SUBDIRS is a cache variable so the user can add extra
  65. # external subdirectories
  66. add_engine_json_external_subdirectories()
  67. else()
  68. ly_find_o3de_packages()
  69. endif()
  70. get_property(external_subdirs GLOBAL PROPERTY LY_EXTERNAL_SUBDIRS)
  71. list(APPEND LY_EXTERNAL_SUBDIRS ${external_subdirs})
  72. # Loop over the additional external subdirectories and invoke add_subdirectory on them
  73. foreach(external_directory ${LY_EXTERNAL_SUBDIRS})
  74. # Hash the extenal_directory name and append it to the Binary Directory section of add_subdirectory
  75. # This is to deal with potential situations where multiple external directories has the same last directory name
  76. # For example if D:/Company1/RayTracingGem and F:/Company2/Path/RayTracingGem were both added as a subdirectory
  77. file(REAL_PATH ${external_directory} full_directory_path)
  78. string(SHA256 full_directory_hash ${full_directory_path})
  79. # Truncate the full_directory_hash down to 8 characters to avoid hitting the Windows 260 character path limit
  80. # when the external subdirectory contains relative paths of significant length
  81. string(SUBSTRING ${full_directory_hash} 0 8 full_directory_hash)
  82. # Use the last directory as the suffix path to use for the Binary Directory
  83. get_filename_component(directory_name ${external_directory} NAME)
  84. add_subdirectory(${external_directory} ${CMAKE_BINARY_DIR}/External/${directory_name}-${full_directory_hash})
  85. endforeach()
  86. ################################################################################
  87. # Post-processing
  88. ################################################################################
  89. # The following steps have to be done after all targets are registered:
  90. # 1. Add any dependencies registered via ly_enable_gems
  91. ly_enable_gems_delayed()
  92. # 2. Defer generation of the StaticModules.inl file which is needed to create the AZ::Module derived class in monolithic
  93. # builds until after all the targets are known and all the gems are enabled
  94. ly_delayed_generate_static_modules_inl()
  95. # 3. generate a settings registry .setreg file for all ly_add_project_dependencies() and ly_add_target_dependencies() calls
  96. # to provide applications with the filenames of gem modules to load
  97. # This must be done before ly_delayed_target_link_libraries() as that inserts BUILD_DEPENDENCIES as MANUALLY_ADDED_DEPENDENCIES
  98. # if the build dependency is a MODULE_LIBRARY. That would cause a false load dependency to be generated
  99. ly_delayed_generate_settings_registry()
  100. # 4. link targets where the dependency was yet not declared, we need to have the declaration so we do different
  101. # linking logic depending on the type of target
  102. ly_delayed_target_link_libraries()
  103. # 5. generate a registry file for unit testing for platforms that support unit testing
  104. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  105. ly_delayed_generate_unit_test_module_registry()
  106. endif()
  107. # 5. inject runtime dependencies to the targets. We need to do this after (1) since we are going to walk through
  108. # the dependencies
  109. ly_delayed_generate_runtime_dependencies()
  110. # 6. Perform test impact framework post steps once all of the targets have been enumerated
  111. ly_test_impact_post_step()
  112. # 7. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  113. if(LY_INSTALL_ENABLED)
  114. # 8. Generate the O3DE find file and setup install locations for scripts, tools, assets etc., required by the engine
  115. ly_setup_o3de_install()
  116. # 9. CPack information (to be included after install)
  117. include(cmake/Packaging.cmake)
  118. endif()