CMakeLists.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. # NOTE:To hook the pre-built binaries into the CMake targets, the binaries must be placed
  9. # at the IMPORTED_LOCATION property specified in the Code/Platform/${PAL_PLATFORM_NAME}/${NameLower}*.cmake files
  10. # Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
  11. # Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
  12. o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
  13. # Now that we have the platform abstraction layer (PAL) folder for this folder, thats where we will find the
  14. # traits for this platform. Traits for a platform are defines for things like whether or not something in this gem
  15. # is supported by this platform.
  16. include(${pal_dir}/PAL.cmake)
  17. # Check to see if the building the Gem Modules are supported for the current platform
  18. if(NOT PAL_TRAIT_${NameUpper}_SUPPORTED)
  19. return()
  20. endif()
  21. # The ${gem_name}.API target declares the common interface that users of this gem should depend on in their targets
  22. ly_add_target(
  23. NAME ${gem_name}.API INTERFACE
  24. NAMESPACE Gem
  25. FILES_CMAKE
  26. ${NameLower}_api_files.cmake
  27. ${pal_dir}/${NameLower}_api_files.cmake
  28. INCLUDE_DIRECTORIES
  29. INTERFACE
  30. Include
  31. BUILD_DEPENDENCIES
  32. INTERFACE
  33. AZ::AzCore
  34. TARGET_PROPERTIES
  35. )
  36. # The ${gem_name} target is a prebuilt module that should contain extern "C" functions to hook into the Gem system
  37. # The list of those functions are available at https://github.com/o3de/o3de/blob/development/Code/Framework/AzCore/AzCore/Module/DynamicModuleHandle.h#L101-L137
  38. ly_add_target(
  39. NAME ${gem_name} IMPORTED ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  40. NAMESPACE Gem
  41. PLATFORM_INCLUDE_FILES
  42. ${pal_dir}/${LY_BUILD_PERMUTATION}/${NameLower}.cmake
  43. COMPILE_DEFINITIONS
  44. INTERFACE
  45. INCLUDE_DIRECTORIES
  46. INTERFACE
  47. BUILD_DEPENDENCIES
  48. INTERFACE
  49. RUNTIME_DEPENDENCIES
  50. TARGET_PROPERTIES
  51. )
  52. # By default, we will specify that the above target ${gem_name} would be used by
  53. # Client and Server type targets when this gem is enabled. If you don't want it
  54. # active in Clients or Servers by default, delete one of both of the following lines:
  55. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  56. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  57. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  58. # For the Client and Server variants of ${gem_name} Gem, an alias to the ${gem_name}.API target will be made
  59. ly_create_alias(NAME ${gem_name}.Clients.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  60. ly_create_alias(NAME ${gem_name}.Servers.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  61. ly_create_alias(NAME ${gem_name}.Unified.API NAMESPACE Gem TARGETS Gem::${gem_name}.API)
  62. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  63. # for the Client, Server and Unified gem variants
  64. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Client Server Unified)
  65. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Tools and ${gem_name}.Builders
  66. if (PAL_TRAIT_BUILD_HOST_TOOLS)
  67. # The ${gem_name}.Tools.API target can be used by other gems that want to interact with the ${gem_name}.Tools module
  68. ly_add_target(
  69. NAME ${gem_name}.Tools.API INTERFACE
  70. NAMESPACE Gem
  71. FILES_CMAKE
  72. ${NameLower}_tools_api_files.cmake
  73. ${pal_dir}/${NameLower}_tools_api_files.cmake
  74. INCLUDE_DIRECTORIES
  75. INTERFACE
  76. Include
  77. BUILD_DEPENDENCIES
  78. INTERFACE
  79. AZ::AzToolsFramework
  80. TARGET_PROPERTIES
  81. )
  82. # The ${gem_name}.Tools target is a prebuilt module that should contain extern "C" functions to hook into the Gem system
  83. # The list of those functions are available at https://github.com/o3de/o3de/blob/development/Code/Framework/AzCore/AzCore/Module/DynamicModuleHandle.h#L101-L137
  84. ly_add_target(
  85. NAME ${gem_name}.Tools IMPORTED GEM_MODULE
  86. NAMESPACE Gem
  87. PLATFORM_INCLUDE_FILES
  88. ${pal_dir}/${LY_BUILD_PERMUTATION}/${NameLower}_tools.cmake
  89. COMPILE_DEFINITIONS
  90. INTERFACE
  91. INCLUDE_DIRECTORIES
  92. INTERFACE
  93. RUNTIME_DEPENDENCIES
  94. TARGET_PROPERTIES
  95. )
  96. # The Builders moudles are loaded by the AssetProcessor, AssetBuilder and AssetBundler
  97. # The ${gem_name}.Builders.API target can be used by other gems that want to interact with the ${gem_name}.Builders module
  98. ly_add_target(
  99. NAME ${gem_name}.Builders.API INTERFACE
  100. NAMESPACE Gem
  101. FILES_CMAKE
  102. ${NameLower}_builders_api_files.cmake
  103. ${pal_dir}/${NameLower}_builders_api_files.cmake
  104. INCLUDE_DIRECTORIES
  105. INTERFACE
  106. Include
  107. BUILD_DEPENDENCIES
  108. INTERFACE
  109. AZ::AzToolsFramework
  110. TARGET_PROPERTIES
  111. )
  112. # The ${gem_name}.Tools target is a prebuilt module that should contain extern "C" functions to hook into the Gem system
  113. # The list of those functions are available at https://github.com/o3de/o3de/blob/development/Code/Framework/AzCore/AzCore/Module/DynamicModuleHandle.h#L101-L137
  114. ly_add_target(
  115. NAME ${gem_name}.Builders IMPORTED GEM_MODULE
  116. NAMESPACE Gem
  117. PLATFORM_INCLUDE_FILES
  118. ${pal_dir}/${LY_BUILD_PERMUTATION}/${NameLower}_builders.cmake
  119. COMPILE_DEFINITIONS
  120. INTERFACE
  121. INCLUDE_DIRECTORIES
  122. INTERFACE
  123. RUNTIME_DEPENDENCIES
  124. TARGET_PROPERTIES
  125. )
  126. # Add in CMake dependencies for each gem dependency listed in this gem's gem.json file
  127. # for the Tools and Builders gem variants
  128. o3de_add_variant_dependencies_for_gem_dependencies(GEM_NAME ${gem_name} VARIANTS Tools Builders)
  129. endif()
  130. ################################################################################
  131. # Tests
  132. ################################################################################
  133. # See if globally, tests are supported
  134. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  135. # Check if test are supported on the current platform
  136. if(PAL_TRAIT_${NameUpper}_TEST_SUPPORTED)
  137. ly_add_target(
  138. NAME ${gem_name}.Tests IMPORTED ${PAL_TRAIT_TEST_TARGET_TYPE}
  139. NAMESPACE Gem
  140. PLATFORM_INCLUDE_FILES
  141. ${pal_dir}/${LY_BUILD_PERMUTATION}/${NameLower}_tests.cmake
  142. COMPILE_DEFINITIONS
  143. INTERFACE
  144. INCLUDE_DIRECTORIES
  145. INTERFACE
  146. TARGET_PROPERTIES
  147. )
  148. ly_add_googletest(
  149. NAME Gem::${gem_name}.Tests
  150. )
  151. endif()
  152. # If we are a host platform we want to add tools test like editor tests here
  153. if (PAL_TRAIT_BUILD_HOST_TOOLS)
  154. if(PAL_TRAIT_${NameUpper}_EDITOR_TEST_SUPPORTED)
  155. # Check if the tools test are supported on the current platform
  156. ly_add_target(
  157. NAME ${gem_name}.Tools.Tests IMPORTED ${PAL_TRAIT_TEST_TARGET_TYPE}
  158. NAMESPACE Gem
  159. PLATFORM_INCLUDE_FILES
  160. ${pal_dir}/${LY_BUILD_PERMUTATION}/${NameLower}_tools_tests.cmake
  161. COMPILE_DEFINITIONS
  162. INTERFACE
  163. INCLUDE_DIRECTORIES
  164. INTERFACE
  165. TARGET_PROPERTIES
  166. )
  167. ly_add_googletest(
  168. NAME Gem::${gem_name}.Tools.Tests
  169. )
  170. endif()
  171. endif()
  172. endif()