OpenDDS / OpenDDS

OpenDDS is an open source C++ implementation of the Object Management Group (OMG) Data Distribution Service (DDS). OpenDDS also supports Java bindings through JNI.
http://www.opendds.org
Other
1.32k stars 472 forks source link

Using the C++11 Mapping with CMake #1714

Closed SalvoVirga closed 4 years ago

SalvoVirga commented 4 years ago

I am trying to generate messages with C++11 mapping over CMake and I have the following tiny example:

demo.idl

module Demo {
  @topic
  struct DemoMessage {
    string demo_string;
  };
};

CMakeLists.txt

find_package(OpenDDS 3.14 REQUIRED)
add_library(MyLib)
OPENDDS_TARGET_SOURCES(MyLib demo.idl OPENDDS_IDL_OPTIONS -Lc++11)

But when running cmake and make I get the following error:

[ 60%] Generating demoC.h, demoC.inl, demoS.h, demoC.cpp
processing /home/<PATH>/demo.idl
[ 66%] Generating demoTypeSupportImpl.h, demoTypeSupportImpl.cpp, demoTypeSupport.idl
processing /home/<PATH>/demo.idl
[ 73%] Generating demoTypeSupportC.h, demoTypeSupportC.inl, demoTypeSupportS.h, demoTypeSupportC.cpp
processing /home/<PATH>/demoTypeSupport.idl
Scanning dependencies of target MyLib
[ 80%] Building CXX object <PATH>/CMakeFiles/MyLib.dir/demoTypeSupportImpl.cpp.o
[ 86%] Building CXX object <PATH>/CMakeFiles/MyLib.dir/demoC.cpp.o
demoC.cpp: In function ‘CORBA::Boolean operator«(TAO_OutputCDR&, const Demo::DemoMessage&)’:
demoC.cpp:46:29: error: invalid use of member function ‘std::__cxx11::string& Demo::DemoMessage::demo_string()’ (did you forget the ‘()’ ?)
     (strm « _tao_aggregate.demo_string.in ());
              ~~~~~~~~~~~~~~~^~~~~~~~~~~
demoC.cpp:46:41: error: expected ‘)’ before ‘in’
     (strm « _tao_aggregate.demo_string.in ());
                                         ^~
demoC.cpp: In function ‘CORBA::Boolean operator»(TAO_InputCDR&, Demo::DemoMessage&)’:
demoC.cpp:54:29: error: invalid use of member function ‘std::__cxx11::string& Demo::DemoMessage::demo_string()’ (did you forget the ‘()’ ?)
     (strm » _tao_aggregate.demo_string.out ());
              ~~~~~~~~~~~~~~~^~~~~~~~~~~
demoC.cpp:54:41: error: expected ‘)’ before ‘out’
     (strm » _tao_aggregate.demo_string.out ());
                                         ^~~
<PATH>/CMakeFiles/MyLib.dir/build.make:137: recipe for target '<PATH>/CMakeFiles/MyLib.dir/demoC.cpp.o' failed
make[2]: * [<PATH>/CMakeFiles/MyLib.dir/demoC.cpp.o] Error 1
CMakeFiles/Makefile2:1141: recipe for target '<PATH>/CMakeFiles/MyLib.dir/all' failed
make[1]: * [<PATH>/CMakeFiles/MyLib.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

Am I missing something in the CMake call to OPENDDS_TARGET_SOURCES? Thanks in advance for any help!

mitza-oci commented 4 years ago

Please look at the Developer's Guide section on code generation in C++11 mode.

SalvoVirga commented 4 years ago

I did, on page 132 it only says running “opendds_idl -Lc++11". Which to my understanding is what OPENDDS_IDL_OPTIONS -Lc++11 should allow to do. I cannot find any more info regarding this.

mitza-oci commented 4 years ago

There are more changes than just -Lc++11

Unlike when using the classic mapping, Foo.idl is not processed by tao_idl.

I suggest starting from a working example project (generated by MPC) and then change CMake to do the same thing.

iguessthislldo commented 4 years ago

I think this is enough to get this working:

diff --git a/cmake/dds_idl_sources.cmake b/cmake/dds_idl_sources.cmake
index 7c4c6f51f..8f5373f5d 100644
--- a/cmake/dds_idl_sources.cmake
+++ b/cmake/dds_idl_sources.cmake
@@ -135,8 +135,9 @@ function(opendds_target_idl_sources target)
     unset(_ddsidl_cmd_arg_-GfaceTS)
     unset(_ddsidl_cmd_arg_-o)
     unset(_ddsidl_cmd_arg_-Wb,java)
+    unset(_ddsidl_cmd_arg_-Lc++11)

-    cmake_parse_arguments(_ddsidl_cmd_arg "-SI;-GfaceTS;-Wb,java" "-o" "" ${_ddsidl_flags})
+    cmake_parse_arguments(_ddsidl_cmd_arg "-SI;-GfaceTS;-Wb,java;-Lc++11" "-o" "" ${_ddsidl_flags})

     get_filename_component(noext_name ${input} NAME_WE)
     get_filename_component(abs_filename ${input} ABSOLUTE)
@@ -162,6 +163,8 @@ function(opendds_target_idl_sources target)
       list(APPEND _cur_idl_headers ${output_prefix}C.h ${output_prefix}_TS.hpp)
       list(APPEND _cur_idl_cpp_files ${output_prefix}_TS.cpp)
       ## if this is FACE IDL, do not reprocess the original idl file throught tao_idl
+    elseif (_ddsidl_cmd_arg_-Lc++11)
+      list(APPEND _cur_idl_headers "${output_prefix}C.h")
     else()
       set(_cur_idl_file ${input})
     endif()

It compiles the given example. I think it just needs its own test and maybe a way to signal which mapping is being used (for https://github.com/oci-labs/pyopendds/issues/9).