eProsima / Fast-DDS-Gen

Fast-DDS IDL code generator tool. Looking for commercial support? Contact info@eprosima.com
Apache License 2.0
80 stars 59 forks source link

Include error with CMake example - <fastcdr/cdr/fixed_size_string.hpp> #312

Open Ryanf55 opened 7 months ago

Ryanf55 commented 7 months ago

Bug Report

$ fastddsgen -version
openjdk version "11.0.21" 2023-10-17
OpenJDK Runtime Environment (build 11.0.21+9-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.21+9-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)
fastddsgen version 3.2.1

OS: Ubuntu 22 Installation Type: apt, with vulcanexus-humble-fastddsgen. I want to use fastddsgen on the IDL file generated by a standard ROS humble installation.

Steps to reproduce

  1. Create BasicTypes.idl
    
    // generated from rosidl_adapter/resource/msg.idl.em
    // with input from rosidl_generator_tests/msg/BasicTypes.msg
    // generated code does not contain a copyright notice

module rosidl_generator_tests { module msg { struct BasicTypes { boolean bool_value;

  octet byte_value;

  uint8 char_value;

  float float32_value;

  double float64_value;

  int8 int8_value;

  uint8 uint8_value;

  int16 int16_value;

  uint16 uint16_value;

  int32 int32_value;

  uint32 uint32_value;

  int64 int64_value;

  uint64 uint64_value;
};

}; };


2. Run generator

fastddsgen -typeros2 BasicTypes.idl -example CMake


3. Observe the generated CMakeLists:
```cmake
cmake_minimum_required(VERSION 3.20)

project("generated_code")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)

# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastrtps 2.12 REQUIRED)

message(STATUS "Configuring BasicTypes...")
add_library(BasicTypes_lib BasicTypes.cxx)
target_link_libraries(BasicTypes_lib fastcdr fastrtps)

add_executable(BasicTypes BasicTypesPubSubTypes.cxx BasicTypesPublisher.cxx BasicTypesSubscriber.cxx BasicTypesPubSubMain.cxx)
target_link_libraries(BasicTypes fastcdr fastrtps
        BasicTypes_lib )
  1. Try building, observe failues
    cmake -S . -B build
    cmake --build build

Logs

-- Configuring BasicTypes...
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/ryan/Dev/ros2_ws/src/rosidl/build/rosidl_generator_tests/rosidl_adapter/rosidl_generator_tests/msg/build
[ 14%] Building CXX object CMakeFiles/BasicTypes_lib.dir/BasicTypes.cxx.o
In file included from /home/ryan/Dev/ros2_ws/src/rosidl/build/rosidl_generator_tests/rosidl_adapter/rosidl_generator_tests/msg/BasicTypes.cxx:29:
/home/ryan/Dev/ros2_ws/src/rosidl/build/rosidl_generator_tests/rosidl_adapter/rosidl_generator_tests/msg/BasicTypes.h:32:10: fatal error: fastcdr/cdr/fixed_size_string.hpp: No such file or directory
   32 | #include <fastcdr/cdr/fixed_size_string.hpp>

Root cause

It might be finding the wrong version of fastcdr. It locates this one:

/opt/ros/rolling/lib/cmake/fastcdr/fastcdr-config.cmake

On my system, there's a ton of fastcdr config files:

/opt/ros/humble/lib/cmake/fastcdr/fastcdr-config.cmake
/opt/ros/iron/lib/cmake/fastcdr/fastcdr-config.cmake
/opt/ros/rolling/lib/cmake/fastcdr/fastcdr-config.cmake
/home/ryan/Dev/ros2_rolling/build/fastcdr/cmake/config/fastcdr-config.cmake
/home/ryan/Dev/ros2_rolling/install/fastcdr/lib/cmake/fastcdr/fastcdr-config.cmake
/home/ryan/Dev/ros2_rolling/src/eProsima/Fast-CDR/cmake/packaging/windows/fastcdr-config.cmake

If I manually set my ROS_DISTRO to humble, which adjusts the CMake prefix path, then I get this error:

  The file was found at

    /opt/ros/humble/lib/cmake/fastcdr/fastcdr-config.cmake

CMake Error at CMakeLists.txt:13 (find_package):
  Could not find a configuration file for package "fastrtps" that is
  compatible with requested version "2.12".

  The following configuration files were considered but not accepted:

    /opt/ros/humble/share/fastrtps/cmake/fastrtps-config.cmake, version: 2.6.7
EduPonz commented 7 months ago

Hi @Ryanf55,

This is because Fast DDS Gen v3 generates code using Fast CDR v2 API by default, but Vulcanexus is still distributing Fast CDR v1 (as ROS 2 does). Try this command:

fastddsgen -typeros2 -cdr both BasicTypes.idl -example CMake  # -cdr v1 would also work

In case you're interested, we are in the process of upgrading Fast CDR to v2 for Jazzy in:

Ryanf55 commented 7 months ago

Thanks. Do you think if there was a version argument to find_package, this could be prevented at configure time rather than build time?

EduPonz commented 7 months ago

Thanks. Do you think if there was a version argument to find_package, this could be prevented at configure time rather than build time?

That's actually a very good point, we could do something like:

-cdr v1 -> find_package Fast CDR v1 -cdr v2 -> find_package Fast CDR v2 -cdr both -> find_package minimum Fast CDR v1