CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. # Copyright (c) Contributors to the Open 3D Engine Project.
  2. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR MIT
  5. # Only allow this gem to be configured on platforms that are currently supported
  6. include(${CMAKE_CURRENT_SOURCE_DIR}/Platform/${PAL_PLATFORM_NAME}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
  7. if(NOT PAL_TRAIT_BUILD_ROS2_GEM_SUPPORTED)
  8. message(FATAL_ERROR "The ROS2 Gem is not currently supported on ${PAL_PLATFORM_NAME}")
  9. return()
  10. endif()
  11. # If no ROS2 is found, no targets are valid for this Gem
  12. find_package(ROS2 MODULE)
  13. if (NOT ROS2_FOUND)
  14. message(FATAL_ERROR "Unable to detect a the ROS2 distribution on this system. Make sure it is installed and enabled.")
  15. return()
  16. endif()
  17. message(DEBUG "Building ${gem_name} Gem with ros2 $ENV{ROS_DISTRO}")
  18. # Check if ROS 2 distribution is cached
  19. get_property(ROS_DISTRO_TYPE CACHE ROS_DISTRO PROPERTY TYPE)
  20. # Perform checks with cached ROS 2 distribution and sourced distribution. Save the distribution into cache if it was not cached before or if they do not match end with error.
  21. if (NOT ROS_DISTRO_TYPE)
  22. set(ROS_DISTRO $ENV{ROS_DISTRO} CACHE STRING "ROS 2 distribution of current configuration" FORCE)
  23. elseif(NOT "$ENV{ROS_DISTRO}" STREQUAL "${ROS_DISTRO}")
  24. get_cmake_property(CACHED_VARIABLES CACHE_VARIABLES)
  25. set(ROS_DISTRO_COPY ${ROS_DISTRO})
  26. # Iterate over cached variables and unset them
  27. foreach(CACHED_VARIABLE ${CACHED_VARIABLES})
  28. unset(${CACHED_VARIABLE} CACHE)
  29. endforeach()
  30. message(FATAL_ERROR "ROS 2 distribution does not match. Configuration created for: ${ROS_DISTRO_COPY}, sourced distribution: $ENV{ROS_DISTRO}. Removed invalid configuration, please reconfigure project.")
  31. endif()
  32. # Add a custom target to always check during build if sourced and cached distributions match.
  33. add_custom_target(
  34. ROS2DistributionCheck ALL
  35. COMMENT "Checking if sourced ROS 2 distribution matches with the configuration"
  36. COMMAND ${CMAKE_COMMAND} -DROS_DISTRO=${ROS_DISTRO} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkROS2Distribution.cmake
  37. )
  38. # Gazebo messages are optional, so we will only add the dependents if the package is found.
  39. # The gazebo_msgs package is EOL and will not be available in ROS 2 Kilted Kaiju.
  40. # If you need to use ContactSensor and/or ROS2 Spawner, please consider building gazebo_msgs from the source.
  41. find_package(gazebo_msgs QUIET)
  42. if (gazebo_msgs_FOUND)
  43. message(STATUS "Found gazebo_msgs package, enabling legacy features like ContactSensor Component and ROS2 Spawner Component")
  44. SET (WITH_GAZEBO_MSGS TRUE)
  45. else()
  46. message(STATUS "Could not find gazebo_msgs package, disabling legacy features like ContactSensor Component and ROS2 Spawner Component")
  47. SET(WITH_GAZEBO_MSGS FALSE)
  48. endif()
  49. # Add the ROS2.Static target
  50. # Note: We include the common files and the platform specific files which are set in ros2_common_files.cmake
  51. # and in ${pal_dir}/ros2_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  52. ly_add_target(
  53. NAME ${gem_name}.Static STATIC
  54. NAMESPACE Gem
  55. FILES_CMAKE
  56. ros2_header_files.cmake
  57. ros2_files.cmake
  58. INCLUDE_DIRECTORIES
  59. PUBLIC
  60. Include
  61. PRIVATE
  62. Source
  63. Source/VehicleDynamics
  64. BUILD_DEPENDENCIES
  65. PUBLIC
  66. AZ::AzCore
  67. AZ::AzFramework
  68. Gem::Atom_RPI.Public
  69. Gem::Atom_Feature_Common.Public
  70. Gem::Atom_Component_DebugCamera.Static
  71. Gem::Atom_AtomBridge.Static
  72. Gem::StartingPointInput
  73. Gem::PhysX5.Static
  74. Gem::LmbrCentral.API
  75. Gem::LevelGeoreferencing.API
  76. )
  77. target_depends_on_ros2_packages(${gem_name}.Static rclcpp builtin_interfaces std_msgs sensor_msgs nav_msgs tf2_ros ackermann_msgs vision_msgs control_msgs)
  78. if (WITH_GAZEBO_MSGS)
  79. target_depends_on_ros2_package(${gem_name}.Static gazebo_msgs REQUIRED)
  80. target_compile_definitions(${gem_name}.Static PUBLIC "WITH_GAZEBO_MSGS")
  81. endif()
  82. ly_add_target(
  83. NAME ${gem_name}.API HEADERONLY
  84. NAMESPACE Gem
  85. FILES_CMAKE
  86. ros2_header_files.cmake
  87. INCLUDE_DIRECTORIES
  88. INTERFACE
  89. Include
  90. )
  91. # Here add ROS2 target, it depends on the ROS2.Static
  92. ly_add_target(
  93. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  94. NAMESPACE Gem
  95. FILES_CMAKE
  96. ros2_shared_files.cmake
  97. INCLUDE_DIRECTORIES
  98. PUBLIC
  99. Include
  100. PRIVATE
  101. Source
  102. BUILD_DEPENDENCIES
  103. PRIVATE
  104. Gem::${gem_name}.Static
  105. Gem::Atom_Feature_Common.Public
  106. )
  107. # By default, we will specify that the above target ROS2 would be used by
  108. # Client, Server and Unified type targets when this gem is enabled. If you don't want it
  109. # active in Clients, Servers or Unified by default, delete one or more of the following lines:
  110. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  111. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  112. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  113. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor target which
  114. # will also depend on ${gem_name}.Static
  115. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  116. ly_add_target(
  117. NAME ${gem_name}.Editor.Static STATIC
  118. NAMESPACE Gem
  119. AUTOMOC
  120. AUTORCC
  121. FILES_CMAKE
  122. ros2_editor_files.cmake
  123. PLATFORM_INCLUDE_FILES
  124. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  125. INCLUDE_DIRECTORIES
  126. PRIVATE
  127. Source
  128. Source/RobotImporter
  129. PUBLIC
  130. Include
  131. COMPILE_DEFINITIONS
  132. PRIVATE
  133. ROS2_EDITOR
  134. BUILD_DEPENDENCIES
  135. PUBLIC
  136. AZ::AzToolsFramework
  137. Gem::CommonFeaturesAtom.Editor.Static
  138. Gem::LmbrCentral.API
  139. Gem::PhysX5.Editor.Static
  140. Gem::${gem_name}.Static
  141. PRIVATE
  142. AZ::AssetBuilderSDK
  143. 3rdParty::sdformat
  144. )
  145. ly_add_target(
  146. NAME ${gem_name}.Editor GEM_MODULE
  147. NAMESPACE Gem
  148. FILES_CMAKE
  149. ros2_editor_shared_files.cmake
  150. PLATFORM_INCLUDE_FILES
  151. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  152. COMPILE_DEFINITIONS
  153. PRIVATE
  154. ROS2_EDITOR
  155. INCLUDE_DIRECTORIES
  156. PRIVATE
  157. Source
  158. PUBLIC
  159. Include
  160. BUILD_DEPENDENCIES
  161. PUBLIC
  162. Gem::${gem_name}.Editor.Static
  163. Gem::Atom_Feature_Common.Public
  164. )
  165. # By default, we will specify that the above target ROS2 would be used by
  166. # Tool and Builder type targets when this gem is enabled. If you don't want it
  167. # active in Tools or Builders by default, delete one or both of the following lines:
  168. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  169. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  170. endif()
  171. ################################################################################
  172. # Tests
  173. ################################################################################
  174. # See if globally, tests are supported
  175. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  176. if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
  177. # We support ROS2.Tests on this platform, add ROS2.Tests target which depends on ROS2.Static
  178. ly_add_target(
  179. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  180. NAMESPACE Gem
  181. FILES_CMAKE
  182. ros2_tests_files.cmake
  183. INCLUDE_DIRECTORIES
  184. PRIVATE
  185. Tests
  186. Source
  187. BUILD_DEPENDENCIES
  188. PRIVATE
  189. AZ::AzTest
  190. Gem::${gem_name}.Static
  191. )
  192. # Add ROS2.Tests to googletest
  193. ly_add_googletest(
  194. NAME Gem::${gem_name}.Tests
  195. )
  196. # integration test for URDF importer
  197. ly_add_target(
  198. NAME ROS2.Frame.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  199. NAMESPACE Gem
  200. FILES_CMAKE
  201. frame_test_files.cmake
  202. INCLUDE_DIRECTORIES
  203. PRIVATE
  204. Source
  205. Tests
  206. BUILD_DEPENDENCIES
  207. PRIVATE
  208. AZ::AzTestShared
  209. AZ::AzToolsFramework
  210. Legacy::CryCommon
  211. Legacy::EditorCommon
  212. Legacy::Editor.Headers
  213. AZ::AzManipulatorTestFramework.Static
  214. Gem::ROS2.Static
  215. RUNTIME_DEPENDENCIES
  216. Gem::PhysX5.Editor
  217. )
  218. ly_add_googletest(
  219. NAME Gem::ROS2.Frame.Tests
  220. )
  221. endif()
  222. # If we are a host platform we want to add tools test like editor tests here
  223. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  224. if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
  225. # We support ROS2.Editor.Tests on this platform, add ROS2.Editor.Tests target which depends on ROS2.Editor
  226. ly_add_target(
  227. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  228. NAMESPACE Gem
  229. FILES_CMAKE
  230. ros2_editor_tests_files.cmake
  231. PLATFORM_INCLUDE_FILES
  232. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  233. INCLUDE_DIRECTORIES
  234. PRIVATE
  235. Tests
  236. Source
  237. BUILD_DEPENDENCIES
  238. PRIVATE
  239. AZ::AzTest
  240. AZ::AzTestShared
  241. AZ::AzToolsFramework
  242. Gem::${gem_name}.Editor.Static
  243. 3rdParty::sdformat
  244. )
  245. # Add ROS2.Editor.Tests to googletest
  246. ly_add_googletest(
  247. NAME Gem::${gem_name}.Editor.Tests
  248. )
  249. endif()
  250. endif()
  251. endif()