CMakeLists.txt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 target is an internal target
  38. # It should not be used outside of this Gems CMakeLists.txt
  39. ly_add_target(
  40. NAME ${gem_name}.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. )
  56. # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
  57. ly_add_target(
  58. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  59. NAMESPACE Gem
  60. FILES_CMAKE
  61. ${NameLower}_shared_files.cmake
  62. ${pal_dir}/${NameLower}_shared_files.cmake
  63. INCLUDE_DIRECTORIES
  64. PUBLIC
  65. Include
  66. PRIVATE
  67. Source
  68. BUILD_DEPENDENCIES
  69. PUBLIC
  70. Gem::${gem_name}.API
  71. PRIVATE
  72. Gem::${gem_name}.Private.Object
  73. )
  74. # By default, we will specify that the above target ${gem_name} would be used by
  75. # Client and Server type targets when this gem is enabled. If you don't want it
  76. # active in Clients or Servers by default, delete one of both of the following lines:
  77. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  78. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  79. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  80. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  81. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  82. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  83. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  84. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  85. # for the Clients, Servers and Unified gem variants
  86. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Clients Servers Unified)
  87. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor MODULE target
  88. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  89. # The ${gem_name}.Editor.API target can be used by other gems that want to interact with the ${gem_name}.Editor module
  90. ly_add_target(
  91. NAME ${gem_name}.Editor.API INTERFACE
  92. NAMESPACE Gem
  93. FILES_CMAKE
  94. ${NameLower}_editor_api_files.cmake
  95. ${pal_dir}/${NameLower}_editor_api_files.cmake
  96. INCLUDE_DIRECTORIES
  97. INTERFACE
  98. Include
  99. BUILD_DEPENDENCIES
  100. INTERFACE
  101. AZ::AzToolsFramework
  102. )
  103. # The ${gem_name}.Editor.Private.Object target is an internal target
  104. # which is only to be used by this gems CMakeLists.txt and any subdirectories
  105. # Other gems should not use this target
  106. ly_add_target(
  107. NAME ${gem_name}.Editor.Private.Object STATIC
  108. NAMESPACE Gem
  109. AUTOMOC
  110. AUTORCC
  111. FILES_CMAKE
  112. ${NameLower}_editor_private_files.cmake
  113. TARGET_PROPERTIES
  114. O3DE_PRIVATE_TARGET TRUE
  115. INCLUDE_DIRECTORIES
  116. PRIVATE
  117. Include
  118. Source
  119. BUILD_DEPENDENCIES
  120. PUBLIC
  121. AZ::AzToolsFramework
  122. $<TARGET_OBJECTS:Gem::${gem_name}.Private.Object>
  123. )
  124. ly_add_target(
  125. NAME ${gem_name}.Editor GEM_MODULE
  126. NAMESPACE Gem
  127. AUTOMOC
  128. FILES_CMAKE
  129. ${NameLower}_editor_shared_files.cmake
  130. INCLUDE_DIRECTORIES
  131. PRIVATE
  132. Source
  133. PUBLIC
  134. Include
  135. BUILD_DEPENDENCIES
  136. PUBLIC
  137. Gem::${gem_name}.Editor.API
  138. PRIVATE
  139. Gem::${gem_name}.Editor.Private.Object
  140. )
  141. # By default, we will specify that the above target ${gem_name} would be used by
  142. # Tool and Builder type targets when this gem is enabled. If you don't want it
  143. # active in Tools or Builders by default, delete one of both of the following lines:
  144. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  145. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  146. # For the Tools and Builders variants of ${gem_name} Gem, an alias to the ${gem_name}.Editor API target will be made
  147. ly_create_alias(NAME ${gem_name}.Tools.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  148. ly_create_alias(NAME ${gem_name}.Builders.API NAMESPACE Gem TARGETS Gem::${gem_name}.Editor.API)
  149. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  150. # for the Tools and Builders gem variants
  151. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  152. endif()
  153. ################################################################################
  154. # Tests
  155. ################################################################################
  156. # See if globally, tests are supported
  157. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  158. # We globally support tests, see if we support tests on this platform for ${gem_name}.Tests
  159. if(PAL_TRAIT_${NameUpper}_TEST_SUPPORTED)
  160. # We support ${gem_name}.Tests on this platform, add dependency on the Private Object target
  161. ly_add_target(
  162. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  163. NAMESPACE Gem
  164. FILES_CMAKE
  165. ${NameLower}_tests_files.cmake
  166. INCLUDE_DIRECTORIES
  167. PRIVATE
  168. Tests
  169. Source
  170. Include
  171. BUILD_DEPENDENCIES
  172. PRIVATE
  173. AZ::AzTest
  174. AZ::AzFramework
  175. Gem::${gem_name}.Private.Object
  176. )
  177. # Add ${gem_name}.Tests to googletest
  178. ly_add_googletest(
  179. NAME Gem::${gem_name}.Tests
  180. )
  181. endif()
  182. # If we are a host platform we want to add tools test like editor tests here
  183. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  184. # We are a host platform, see if Editor tests are supported on this platform
  185. if(PAL_TRAIT_${NameUpper}_EDITOR_TEST_SUPPORTED)
  186. # We support ${gem_name}.Editor.Tests on this platform, add ${gem_name}.Editor.Tests target which depends on
  187. # private ${gem_name}.Editor.Private.Object target
  188. ly_add_target(
  189. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  190. NAMESPACE Gem
  191. FILES_CMAKE
  192. ${NameLower}_editor_tests_files.cmake
  193. INCLUDE_DIRECTORIES
  194. PRIVATE
  195. Tests
  196. Source
  197. Include
  198. BUILD_DEPENDENCIES
  199. PRIVATE
  200. AZ::AzTest
  201. Gem::${gem_name}.Editor.Private.Object
  202. )
  203. # Add ${gem_name}.Editor.Tests to googletest
  204. ly_add_googletest(
  205. NAME Gem::${gem_name}.Editor.Tests
  206. )
  207. endif()
  208. endif()
  209. endif()