Ver Fonte

Added CMAKE logic to disable Contact Sensor and Spawner components. (#842)

Components will be disabled when gazebo_msgs is no longer available.
Apply suggestions from code review
---------
Signed-off-by: Michał Pełka <[email protected]>
Co-authored-by: Jan Hanca <[email protected]>
Signed-off-by: Jan Hanca <[email protected]>
Michał Pełka há 4 meses atrás
pai
commit
69638854c8
25 ficheiros alterados com 197 adições e 42 exclusões
  1. 18 1
      Gems/ROS2/Code/CMakeLists.txt
  2. 1 1
      Gems/ROS2/Code/Source/Clients/ROS2SystemComponent.cpp
  3. 72 0
      Gems/ROS2/Code/Source/ROS2EditorModule.cpp
  4. 6 2
      Gems/ROS2/Code/Source/ROS2ModuleInterface.cpp
  5. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponent.cpp
  6. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponent.h
  7. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponentController.cpp
  8. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponentController.h
  9. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointEditorComponent.cpp
  10. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointEditorComponent.h
  11. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponent.cpp
  12. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponent.h
  13. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponentController.cpp
  14. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponentController.h
  15. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerEditorComponent.cpp
  16. 3 1
      Gems/ROS2/Code/Source/Spawner/ROS2SpawnerEditorComponent.h
  17. 4 0
      Gems/ROS2/Code/Source/Tools/ROS2EditorModule.cpp
  18. 10 4
      Gems/ROS2/Code/ros2_editor_private_files.cmake
  19. 14 8
      Gems/ROS2/Code/ros2_private_files.cmake
  20. 9 5
      Gems/ROS2/Code/ros2_target_depends.cmake
  21. 5 5
      Gems/ROS2/gem.json
  22. 8 1
      Gems/ROS2Sensors/Code/CMakeLists.txt
  23. 3 1
      Gems/ROS2Sensors/Code/Source/ContactSensor/ROS2ContactSensorComponent.cpp
  24. 3 0
      Gems/ROS2Sensors/Code/Source/ContactSensor/ROS2ContactSensorComponent.h
  25. 8 2
      Gems/ROS2Sensors/Code/ros2sensors_private_files.cmake

+ 18 - 1
Gems/ROS2/Code/CMakeLists.txt

@@ -53,6 +53,18 @@ add_custom_target(
     COMMAND ${CMAKE_COMMAND} -DROS_DISTRO=${ROS_DISTRO} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkROS2Distribution.cmake
 )
 
+# Gazebo messages are optional, so we will only add the dependents if the package is found.
+# The gazebo_msgs package is EOL and will not be available in ROS 2 Kilted Kaiju.
+# If you need to use ContactSensor and/or ROS2 Spawner, please consider building gazebo_msgs from the source.
+find_package(gazebo_msgs QUIET)
+if (gazebo_msgs_FOUND)
+    message(STATUS "Found gazebo_msgs package, enabling legacy features like ContactSensor Component and ROS2 Spawner Component")
+    SET (WITH_GAZEBO_MSGS TRUE)
+else()
+    message(STATUS "Could not find gazebo_msgs package, disabling legacy features like ContactSensor Component and ROS2 Spawner Component")
+    SET(WITH_GAZEBO_MSGS FALSE)
+endif()
+
 # Add the static target with the API Interface and the code
 # TODO: This target should be removed after API is fully implemented with buses
 ly_add_target(
@@ -130,7 +142,12 @@ ly_add_target(
             Gem::LevelGeoreferencing.API # ROS2SpawnerComponent
 )
 
-target_depends_on_ros2_packages(${gem_name}.Private.Object rclcpp builtin_interfaces std_msgs sensor_msgs nav_msgs tf2_ros ackermann_msgs gazebo_msgs vision_msgs control_msgs)
+target_depends_on_ros2_packages(${gem_name}.Private.Object rclcpp builtin_interfaces std_msgs sensor_msgs nav_msgs tf2_ros ackermann_msgs vision_msgs control_msgs)
+
+if (WITH_GAZEBO_MSGS)
+    target_depends_on_ros2_package(${gem_name}.Private.Object gazebo_msgs REQUIRED)
+    target_compile_definitions(${gem_name}.Private.Object PUBLIC "WITH_GAZEBO_MSGS")
+endif()
 
 # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
 ly_add_target(

+ 1 - 1
Gems/ROS2/Code/Source/Clients/ROS2SystemComponent.cpp

@@ -72,7 +72,7 @@ namespace ROS2
         incompatible.push_back(AZ_CRC_CE("ROS2Service"));
     }
 
-    void ROS2SystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
+    void ROS2SystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
     {
         required.push_back(AZ_CRC("AssetDatabaseService", 0x3abf5601));
     }

+ 72 - 0
Gems/ROS2/Code/Source/ROS2EditorModule.cpp

@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#include <AzCore/RTTI/RTTIMacros.h>
+#include <Camera/ROS2CameraSensorEditorComponent.h>
+#include <Camera/ROS2EditorCameraSystemComponent.h>
+#include <Frame/ROS2FrameSystemComponent.h>
+#include <Lidar/LidarRegistrarEditorSystemComponent.h>
+#include <Manipulation/JointsManipulationEditorComponent.h>
+#include <Manipulation/JointsPositionsEditorComponent.h>
+#include <QtCore/qglobal.h>
+#include <ROS2/Frame/ROS2FrameEditorComponent.h>
+#include <ROS2ModuleInterface.h>
+#include <RobotImporter/ROS2RobotImporterEditorSystemComponent.h>
+#include <SdfAssetBuilder/SdfAssetBuilderSystemComponent.h>
+#include <SystemComponents/ROS2EditorSystemComponent.h>
+#ifdef WITH_GAZEBO_MSGS
+#include <Spawner/ROS2SpawnPointEditorComponent.h>
+#include <Spawner/ROS2SpawnerEditorComponent.h>
+#endif
+void InitROS2Resources()
+{
+    // Registration of Qt (ROS2.qrc) resources
+    Q_INIT_RESOURCE(ROS2);
+}
+
+namespace ROS2
+{
+    class ROS2EditorModule : public ROS2ModuleInterface
+    {
+    public:
+        AZ_RTTI(ROS2EditorModule, "{3DDFC98F-D1CC-4658-BAF8-2CC34A9D39F3}", ROS2ModuleInterface);
+        AZ_CLASS_ALLOCATOR(ROS2EditorModule, AZ::SystemAllocator);
+
+        ROS2EditorModule()
+        {
+            InitROS2Resources();
+
+            m_descriptors.insert(
+                m_descriptors.end(),
+                { ROS2EditorSystemComponent::CreateDescriptor(),
+                  ROS2EditorCameraSystemComponent::CreateDescriptor(),
+                  LidarRegistrarEditorSystemComponent::CreateDescriptor(),
+                  ROS2RobotImporterEditorSystemComponent::CreateDescriptor(),
+                  ROS2CameraSensorEditorComponent::CreateDescriptor(),
+#ifdef WITH_GAZEBO_MSGS
+                  ROS2SpawnerEditorComponent::CreateDescriptor(),
+                  ROS2SpawnPointEditorComponent::CreateDescriptor(),
+#endif
+                  SdfAssetBuilderSystemComponent::CreateDescriptor(),
+                  JointsManipulationEditorComponent::CreateDescriptor(),
+                  JointsPositionsEditorComponent::CreateDescriptor(),
+                  ROS2FrameSystemComponent::CreateDescriptor(),
+                  ROS2FrameEditorComponent::CreateDescriptor() });
+        }
+
+        AZ::ComponentTypeList GetRequiredSystemComponents() const override
+        {
+            return AZ::ComponentTypeList{
+                azrtti_typeid<ROS2EditorSystemComponent>(),           azrtti_typeid<ROS2EditorCameraSystemComponent>(),
+                azrtti_typeid<LidarRegistrarEditorSystemComponent>(), azrtti_typeid<ROS2RobotImporterEditorSystemComponent>(),
+                azrtti_typeid<SdfAssetBuilderSystemComponent>(),      azrtti_typeid<ROS2FrameSystemComponent>(),
+            };
+        }
+    };
+} // namespace ROS2
+
+AZ_DECLARE_MODULE_CLASS(Gem_ROS2, ROS2::ROS2EditorModule)

+ 6 - 2
Gems/ROS2/Code/Source/ROS2ModuleInterface.cpp

@@ -16,8 +16,10 @@
 #include <ROS2/Sensor/Events/TickBasedSource.h>
 #include <ROS2/Sensor/ROS2SensorComponentBase.h>
 #include <SimulationUtils/FollowingCameraComponent.h>
+#ifdef WITH_GAZEBO_MSGS
 #include <Spawner/ROS2SpawnPointComponent.h>
 #include <Spawner/ROS2SpawnerComponent.h>
+#endif
 
 namespace ROS2
 {
@@ -32,11 +34,13 @@ namespace ROS2
             {
                 ROS2SystemComponent::CreateDescriptor(),
                 ROS2FrameComponent::CreateDescriptor(),
-                ROS2SpawnerComponent::CreateDescriptor(),
-                ROS2SpawnPointComponent::CreateDescriptor(),
                 FollowingCameraComponent::CreateDescriptor(),
                 ROS2SensorComponentBase<TickBasedSource>::CreateDescriptor(),
                 ROS2SensorComponentBase<PhysicsBasedSource>::CreateDescriptor(),
+#ifdef WITH_GAZEBO_MSGS
+                ROS2SpawnerComponent::CreateDescriptor(),
+                ROS2SpawnPointComponent::CreateDescriptor(),
+#endif
             });
     }
 

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponent.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnPointComponent.h"
 #include "Spawner/ROS2SpawnPointComponentController.h"
 #include <AzCore/Component/Entity.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponent.h

@@ -6,7 +6,9 @@
  *
  */
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "Spawner/ROS2SpawnPointComponentController.h"
 #include <AzCore/Component/Component.h>
 #include <AzCore/Math/Transform.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponentController.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "Spawner/ROS2SpawnPointComponentController.h"
 #include "Spawner/ROS2SpawnerComponentController.h"
 #include <AzCore/Component/TransformBus.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointComponentController.h

@@ -6,7 +6,9 @@
  *
  */
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include <AzCore/Component/Component.h>
 #include <AzCore/Component/ComponentBus.h>
 #include <AzCore/Math/Transform.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointEditorComponent.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnPointEditorComponent.h"
 #include "Spawner/ROS2SpawnPointComponentController.h"
 #include "Spawner/ROS2SpawnerEditorComponent.h"

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnPointEditorComponent.h

@@ -6,7 +6,9 @@
  *
  */
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "Spawner/ROS2SpawnPointComponent.h"
 #include "Spawner/ROS2SpawnPointComponentController.h"
 #include "Spawner/ROS2SpawnerEditorComponent.h"

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponent.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnerComponent.h"
 #include "Spawner/ROS2SpawnerComponentController.h"
 #include <AzCore/Component/EntityId.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponent.h

@@ -6,7 +6,9 @@
  *
  */
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnPointComponent.h"
 #include "Spawner/ROS2SpawnerComponentController.h"
 #include <AzCore/Asset/AssetCommon.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponentController.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnerComponentController.h"
 #include "Spawner/ROS2SpawnPointComponent.h"
 #include "Spawner/ROS2SpawnerComponent.h"

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerComponentController.h

@@ -7,7 +7,9 @@
  */
 
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2/Spawner/SpawnerBus.h"
 #include "ROS2SpawnPointComponent.h"
 #include <AzCore/Component/ComponentBus.h>

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerEditorComponent.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2SpawnerEditorComponent.h"
 #include "AzCore/Debug/Trace.h"
 #include "ROS2SpawnPointEditorComponent.h"

+ 3 - 1
Gems/ROS2/Code/Source/Spawner/ROS2SpawnerEditorComponent.h

@@ -6,7 +6,9 @@
  *
  */
 #pragma once
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "Spawner/ROS2SpawnerComponent.h"
 #include "Spawner/ROS2SpawnerComponentController.h"
 #include <AzToolsFramework/ToolsComponents/EditorComponentAdapter.h>

+ 4 - 0
Gems/ROS2/Code/Source/Tools/ROS2EditorModule.cpp

@@ -11,8 +11,10 @@
 #include <ROS2/Frame/ROS2FrameEditorComponent.h>
 #include <ROS2/ROS2TypeIds.h>
 #include <ROS2ModuleInterface.h>
+#ifdef WITH_GAZEBO_MSGS
 #include <Spawner/ROS2SpawnPointEditorComponent.h>
 #include <Spawner/ROS2SpawnerEditorComponent.h>
+#endif
 
 namespace ROS2
 {
@@ -27,8 +29,10 @@ namespace ROS2
             m_descriptors.insert(
                 m_descriptors.end(),
                 { ROS2EditorSystemComponent::CreateDescriptor(),
+#ifdef WITH_GAZEBO_MSGS
                   ROS2SpawnerEditorComponent::CreateDescriptor(),
                   ROS2SpawnPointEditorComponent::CreateDescriptor(),
+#endif
                   ROS2FrameSystemComponent::CreateDescriptor(),
                   ROS2FrameEditorComponent::CreateDescriptor() });
         }

+ 10 - 4
Gems/ROS2/Code/ros2_editor_private_files.cmake

@@ -7,10 +7,16 @@ set(FILES
     Source/Frame/ROS2FrameSystemComponent.cpp
     Source/Frame/ROS2FrameSystemComponent.h
     Source/Frame/ROS2FrameSystemBus.h
-    Source/Spawner/ROS2SpawnerEditorComponent.cpp
-    Source/Spawner/ROS2SpawnerEditorComponent.h
-    Source/Spawner/ROS2SpawnPointEditorComponent.cpp
-    Source/Spawner/ROS2SpawnPointEditorComponent.h
     Source/Tools/ROS2EditorSystemComponent.cpp
     Source/Tools/ROS2EditorSystemComponent.h
 )
+
+# optional, legacy features compilation
+if (WITH_GAZEBO_MSGS)
+    list(APPEND FILES
+        Source/Spawner/ROS2SpawnerEditorComponent.cpp
+        Source/Spawner/ROS2SpawnerEditorComponent.h
+        Source/Spawner/ROS2SpawnPointEditorComponent.cpp
+        Source/Spawner/ROS2SpawnPointEditorComponent.h
+    )
+endif ()

+ 14 - 8
Gems/ROS2/Code/ros2_private_files.cmake

@@ -13,12 +13,18 @@ set(FILES
     Source/SimulationUtils/FollowingCameraConfiguration.h
     Source/SimulationUtils/FollowingCameraComponent.cpp
     Source/SimulationUtils/FollowingCameraComponent.h
-    Source/Spawner/ROS2SpawnerComponent.cpp
-    Source/Spawner/ROS2SpawnerComponent.h
-    Source/Spawner/ROS2SpawnPointComponent.cpp
-    Source/Spawner/ROS2SpawnPointComponent.h
-    Source/Spawner/ROS2SpawnerComponentController.cpp
-    Source/Spawner/ROS2SpawnerComponentController.h
-    Source/Spawner/ROS2SpawnPointComponentController.cpp
-    Source/Spawner/ROS2SpawnPointComponentController.h
 )
+
+# optional, legacy features compilation
+if (WITH_GAZEBO_MSGS)
+        list(APPEND FILES
+                Source/Spawner/ROS2SpawnerComponent.cpp
+                Source/Spawner/ROS2SpawnerComponent.h
+                Source/Spawner/ROS2SpawnPointComponent.cpp
+                Source/Spawner/ROS2SpawnPointComponent.h
+                Source/Spawner/ROS2SpawnerComponentController.cpp
+                Source/Spawner/ROS2SpawnerComponentController.h
+                Source/Spawner/ROS2SpawnPointComponentController.cpp
+                Source/Spawner/ROS2SpawnPointComponentController.h
+        )
+endif ()

+ 9 - 5
Gems/ROS2/Code/ros2_target_depends.cmake

@@ -6,12 +6,16 @@
 function(target_depends_on_ros2_package TARGET_NAME)
     list(GET ARGN 0 _package)
     find_package(${ARGN})
-    include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
-    if (${${_package}_FOUND_AMENT_PACKAGE})
-        message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
-        target_link_libraries(${TARGET_NAME} PUBLIC ${${_package}_TARGETS})
+    if (${${_package}_FOUND})
+        include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
+        if (${${_package}_FOUND_AMENT_PACKAGE})
+            message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
+            target_link_libraries(${TARGET_NAME} PUBLIC ${${_package}_TARGETS})
+        else ()
+            message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
+        endif ()
     else ()
-        message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
+        message(DEBUG "Package ${_package} was not found.")
     endif ()
 endfunction()
 

+ 5 - 5
Gems/ROS2/gem.json

@@ -15,11 +15,6 @@
     "user_tags": [
         "ROS2"
     ],
-    "compatible_engines": [
-        "o3de-sdk>=2.4.0",
-        "o3de>=2.4.0"
-    ],
-    "engine_api_dependencies": [],
     "platforms": [
         "Linux"
     ],
@@ -29,6 +24,11 @@
     "dependencies": [
         "LevelGeoreferencing"
     ],
+    "compatible_engines": [
+        "o3de-sdk>=2.4.0",
+        "o3de>=2.4.0"
+    ],
+    "engine_api_dependencies": [],
     "restricted": "ROS2",
     "repo_uri": "https://github.com/o3de/o3de-extras",
     "download_source_uri": "https://github.com/o3de/o3de-extras/releases/download/2.0/ros2-4.0.0-gem.zip"

+ 8 - 1
Gems/ROS2Sensors/Code/CMakeLists.txt

@@ -85,7 +85,14 @@ ly_add_target(
             ${gem_name}.Lidar.Static
 )
 
-target_depends_on_ros2_packages(${gem_name}.Private.Object rclcpp sensor_msgs nav_msgs)
+target_depends_on_ros2_packages(${gem_name}.Private.Object rclcpp sensor_msgs nav_msgs vision_msgs)
+
+# WITH_GAZEBO_MSGS is set in ROS 2 Gem, which is a dependency of this gem.
+# If WITH_GAZEBO_MSGS is set, legacy sensors will be compiled in.
+if (WITH_GAZEBO_MSGS)
+    target_depends_on_ros2_package(${gem_name}.Private.Object gazebo_msgs REQUIRED)
+    target_compile_definitions(${gem_name}.Private.Object PUBLIC "WITH_GAZEBO_MSGS")
+endif()
 
 # Here add ${gem_name} target, it depends on the Private Object library and Public API interface
 ly_add_target(

+ 3 - 1
Gems/ROS2Sensors/Code/Source/ContactSensor/ROS2ContactSensorComponent.cpp

@@ -5,7 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  */
-
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 #include "ROS2ContactSensorComponent.h"
 #include <AzFramework/Physics/Collision/CollisionEvents.h>
 #include <AzFramework/Physics/Common/PhysicsSimulatedBody.h>

+ 3 - 0
Gems/ROS2Sensors/Code/Source/ContactSensor/ROS2ContactSensorComponent.h

@@ -7,6 +7,9 @@
  */
 
 #pragma once
+#ifndef WITH_GAZEBO_MSGS
+static_assert(false, "This file should not be included in the build, without WITH_GAZEBO_MSGS defined.");
+#endif
 
 #include <AzCore/Component/EntityId.h>
 #include <AzCore/RTTI/ReflectContext.h>

+ 8 - 2
Gems/ROS2Sensors/Code/ros2sensors_private_files.cmake

@@ -26,8 +26,6 @@ set(FILES
     Source/Camera/ROS2CameraSensorComponent.h
     Source/Camera/ROS2CameraSystemComponent.cpp
     Source/Camera/ROS2CameraSystemComponent.h
-    Source/ContactSensor/ROS2ContactSensorComponent.cpp
-    Source/ContactSensor/ROS2ContactSensorComponent.h
     Source/GNSS/ROS2GNSSSensorComponent.cpp
     Source/GNSS/ROS2GNSSSensorComponent.h
     Source/Imu/ImuSensorConfiguration.cpp
@@ -53,3 +51,11 @@ set(FILES
     Source/Odometry/ROS2OdometrySensorComponent.cpp
     Source/Odometry/ROS2OdometrySensorComponent.h
 )
+
+# optional, legacy features compilation
+if (WITH_GAZEBO_MSGS)
+        list(APPEND FILES
+                Source/ContactSensor/ROS2ContactSensorComponent.cpp
+                Source/ContactSensor/ROS2ContactSensorComponent.h
+        )
+endif ()