CMakeLists.txt 12 KB

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