CMakeLists.txt 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 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. COMPILE_DEFINITIONS
  73. PRIVATE
  74. AZCORE_EXPORTS
  75. PLATFORM_INCLUDE_FILES
  76. ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  77. INCLUDE_DIRECTORIES
  78. PUBLIC
  79. .
  80. ${pal_dir}
  81. ${common_dir}
  82. BUILD_DEPENDENCIES
  83. PRIVATE
  84. ${AZ_CORE_PIX_BUILD_DEPENDENCIES}
  85. PUBLIC
  86. 3rdParty::Lua
  87. 3rdParty::RapidJSON
  88. 3rdParty::RapidXML
  89. 3rdParty::ZLIB
  90. 3rdParty::zstd
  91. 3rdParty::cityhash
  92. AZ::O3DEKernel
  93. )
  94. ly_add_target(
  95. NAME AzCore ${PAL_TRAIT_MONOLITHIC_DRIVEN_LIBRARY_TYPE}
  96. NAMESPACE AZ
  97. FILES_CMAKE
  98. AzCore/azcoreshared_files.cmake
  99. BUILD_DEPENDENCIES
  100. PUBLIC
  101. AZ::AzCore.Static
  102. )
  103. ly_add_source_properties(
  104. SOURCES
  105. AzCore/Script/ScriptSystemComponent.cpp
  106. AzCore/PlatformId/PlatformId.cpp
  107. PROPERTY COMPILE_DEFINITIONS
  108. VALUES ${LY_PAL_TOOLS_DEFINES}
  109. )
  110. ly_add_source_properties(
  111. SOURCES
  112. AzCore/Component/ComponentApplication.cpp
  113. PROPERTY COMPILE_DEFINITIONS
  114. VALUES ${ALLOW_SETTINGS_REGISTRY_DEVELOPMENT_OVERRIDES_FLAG}
  115. ${STARTUP_CFG_FILE_CHECK_OVERRIDE_FLAG}
  116. )
  117. # Add the O3DE_STACK_CAPTURE_DEPTH define only to the cpp files for the following allocators
  118. # This reduces re-compile time when the cache variable value changes.
  119. set(O3DE_STACK_CAPTURE_DEPTH_DEFINE $<$<NOT:$<STREQUAL:"${O3DE_STACK_CAPTURE_DEPTH}","">>:O3DE_STACK_CAPTURE_DEPTH=${O3DE_STACK_CAPTURE_DEPTH}>)
  120. ly_add_source_properties(
  121. SOURCES
  122. AzCore/Memory/OSAllocator.cpp
  123. AzCore/Memory/PoolAllocator.cpp
  124. AzCore/Memory/SystemAllocator.cpp
  125. PROPERTY COMPILE_DEFINITIONS
  126. VALUES ${O3DE_STACK_CAPTURE_DEPTH_DEFINE}
  127. )
  128. if(LY_BUILD_WITH_ADDRESS_SANITIZER)
  129. # Default to use Malloc schema so ASan works well
  130. ly_add_source_properties(
  131. SOURCES AzCore/Memory/SystemAllocator.cpp
  132. PROPERTY COMPILE_DEFINITIONS
  133. VALUES AZCORE_SYSTEM_ALLOCATOR=AZCORE_SYSTEM_ALLOCATOR_MALLOC
  134. )
  135. endif()
  136. ################################################################################
  137. # Tests
  138. ################################################################################
  139. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  140. ly_add_target(
  141. NAME AzCoreTestCommon STATIC
  142. NAMESPACE AZ
  143. FILES_CMAKE
  144. AzCore/azcoretestcommon_files.cmake
  145. INCLUDE_DIRECTORIES
  146. PRIVATE
  147. .
  148. ${pal_dir}
  149. ${common_dir}
  150. BUILD_DEPENDENCIES
  151. PRIVATE
  152. AZ::AzTest
  153. 3rdParty::GoogleBenchmark
  154. )
  155. ly_add_target(
  156. NAME AzTestShared STATIC
  157. NAMESPACE AZ
  158. FILES_CMAKE
  159. Tests/aztestshared_files.cmake
  160. INCLUDE_DIRECTORIES
  161. PUBLIC
  162. Tests
  163. BUILD_DEPENDENCIES
  164. PRIVATE
  165. AZ::AzTest
  166. AZ::AzCore
  167. )
  168. ly_add_target(
  169. NAME AzCoreTestDLL MODULE
  170. NAMESPACE AZ
  171. FILES_CMAKE
  172. Tests/azcoretestdll_files.cmake
  173. INCLUDE_DIRECTORIES
  174. PUBLIC
  175. Tests
  176. BUILD_DEPENDENCIES
  177. PRIVATE
  178. AZ::AzCore
  179. )
  180. o3de_pal_dir(pal_tests_dir ${CMAKE_CURRENT_LIST_DIR}/Tests/Platform/${PAL_PLATFORM_NAME} ${O3DE_ENGINE_RESTRICTED_PATH} ${LY_ROOT_FOLDER})
  181. ly_add_target(
  182. NAME AzCore.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  183. NAMESPACE AZ
  184. FILES_CMAKE
  185. Tests/azcoretests_files.cmake
  186. ${pal_tests_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  187. PLATFORM_INCLUDE_FILES
  188. ${pal_tests_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
  189. INCLUDE_DIRECTORIES
  190. PRIVATE
  191. Tests
  192. COMPILE_DEFINITIONS
  193. PRIVATE
  194. AZ_NUMERICCAST_ENABLED
  195. BUILD_DEPENDENCIES
  196. PRIVATE
  197. AZ::AzCore
  198. AZ::AzCoreTestCommon
  199. AZ::AzTestShared
  200. AZ::AzTest
  201. RUNTIME_DEPENDENCIES
  202. AZ::AzCoreTestDLL
  203. )
  204. ly_add_googletest(
  205. NAME AZ::AzCore.Tests
  206. LABELS REQUIRES_tiaf
  207. )
  208. ly_add_googletest(
  209. NAME AZ::AzCore.Tests
  210. TEST_SUITE sandbox
  211. )
  212. ly_add_googlebenchmark(
  213. NAME AZ::AzCore.Benchmarks
  214. TARGET AZ::AzCore.Tests
  215. )
  216. ly_add_source_properties(
  217. SOURCES Tests/Debug.cpp
  218. PROPERTY COMPILE_DEFINITIONS
  219. VALUES AZCORETEST_DLL_NAME=\"$<TARGET_FILE_NAME:AzCore.Tests>\"
  220. )
  221. ly_add_target_files(
  222. TARGETS AzCore.Tests
  223. FILES ${CMAKE_CURRENT_SOURCE_DIR}/Tests/Memory/AllocatorBenchmarkRecordings.bin
  224. OUTPUT_SUBDIRECTORY Tests/AzCore/Memory
  225. )
  226. endif()