CMakeLists.txt 11 KB

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