CMakeLists.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. # TODO: would like to be able to build from this path, however, the whole setup is done at the workspace's root
  9. # we also dont want to drop cmake output files everywhere.
  10. o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
  11. set(common_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/Common)
  12. if(PAL_TRAIT_PROF_PIX_SUPPORTED)
  13. set(LY_PIX_ENABLED OFF CACHE BOOL "Enables PIX profiler integration.")
  14. if(LY_PIX_ENABLED)
  15. message(STATUS "PIX found, enabling as profiler")
  16. set(AZ_CORE_PIX_BUILD_DEPENDENCIES 3rdParty::pix)
  17. endif()
  18. endif()
  19. # By default, the Settings Registry will apply user and project registry files as overrides in development (non-release) builds,
  20. # and will ignore all overrides in release builds.
  21. # This behavior can be overridden by passing -DALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES=0, 1, 2, 3 or 4 when generating the build files.
  22. # The override can be removed by passing -UALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES when generating the build files.
  23. set(ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES "" CACHE STRING
  24. "Forces the Settings Registry development overrides to be used or ignored.
  25. If unset, development overrides are used in development builds and ignored in release builds.
  26. 0 disables the development overrides in all builds.
  27. 1 = registry overrides are allowed from the command line.
  28. 2 = registry overrides are allowed from the engine, gem, and project files (not command line).
  29. 3 = registry overrides are allowed from the command line, engine, gem, and project files.
  30. 4 = registry overrides are allowed from the command line, engine, gem, project, and user files.")
  31. # If there's a value in ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES, the compiler flag will get set to it.
  32. # Otherwise, the variable will be empty and no compiler flag will be set, leaving it to the code to decide
  33. # whether or not to allow the Settings Registry development overrides.
  34. set(ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES_FLAG $<$<NOT:$<STREQUAL:"${ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES}","">>:ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES=${ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES}>)
  35. # If empty, the allocator initialization startup config file will be checked for on startup in development (non-release) builds
  36. # This behavior can be overridden by passing -DO3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE=0,1 to either prevent/force checking for the startup config file.
  37. # The override can be removed by reconfiguring with CMake using the -UO3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE option to undefine the cache variable.
  38. set(O3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE "" CACHE STRING
  39. "If unset, the default behavior is to check for a startup config file in development builds only.
  40. When set to a falsey value(0, FALSE, OFF, etc...), no build configuration will check for a startup config file.
  41. When set to any other value all build configurations will check for a startup config file.
  42. NOTE: The startup config file is able to initialize O3DE allocator settings using a Windows-style INI file by specifying
  43. the path to the file in 1 of 4 locations
  44. 1. ~/.o3de/Registry/startup.cfg
  45. 2. <executable-directory>/Registry/startup.cfg
  46. 3. The value of the O3DE_STARTUP_CFG_FILE environment variable if set
  47. 4. The value of the --startup-cfg-file command line argument")
  48. # If there's a value in ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES, the compiler flag will get set to it.
  49. # Otherwise, the variable will be empty and no compiler flag will be set, leaving it to the code to decide
  50. # whether or not to allow the Settings Registry development overrides.
  51. set(STARTUP_CFG_FILE_CHECK_OVERRIDE_FLAG $<$<NOT:$<STREQUAL:"${O3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE}","">>:O3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE=$<BOOL:${O3DE_STARTUP_CFG_FILE_CHECK_OVERRIDE}>>)
  52. ly_add_target(
  53. NAME O3DEKernel ${PAL_TRAIT_MONOLITHIC_DRIVEN_LIBRARY_TYPE}
  54. NAMESPACE AZ
  55. FILES_CMAKE
  56. AzCore/o3dekernel_files.cmake
  57. PLATFORM_INCLUDE_FILES
  58. ${pal_dir}/o3dekernel_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  59. INCLUDE_DIRECTORIES
  60. PUBLIC
  61. .
  62. ${pal_dir}
  63. ${common_dir}
  64. )
  65. ly_add_target(
  66. NAME AzCore STATIC
  67. NAMESPACE AZ
  68. FILES_CMAKE
  69. AzCore/azcore_files.cmake
  70. AzCore/std/azstd_files.cmake
  71. ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  72. PLATFORM_INCLUDE_FILES
  73. ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  74. INCLUDE_DIRECTORIES
  75. PUBLIC
  76. .
  77. ${pal_dir}
  78. ${common_dir}
  79. BUILD_DEPENDENCIES
  80. PUBLIC
  81. 3rdParty::Lua
  82. 3rdParty::RapidJSON
  83. 3rdParty::RapidXML
  84. 3rdParty::ZLIB
  85. 3rdParty::zstd
  86. 3rdParty::cityhash
  87. ${AZ_CORE_PIX_BUILD_DEPENDENCIES}
  88. AZ::O3DEKernel
  89. )
  90. ly_add_source_properties(
  91. SOURCES
  92. AzCore/Script/ScriptSystemComponent.cpp
  93. AzCore/PlatformId/PlatformId.cpp
  94. PROPERTY COMPILE_DEFINITIONS
  95. VALUES ${LY_PAL_TOOLS_DEFINES}
  96. )
  97. ly_add_source_properties(
  98. SOURCES
  99. AzCore/Component/ComponentApplication.cpp
  100. PROPERTY COMPILE_DEFINITIONS
  101. VALUES ${ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES_FLAG}
  102. ${STARTUP_CFG_FILE_CHECK_OVERRIDE_FLAG}
  103. )
  104. # Add the O3DE_STACK_CAPTURE_DEPTH define only to the cpp files for the following allocators
  105. # This reduces re-compile time when the cache variable value changes.
  106. set(O3DE_STACK_CAPTURE_DEPTH_DEFINE $<$<NOT:$<STREQUAL:"${O3DE_STACK_CAPTURE_DEPTH}","">>:O3DE_STACK_CAPTURE_DEPTH=${O3DE_STACK_CAPTURE_DEPTH}>)
  107. ly_add_source_properties(
  108. SOURCES
  109. AzCore/Memory/OSAllocator.cpp
  110. AzCore/Memory/PoolAllocator.cpp
  111. AzCore/Memory/SystemAllocator.cpp
  112. PROPERTY COMPILE_DEFINITIONS
  113. VALUES ${O3DE_STACK_CAPTURE_DEPTH_DEFINE}
  114. )
  115. if(LY_BUILD_WITH_ADDRESS_SANITIZER)
  116. # Default to use Malloc schema so ASan works well
  117. ly_add_source_properties(
  118. SOURCES AzCore/Memory/SystemAllocator.cpp
  119. PROPERTY COMPILE_DEFINITIONS
  120. VALUES AZCORE_SYSTEM_ALLOCATOR=AZCORE_SYSTEM_ALLOCATOR_MALLOC
  121. )
  122. endif()
  123. ################################################################################
  124. # Tests
  125. ################################################################################
  126. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  127. ly_add_target(
  128. NAME AzCoreTestCommon STATIC
  129. NAMESPACE AZ
  130. FILES_CMAKE
  131. AzCore/azcoretestcommon_files.cmake
  132. INCLUDE_DIRECTORIES
  133. PRIVATE
  134. .
  135. ${pal_dir}
  136. ${common_dir}
  137. BUILD_DEPENDENCIES
  138. PRIVATE
  139. 3rdParty::googletest::GMock
  140. 3rdParty::GoogleBenchmark
  141. )
  142. ly_add_target(
  143. NAME AzTestShared STATIC
  144. NAMESPACE AZ
  145. FILES_CMAKE
  146. Tests/aztestshared_files.cmake
  147. INCLUDE_DIRECTORIES
  148. PUBLIC
  149. Tests
  150. BUILD_DEPENDENCIES
  151. PRIVATE
  152. AZ::AzTest
  153. AZ::AzCore
  154. )
  155. ly_add_target(
  156. NAME AzCoreTestDLL MODULE
  157. NAMESPACE AZ
  158. FILES_CMAKE
  159. Tests/azcoretestdll_files.cmake
  160. INCLUDE_DIRECTORIES
  161. PUBLIC
  162. Tests
  163. BUILD_DEPENDENCIES
  164. PRIVATE
  165. AZ::AzCore
  166. )
  167. o3de_pal_dir(pal_tests_dir ${CMAKE_CURRENT_LIST_DIR}/Tests/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
  168. ly_add_target(
  169. NAME AzCore.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  170. NAMESPACE AZ
  171. FILES_CMAKE
  172. Tests/azcoretests_files.cmake
  173. ${pal_tests_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  174. PLATFORM_INCLUDE_FILES
  175. ${pal_tests_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  176. INCLUDE_DIRECTORIES
  177. PRIVATE
  178. Tests
  179. COMPILE_DEFINITIONS
  180. PRIVATE
  181. AZ_NUMERICCAST_ENABLED
  182. BUILD_DEPENDENCIES
  183. PRIVATE
  184. AZ::AzCore
  185. AZ::AzCoreTestCommon
  186. AZ::AzTestShared
  187. AZ::AzTest
  188. RUNTIME_DEPENDENCIES
  189. AZ::AzCoreTestDLL
  190. )
  191. ly_add_googletest(
  192. NAME AZ::AzCore.Tests
  193. LABELS REQUIRES_tiaf
  194. )
  195. ly_add_googletest(
  196. NAME AZ::AzCore.Tests
  197. TEST_SUITE sandbox
  198. )
  199. ly_add_googlebenchmark(
  200. NAME AZ::AzCore.Benchmarks
  201. TARGET AZ::AzCore.Tests
  202. )
  203. ly_add_source_properties(
  204. SOURCES Tests/Debug.cpp
  205. PROPERTY COMPILE_DEFINITIONS
  206. VALUES AZCORETEST_DLL_NAME=\"$<TARGET_FILE_NAME:AzCore.Tests>\"
  207. )
  208. ly_add_target_files(
  209. TARGETS AzCore.Tests
  210. FILES ${CMAKE_CURRENT_SOURCE_DIR}/Tests/Memory/AllocatorBenchmarkRecordings.bin
  211. OUTPUT_SUBDIRECTORY Tests/AzCore/Memory
  212. )
  213. endif()