CMakeLists.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # {BEGIN_LICENSE}
  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. # {END_LICENSE}
  8. # Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
  9. # Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
  10. # Note: o3de_pal_dir will take care of the details for us, as this may be a restricted platform
  11. # in which case it will see if that platform is present here or in the restricted folder.
  12. # i.e. It could here in our gem : Gems/${Name}/Code/Platform/<platorm_name> or
  13. # <restricted_folder>/<platform_name>/Gems/${Name}/Code
  14. o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
  15. # Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
  16. # traits for this platform. Traits for a platform are defines for things like whether or not something in this gem
  17. # is supported by this platform.
  18. include(${pal_dir}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  19. # Check to see if building the Gem Modules are supported for the current platform
  20. if(NOT PAL_TRAIT_${NameUpper}_SUPPORTED)
  21. return()
  22. endif()
  23. # The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
  24. ly_add_target(
  25. NAME ${gem_name}.API INTERFACE
  26. NAMESPACE Gem
  27. FILES_CMAKE
  28. ${NameLower}_api_files.cmake
  29. ${pal_dir}/${NameLower}_api_files.cmake
  30. INCLUDE_DIRECTORIES
  31. INTERFACE
  32. Include
  33. BUILD_DEPENDENCIES
  34. INTERFACE
  35. AZ::AzCore
  36. )
  37. # The ${gem_name}.Private.Object targets are internal targets
  38. # They should not be used outside of this Gems CMakeLists.txt
  39. ly_add_target(
  40. NAME ${gem_name}.Client.Private.Object STATIC
  41. NAMESPACE Gem
  42. FILES_CMAKE
  43. ${NameLower}_private_files.cmake
  44. ${pal_dir}/${NameLower}_private_files.cmake
  45. TARGET_PROPERTIES
  46. O3DE_PRIVATE_TARGET TRUE
  47. INCLUDE_DIRECTORIES
  48. PRIVATE
  49. Include
  50. Source
  51. BUILD_DEPENDENCIES
  52. PUBLIC
  53. AZ::AzCore
  54. AZ::AzFramework
  55. Gem::Multiplayer.Client
  56. PRIVATE
  57. Gem::Multiplayer.Client.Static
  58. )
  59. ly_add_target(
  60. NAME ${gem_name}.Server.Private.Object STATIC
  61. NAMESPACE Gem
  62. FILES_CMAKE
  63. ${NameLower}_private_files.cmake
  64. ${pal_dir}/${NameLower}_private_files.cmake
  65. TARGET_PROPERTIES
  66. O3DE_PRIVATE_TARGET TRUE
  67. INCLUDE_DIRECTORIES
  68. PRIVATE
  69. Include
  70. Source
  71. BUILD_DEPENDENCIES
  72. PUBLIC
  73. AZ::AzCore
  74. AZ::AzFramework
  75. Gem::Multiplayer.Server
  76. PRIVATE
  77. Gem::Multiplayer.Server.Static
  78. )
  79. ly_add_target(
  80. NAME ${gem_name}.Unified.Private.Object STATIC
  81. NAMESPACE Gem
  82. FILES_CMAKE
  83. ${NameLower}_private_files.cmake
  84. ${pal_dir}/${NameLower}_private_files.cmake
  85. TARGET_PROPERTIES
  86. O3DE_PRIVATE_TARGET TRUE
  87. INCLUDE_DIRECTORIES
  88. PRIVATE
  89. Include
  90. Source
  91. BUILD_DEPENDENCIES
  92. PUBLIC
  93. AZ::AzCore
  94. AZ::AzFramework
  95. Gem::Multiplayer
  96. PRIVATE
  97. Gem::Multiplayer.Unified.Static
  98. )
  99. # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
  100. ly_add_target(
  101. NAME ${gem_name}.Client ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  102. NAMESPACE Gem
  103. FILES_CMAKE
  104. ${NameLower}_shared_files.cmake
  105. ${pal_dir}/${NameLower}_shared_files.cmake
  106. INCLUDE_DIRECTORIES
  107. PUBLIC
  108. Include
  109. PRIVATE
  110. Source
  111. BUILD_DEPENDENCIES
  112. PUBLIC
  113. Gem::${gem_name}.API
  114. PRIVATE
  115. Gem::${gem_name}.Client.Private.Object
  116. )
  117. ly_add_target(
  118. NAME ${gem_name}.Server ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  119. NAMESPACE Gem
  120. FILES_CMAKE
  121. ${NameLower}_shared_files.cmake
  122. ${pal_dir}/${NameLower}_shared_files.cmake
  123. INCLUDE_DIRECTORIES
  124. PUBLIC
  125. Include
  126. PRIVATE
  127. Source
  128. BUILD_DEPENDENCIES
  129. PUBLIC
  130. Gem::${gem_name}.API
  131. PRIVATE
  132. Gem::${gem_name}.Server.Private.Object
  133. )
  134. ly_add_target(
  135. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  136. NAMESPACE Gem
  137. FILES_CMAKE
  138. ${NameLower}_shared_files.cmake
  139. ${pal_dir}/${NameLower}_shared_files.cmake
  140. INCLUDE_DIRECTORIES
  141. PUBLIC
  142. Include
  143. PRIVATE
  144. Source
  145. BUILD_DEPENDENCIES
  146. PUBLIC
  147. Gem::${gem_name}.API
  148. PRIVATE
  149. Gem::${gem_name}.Unified.Private.Object
  150. )
  151. # Include the gem name into Module source file
  152. # for use with the AZ_DECLARE_MODULE_CLASS macro
  153. # This is to allow renaming of the gem to also cause
  154. # the CreateModuleClass_Gem_<gem-name> function which
  155. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  156. ly_add_source_properties(
  157. SOURCES
  158. Source/Unified/${Name}Module.cpp
  159. PROPERTY COMPILE_DEFINITIONS
  160. VALUES
  161. O3DE_GEM_NAME=${gem_name}
  162. O3DE_GEM_VERSION=${gem_version})
  163. # By default, we will specify that the above target ${gem_name} would be used by
  164. # Client and Server type targets when this gem is enabled. If you don't want it
  165. # active in Clients or Servers by default, delete one of both of the following lines:
  166. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name}.Client)
  167. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name}.Server)
  168. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  169. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  170. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  171. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  172. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  173. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  174. # for the Clients, Servers and Unified gem variants
  175. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
  176. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  177. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  178. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  179. ly_add_target(
  180. NAME ${gem_name}.Editor.API INTERFACE
  181. NAMESPACE Gem
  182. FILES_CMAKE
  183. ${NameLower}_editor_api_files.cmake
  184. ${pal_dir}/${NameLower}_editor_api_files.cmake
  185. INCLUDE_DIRECTORIES
  186. INTERFACE
  187. Include
  188. BUILD_DEPENDENCIES
  189. INTERFACE
  190. AZ::AzToolsFramework
  191. )
  192. # The ${gem_name}.Editor.Private.Object target is an internal target
  193. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  194. # Other gems should not use this target
  195. ly_add_target(
  196. NAME ${gem_name}.Editor.Private.Object STATIC
  197. NAMESPACE Gem
  198. FILES_CMAKE
  199. ${NameLower}_editor_private_files.cmake
  200. TARGET_PROPERTIES
  201. O3DE_PRIVATE_TARGET TRUE
  202. INCLUDE_DIRECTORIES
  203. PRIVATE
  204. Include
  205. Source
  206. BUILD_DEPENDENCIES
  207. PUBLIC
  208. AZ::AzToolsFramework
  209. ${gem_name}.Unified.Private.Object
  210. )
  211. ly_add_target(
  212. NAME ${gem_name}.Editor GEM_MODULE
  213. NAMESPACE Gem
  214. AUTOMOC
  215. FILES_CMAKE
  216. ${NameLower}_editor_shared_files.cmake
  217. INCLUDE_DIRECTORIES
  218. PRIVATE
  219. Source
  220. PUBLIC
  221. Include
  222. BUILD_DEPENDENCIES
  223. PUBLIC
  224. Gem::${gem_name}.Editor.API
  225. PRIVATE
  226. Gem::${gem_name}.Editor.Private.Object
  227. )
  228. # Include the gem name into the Editor Module source file
  229. # for use with the AZ_DECLARE_MODULE_CLASS macro
  230. # This is to allow renaming of the gem to also cause
  231. # the CreateModuleClass_Gem_<gem-name> function which
  232. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  233. ly_add_source_properties(
  234. SOURCES
  235. Source/Tools/${Name}EditorModule.cpp
  236. PROPERTY COMPILE_DEFINITIONS
  237. VALUES
  238. O3DE_GEM_NAME=${gem_name}
  239. O3DE_GEM_VERSION=${gem_version})
  240. # By default, we will specify that the above target ${gem_name} would be used by
  241. # Tool and Builder type targets when this gem is enabled. If you don't want it
  242. # active in Tools or Builders by default, delete one of both of the following lines:
  243. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  244. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  245. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  246. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  247. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  248. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  249. # for the Tools and Builders gem variants
  250. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  251. endif()
  252. ################################################################################
  253. # Tests
  254. ################################################################################
  255. # See if globally, tests are supported
  256. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  257. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  258. if(PAL_TRAIT_${NameUpper}_TEST_SUPPORTED)
  259. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  260. ly_add_target(
  261. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  262. NAMESPACE Gem
  263. FILES_CMAKE
  264. ${NameLower}_tests_files.cmake
  265. INCLUDE_DIRECTORIES
  266. PRIVATE
  267. Tests
  268. Source
  269. BUILD_DEPENDENCIES
  270. PRIVATE
  271. AZ::AzTest
  272. AZ::AzFramework
  273. Gem::${gem_name}.Unified.Private.Object
  274. )
  275. # Add ${gem_name}.Tests to googletest
  276. ly_add_googletest(
  277. NAME Gem::${gem_name}.Tests
  278. )
  279. endif()
  280. # If we are a host platform we want to add tools test like editor tests here
  281. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  282. # We are a host platform, see if Editor tests are supported on this platform
  283. if(PAL_TRAIT_${NameUpper}_EDITOR_TEST_SUPPORTED)
  284. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  285. # private ${gem_name}.Editor.Private.Object target
  286. ly_add_target(
  287. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  288. NAMESPACE Gem
  289. FILES_CMAKE
  290. ${NameLower}_editor_tests_files.cmake
  291. INCLUDE_DIRECTORIES
  292. PRIVATE
  293. Tests
  294. Source
  295. BUILD_DEPENDENCIES
  296. PRIVATE
  297. AZ::AzTest
  298. Gem::${gem_name}.Unified.Private.Object
  299. )
  300. # Add ${gem_name}.Editor.Tests to googletest
  301. ly_add_googletest(
  302. NAME Gem::${gem_name}.Editor.Tests
  303. )
  304. endif()
  305. endif()
  306. endif()