CMakeLists.txt 11 KB

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