CMakeLists.txt 11 KB

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