CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. Gem::Atom_RPI.Public
  37. Gem::Atom_Feature_Common
  38. Gem::Atom_Feature_Common.Public
  39. Gem::Atom_Feature_Common.Static
  40. )
  41. # The ${gem_name}.Private.Object target is an internal target
  42. # It should not be used outside of this Gems CMakeLists.txt
  43. ly_add_target(
  44. NAME ${gem_name}.Private.Object STATIC
  45. NAMESPACE Gem
  46. FILES_CMAKE
  47. ${NameLower}_private_files.cmake
  48. ${pal_dir}/${NameLower}_private_files.cmake
  49. TARGET_PROPERTIES
  50. O3DE_PRIVATE_TARGET TRUE
  51. INCLUDE_DIRECTORIES
  52. PRIVATE
  53. Include
  54. Source
  55. BUILD_DEPENDENCIES
  56. PUBLIC
  57. AZ::AzCore
  58. AZ::AzFramework
  59. Gem::Atom_RPI.Public
  60. Gem::Atom_Utils.Static
  61. Gem::Atom_Feature_Common
  62. Gem::CommonFeaturesAtom.Static
  63. )
  64. # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
  65. ly_add_target(
  66. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  67. NAMESPACE Gem
  68. FILES_CMAKE
  69. ${NameLower}_shared_files.cmake
  70. ${pal_dir}/${NameLower}_shared_files.cmake
  71. INCLUDE_DIRECTORIES
  72. PUBLIC
  73. Include
  74. PRIVATE
  75. Source
  76. BUILD_DEPENDENCIES
  77. PUBLIC
  78. Gem::${gem_name}.API
  79. PRIVATE
  80. Gem::${gem_name}.Private.Object
  81. )
  82. # Include the gem name into the Client Module source file
  83. # for use with the AZ_DECLARE_MODULE_CLASS macro
  84. # This is to allow renaming of the gem to also cause
  85. # the CreateModuleClass_Gem_<gem-name> function which
  86. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  87. ly_add_source_properties(
  88. SOURCES
  89. Source/Clients/${Name}Module.cpp
  90. PROPERTY COMPILE_DEFINITIONS
  91. VALUES
  92. O3DE_GEM_NAME=${gem_name}
  93. O3DE_GEM_VERSION=${gem_version})
  94. # By default, we will specify that the above target ${gem_name} would be used by
  95. # Client and Server type targets when this gem is enabled. If you don't want it
  96. # active in Clients or Servers by default, delete one of both of the following lines:
  97. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  98. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  99. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  100. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  101. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  102. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  103. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  104. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  105. # for the Clients, Servers and Unified gem variants
  106. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
  107. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  108. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  109. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  110. ly_add_target(
  111. NAME ${gem_name}.Editor.API INTERFACE
  112. NAMESPACE Gem
  113. FILES_CMAKE
  114. ${NameLower}_editor_api_files.cmake
  115. ${pal_dir}/${NameLower}_editor_api_files.cmake
  116. INCLUDE_DIRECTORIES
  117. INTERFACE
  118. Include
  119. BUILD_DEPENDENCIES
  120. INTERFACE
  121. AZ::AzToolsFramework
  122. )
  123. # The ${gem_name}.Editor.Private.Object target is an internal target
  124. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  125. # Other gems should not use this target
  126. ly_add_target(
  127. NAME ${gem_name}.Editor.Private.Object STATIC
  128. NAMESPACE Gem
  129. FILES_CMAKE
  130. ${NameLower}_editor_private_files.cmake
  131. TARGET_PROPERTIES
  132. O3DE_PRIVATE_TARGET TRUE
  133. INCLUDE_DIRECTORIES
  134. PRIVATE
  135. Include
  136. Source
  137. BUILD_DEPENDENCIES
  138. PUBLIC
  139. AZ::AzToolsFramework
  140. $<TARGET_OBJECTS:Gem::${gem_name}.Private.Object>
  141. Gem::Atom_Utils.Static
  142. Gem::Atom_Feature_Common.Static
  143. Gem::CommonFeaturesAtom.Static
  144. )
  145. ly_add_target(
  146. NAME ${gem_name}.Editor GEM_MODULE
  147. NAMESPACE Gem
  148. AUTOMOC
  149. FILES_CMAKE
  150. ${NameLower}_editor_shared_files.cmake
  151. INCLUDE_DIRECTORIES
  152. PRIVATE
  153. Source
  154. PUBLIC
  155. Include
  156. BUILD_DEPENDENCIES
  157. PUBLIC
  158. Gem::${gem_name}.Editor.API
  159. PRIVATE
  160. Gem::${gem_name}.Editor.Private.Object
  161. )
  162. # Include the gem name into the Editor Module source file
  163. # for use with the AZ_DECLARE_MODULE_CLASS macro
  164. # This is to allow renaming of the gem to also cause
  165. # the CreateModuleClass_Gem_<gem-name> function which
  166. # is used to bootstrap the gem in monolithic builds to link to the new gem name
  167. ly_add_source_properties(
  168. SOURCES
  169. Source/Tools/${Name}EditorModule.cpp
  170. PROPERTY COMPILE_DEFINITIONS
  171. VALUES
  172. O3DE_GEM_NAME=${gem_name}
  173. O3DE_GEM_VERSION=${gem_version})
  174. # By default, we will specify that the above target ${gem_name} would be used by
  175. # Tool and Builder type targets when this gem is enabled. If you don't want it
  176. # active in Tools or Builders by default, delete one of both of the following lines:
  177. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  178. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  179. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  180. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  181. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  182. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  183. # for the Tools and Builders gem variants
  184. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  185. endif()
  186. ################################################################################
  187. # Tests
  188. ################################################################################
  189. # See if globally, tests are supported
  190. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  191. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  192. if(PAL_TRAIT_${NameUpper}_TEST_SUPPORTED)
  193. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  194. ly_add_target(
  195. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  196. NAMESPACE Gem
  197. FILES_CMAKE
  198. ${NameLower}_tests_files.cmake
  199. INCLUDE_DIRECTORIES
  200. PRIVATE
  201. Tests
  202. Source
  203. Include
  204. BUILD_DEPENDENCIES
  205. PRIVATE
  206. AZ::AzTest
  207. AZ::AzFramework
  208. Gem::${gem_name}.Private.Object
  209. )
  210. # Add ${gem_name}.Tests to googletest
  211. ly_add_googletest(
  212. NAME Gem::${gem_name}.Tests
  213. )
  214. endif()
  215. # If we are a host platform we want to add tools test like editor tests here
  216. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  217. # We are a host platform, see if Editor tests are supported on this platform
  218. if(PAL_TRAIT_${NameUpper}_EDITOR_TEST_SUPPORTED)
  219. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  220. # private ${gem_name}.Editor.Private.Object target
  221. ly_add_target(
  222. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  223. NAMESPACE Gem
  224. FILES_CMAKE
  225. ${NameLower}_editor_tests_files.cmake
  226. INCLUDE_DIRECTORIES
  227. PRIVATE
  228. Tests
  229. Source
  230. Include
  231. BUILD_DEPENDENCIES
  232. PRIVATE
  233. AZ::AzTest
  234. Gem::${gem_name}.Editor.Private.Object
  235. )
  236. # Add ${gem_name}.Editor.Tests to googletest
  237. ly_add_googletest(
  238. NAME Gem::${gem_name}.Editor.Tests
  239. )
  240. endif()
  241. endif()
  242. endif()