CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. # By default, we will specify that the above target ${gem_name} would be used by
  152. # Client and Server type targets when this gem is enabled. If you don't want it
  153. # active in Clients or Servers by default, delete one of both of the following lines:
  154. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name}.Client)
  155. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name}.Server)
  156. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  157. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  158. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  159. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  160. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  161. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  162. # for the Clients, Servers and Unified gem variants
  163. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
  164. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  165. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  166. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  167. ly_add_target(
  168. NAME ${gem_name}.Editor.API INTERFACE
  169. NAMESPACE Gem
  170. FILES_CMAKE
  171. ${NameLower}_editor_api_files.cmake
  172. ${pal_dir}/${NameLower}_editor_api_files.cmake
  173. INCLUDE_DIRECTORIES
  174. INTERFACE
  175. Include
  176. BUILD_DEPENDENCIES
  177. INTERFACE
  178. AZ::AzToolsFramework
  179. )
  180. # The ${gem_name}.Editor.Private.Object target is an internal target
  181. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  182. # Other gems should not use this target
  183. ly_add_target(
  184. NAME ${gem_name}.Editor.Private.Object STATIC
  185. NAMESPACE Gem
  186. FILES_CMAKE
  187. ${NameLower}_editor_private_files.cmake
  188. TARGET_PROPERTIES
  189. O3DE_PRIVATE_TARGET TRUE
  190. INCLUDE_DIRECTORIES
  191. PRIVATE
  192. Include
  193. Source
  194. BUILD_DEPENDENCIES
  195. PUBLIC
  196. AZ::AzToolsFramework
  197. $<TARGET_OBJECTS:Gem::${gem_name}.Unified.Private.Object>
  198. )
  199. ly_add_target(
  200. NAME ${gem_name}.Editor GEM_MODULE
  201. NAMESPACE Gem
  202. AUTOMOC
  203. FILES_CMAKE
  204. ${NameLower}_editor_shared_files.cmake
  205. INCLUDE_DIRECTORIES
  206. PRIVATE
  207. Source
  208. PUBLIC
  209. Include
  210. BUILD_DEPENDENCIES
  211. PUBLIC
  212. Gem::${gem_name}.Editor.API
  213. PRIVATE
  214. Gem::${gem_name}.Editor.Private.Object
  215. )
  216. # By default, we will specify that the above target ${gem_name} would be used by
  217. # Tool and Builder type targets when this gem is enabled. If you don't want it
  218. # active in Tools or Builders by default, delete one of both of the following lines:
  219. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  220. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  221. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  222. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  223. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  224. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  225. # for the Tools and Builders gem variants
  226. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  227. endif()
  228. ################################################################################
  229. # Tests
  230. ################################################################################
  231. # See if globally, tests are supported
  232. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  233. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  234. if(PAL_TRAIT_${NameUpper}_TEST_SUPPORTED)
  235. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  236. ly_add_target(
  237. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  238. NAMESPACE Gem
  239. FILES_CMAKE
  240. ${NameLower}_tests_files.cmake
  241. INCLUDE_DIRECTORIES
  242. PRIVATE
  243. Tests
  244. Source
  245. BUILD_DEPENDENCIES
  246. PRIVATE
  247. AZ::AzTest
  248. AZ::AzFramework
  249. Gem::${gem_name}.Unified.Private.Object
  250. )
  251. # Add ${gem_name}.Tests to googletest
  252. ly_add_googletest(
  253. NAME Gem::${gem_name}.Tests
  254. )
  255. endif()
  256. # If we are a host platform we want to add tools test like editor tests here
  257. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  258. # We are a host platform, see if Editor tests are supported on this platform
  259. if(PAL_TRAIT_${NameUpper}_EDITOR_TEST_SUPPORTED)
  260. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  261. # private ${gem_name}.Editor.Private.Object target
  262. ly_add_target(
  263. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  264. NAMESPACE Gem
  265. FILES_CMAKE
  266. ${NameLower}_editor_tests_files.cmake
  267. INCLUDE_DIRECTORIES
  268. PRIVATE
  269. Tests
  270. Source
  271. BUILD_DEPENDENCIES
  272. PRIVATE
  273. AZ::AzTest
  274. Gem::${gem_name}.Unified.Private.Object
  275. )
  276. # Add ${gem_name}.Editor.Tests to googletest
  277. ly_add_googletest(
  278. NAME Gem::${gem_name}.Editor.Tests
  279. )
  280. endif()
  281. endif()
  282. endif()