CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. if(NOT (ROS_DISTRO STREQUAL "humble" OR ROS_DISTRO STREQUAL "jazzy"))
  46. message(WARNING
  47. "The support for deprecated gazebo_msgs package is not supported in ROS 2 Kilted or newer. "
  48. "Please consider migration to Simulation Interfaces. "
  49. "If you do not intend to use Gazebo messages, please make sure that this package is not sourced in your environment." )
  50. endif()
  51. else()
  52. message(STATUS "Could not find gazebo_msgs package, disabling legacy features like ContactSensor Component and ROS2 Spawner Component")
  53. SET(WITH_GAZEBO_MSGS FALSE)
  54. endif()
  55. # Add the ROS2.Static target
  56. # Note: We include the common files and the platform specific files which are set in ros2_common_files.cmake
  57. # and in ${pal_dir}/ros2_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
  58. ly_add_target(
  59. NAME ${gem_name}.Static STATIC
  60. NAMESPACE Gem
  61. FILES_CMAKE
  62. ros2_header_files.cmake
  63. ros2_files.cmake
  64. INCLUDE_DIRECTORIES
  65. PUBLIC
  66. Include
  67. PRIVATE
  68. Source
  69. Source/VehicleDynamics
  70. BUILD_DEPENDENCIES
  71. PUBLIC
  72. AZ::AzCore
  73. AZ::AzFramework
  74. Gem::Atom_RPI.Public
  75. Gem::Atom_Feature_Common.Public
  76. Gem::Atom_Component_DebugCamera.Static
  77. Gem::Atom_AtomBridge.Static
  78. Gem::StartingPointInput
  79. Gem::PhysX5.Static
  80. Gem::LmbrCentral.API
  81. Gem::LevelGeoreferencing.API
  82. )
  83. 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)
  84. if (WITH_GAZEBO_MSGS)
  85. target_depends_on_ros2_package(${gem_name}.Static gazebo_msgs REQUIRED)
  86. target_compile_definitions(${gem_name}.Static PUBLIC "WITH_GAZEBO_MSGS")
  87. endif()
  88. ly_add_target(
  89. NAME ${gem_name}.API HEADERONLY
  90. NAMESPACE Gem
  91. FILES_CMAKE
  92. ros2_header_files.cmake
  93. INCLUDE_DIRECTORIES
  94. INTERFACE
  95. Include
  96. )
  97. # Here add ROS2 target, it depends on the ROS2.Static
  98. ly_add_target(
  99. NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
  100. NAMESPACE Gem
  101. FILES_CMAKE
  102. ros2_shared_files.cmake
  103. INCLUDE_DIRECTORIES
  104. PUBLIC
  105. Include
  106. PRIVATE
  107. Source
  108. BUILD_DEPENDENCIES
  109. PRIVATE
  110. Gem::${gem_name}.Static
  111. Gem::Atom_Feature_Common.Public
  112. )
  113. # By default, we will specify that the above target ROS2 would be used by
  114. # Client, Server and Unified type targets when this gem is enabled. If you don't want it
  115. # active in Clients, Servers or Unified by default, delete one or more of the following lines:
  116. ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
  117. ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name})
  118. ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name})
  119. # If we are on a host platform, we want to add the host tools targets like the ${gem_name}.Editor target which
  120. # will also depend on ${gem_name}.Static
  121. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  122. ly_add_target(
  123. NAME ${gem_name}.Editor.Static STATIC
  124. NAMESPACE Gem
  125. AUTOMOC
  126. AUTORCC
  127. FILES_CMAKE
  128. ros2_editor_files.cmake
  129. PLATFORM_INCLUDE_FILES
  130. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  131. INCLUDE_DIRECTORIES
  132. PRIVATE
  133. Source
  134. Source/RobotImporter
  135. PUBLIC
  136. Include
  137. COMPILE_DEFINITIONS
  138. PRIVATE
  139. ROS2_EDITOR
  140. BUILD_DEPENDENCIES
  141. PUBLIC
  142. AZ::AzToolsFramework
  143. Gem::CommonFeaturesAtom.Editor.Static
  144. Gem::LmbrCentral.API
  145. Gem::PhysX5.Editor.Static
  146. Gem::${gem_name}.Static
  147. PRIVATE
  148. AZ::AssetBuilderSDK
  149. 3rdParty::sdformat
  150. )
  151. ly_add_target(
  152. NAME ${gem_name}.Editor GEM_MODULE
  153. NAMESPACE Gem
  154. FILES_CMAKE
  155. ros2_editor_shared_files.cmake
  156. PLATFORM_INCLUDE_FILES
  157. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  158. COMPILE_DEFINITIONS
  159. PRIVATE
  160. ROS2_EDITOR
  161. INCLUDE_DIRECTORIES
  162. PRIVATE
  163. Source
  164. PUBLIC
  165. Include
  166. BUILD_DEPENDENCIES
  167. PUBLIC
  168. Gem::${gem_name}.Editor.Static
  169. Gem::Atom_Feature_Common.Public
  170. )
  171. # By default, we will specify that the above target ROS2 would be used by
  172. # Tool and Builder type targets when this gem is enabled. If you don't want it
  173. # active in Tools or Builders by default, delete one or both of the following lines:
  174. ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  175. ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
  176. endif()
  177. ################################################################################
  178. # Tests
  179. ################################################################################
  180. # See if globally, tests are supported
  181. if(PAL_TRAIT_BUILD_TESTS_SUPPORTED)
  182. if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
  183. # We support ROS2.Tests on this platform, add ROS2.Tests target which depends on ROS2.Static
  184. ly_add_target(
  185. NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  186. NAMESPACE Gem
  187. FILES_CMAKE
  188. ros2_tests_files.cmake
  189. INCLUDE_DIRECTORIES
  190. PRIVATE
  191. Tests
  192. Source
  193. BUILD_DEPENDENCIES
  194. PRIVATE
  195. AZ::AzTest
  196. Gem::${gem_name}.Static
  197. )
  198. # Add ROS2.Tests to googletest
  199. ly_add_googletest(
  200. NAME Gem::${gem_name}.Tests
  201. )
  202. # integration test for URDF importer
  203. ly_add_target(
  204. NAME ROS2.Frame.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  205. NAMESPACE Gem
  206. FILES_CMAKE
  207. frame_test_files.cmake
  208. INCLUDE_DIRECTORIES
  209. PRIVATE
  210. Source
  211. Tests
  212. BUILD_DEPENDENCIES
  213. PRIVATE
  214. AZ::AzTestShared
  215. AZ::AzToolsFramework
  216. Legacy::CryCommon
  217. Legacy::EditorCommon
  218. Legacy::Editor.Headers
  219. AZ::AzManipulatorTestFramework.Static
  220. Gem::ROS2.Static
  221. RUNTIME_DEPENDENCIES
  222. Gem::PhysX5.Editor
  223. )
  224. ly_add_googletest(
  225. NAME Gem::ROS2.Frame.Tests
  226. )
  227. endif()
  228. # If we are a host platform we want to add tools test like editor tests here
  229. if(PAL_TRAIT_BUILD_HOST_TOOLS)
  230. if(PAL_TRAIT_TEST_GOOGLE_TEST_SUPPORTED)
  231. # We support ROS2.Editor.Tests on this platform, add ROS2.Editor.Tests target which depends on ROS2.Editor
  232. ly_add_target(
  233. NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
  234. NAMESPACE Gem
  235. FILES_CMAKE
  236. ros2_editor_tests_files.cmake
  237. PLATFORM_INCLUDE_FILES
  238. ${CMAKE_CURRENT_LIST_DIR}/Platform/Common/${PAL_TRAIT_COMPILER_ID}/ros2_static_editor_${PAL_TRAIT_COMPILER_ID_LOWERCASE}.cmake
  239. INCLUDE_DIRECTORIES
  240. PRIVATE
  241. Tests
  242. Source
  243. BUILD_DEPENDENCIES
  244. PRIVATE
  245. AZ::AzTest
  246. AZ::AzTestShared
  247. AZ::AzToolsFramework
  248. Gem::${gem_name}.Editor.Static
  249. 3rdParty::sdformat
  250. )
  251. # Add ROS2.Editor.Tests to googletest
  252. ly_add_googletest(
  253. NAME Gem::${gem_name}.Editor.Tests
  254. )
  255. endif()
  256. endif()
  257. endif()