Skip to content

Commit

Permalink
Support for C++11 Mapping in the CMake Module
Browse files Browse the repository at this point in the history
Fix for OpenDDS#1714

Support for the C++11 mapping in the CMake module. `-Lc++11` can now be
passed with `OPENDDS_IDL_OPTIONS` in `OPENDDS_TARGET_SOURCES`.

Also added a property to the target of `OPENDDS_TARGET_SOURCES` called
`OPENDDS_LANGUAGE_MAPPING` that states what mapping was used. This will
be exported if supported by CMake. Fix for
OpenDDS/pyopendds#9.
  • Loading branch information
iguessthislldo committed Oct 19, 2020
1 parent 8a7a5cc commit 756d10b
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 15 deletions.
45 changes: 44 additions & 1 deletion cmake/dds_idl_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,50 @@ function(opendds_target_idl_sources target)
set(multiValueArgs TAO_IDL_FLAGS DDS_IDL_FLAGS IDL_FILES)
cmake_parse_arguments(_arg "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Language mapping usage are designated on an IDL file by IDL file basis,
# then at combined (or mixed together) on a target by target basis. If this
# target has any existing mappings set, combine those with any mappings on
# the IDL files. If we need to generate rules for a IDL file, then add those
# to the IDL file and the target.
get_property(language_mappings TARGET ${target}
PROPERTY "OPENDDS_LANGUAGE_MAPPINGS")
# Make sure OPENDDS_LANGUAGE_MAPPINGS is exported if supported
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
get_property(target_export_properties TARGET ${target}
PROPERTY "EXPORT_PROPERTIES")
if(NOT ("OPENDDS_LANGUAGE_MAPPINGS" IN_LIST target_export_properties))
list(APPEND target_export_properties "OPENDDS_LANGUAGE_MAPPINGS")
set_property(TARGET ${target} PROPERTY "EXPORT_PROPERTIES"
"${target_export_properties}")
endif()
endif()

foreach(idl_file ${_arg_IDL_FILES})
if (NOT IS_ABSOLUTE ${idl_file})
set(idl_file ${CMAKE_CURRENT_LIST_DIR}/${idl_file})
endif()

get_property(file_language_mappings SOURCE ${idl_file}
PROPERTY "OPENDDS_LANGUAGE_MAPPINGS")

get_property(_generated_dependencies SOURCE ${idl_file}
PROPERTY OPENDDS_IDL_GENERATED_DEPENDENCIES SET)

if (_generated_dependencies)
# If an IDL-Generation command was already created this file can safely be
# skipped; however, the dependencies still need to be added to the target.
opendds_target_generated_dependencies(${target} ${idl_file} ${_arg_SCOPE})
list(APPEND language_mappings ${file_language_mappings})

else()
list(APPEND non_generated_idl_files ${idl_file})
endif()
endforeach()

if (NOT non_generated_idl_files)
list(REMOVE_DUPLICATES language_mappings)
set_property(TARGET ${target}
PROPERTY "OPENDDS_LANGUAGE_MAPPINGS" ${language_mappings})
return()
endif()

Expand Down Expand Up @@ -135,8 +160,11 @@ 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)
unset(file_language_mappings)

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)
Expand All @@ -162,13 +190,19 @@ 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
list(APPEND file_language_mappings "FACE")
elseif (_ddsidl_cmd_arg_-Lc++11)
list(APPEND _cur_idl_headers "${output_prefix}C.h")
list(APPEND file_language_mappings "C++11")
else()
set(_cur_idl_file ${input})
list(APPEND file_language_mappings "C++03")
endif()

if (_ddsidl_cmd_arg_-Wb,java)
set(_cur_java_list "${output_prefix}${file_ext}.TypeSupportImpl.java.list")
list(APPEND file_dds_idl_flags -j)
list(APPEND file_language_mappings "Java")
else()
unset(_cur_java_list)
endif()
Expand Down Expand Up @@ -200,6 +234,9 @@ function(opendds_target_idl_sources target)
set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_JAVA_OUTPUTS "@${_cur_java_list}")

set_property(SOURCE ${abs_filename} APPEND PROPERTY
OPENDDS_LANGUAGE_MAPPINGS ${file_language_mappings})

if (NOT _arg_SKIP_TAO_IDL)
tao_idl_command(${target}
IDL_FLAGS
Expand All @@ -213,5 +250,11 @@ function(opendds_target_idl_sources target)
OPENDDS_IDL_GENERATED_DEPENDENCIES TRUE)

opendds_target_generated_dependencies(${target} ${abs_filename} ${_arg_SCOPE})

list(APPEND language_mappings ${file_language_mappings})
list(REMOVE_DUPLICATES language_mappings)
endforeach()

set_property(TARGET ${target}
PROPERTY "OPENDDS_LANGUAGE_MAPPINGS" ${language_mappings})
endfunction()
23 changes: 23 additions & 0 deletions docs/cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ which simplifies IDL compilation.
* [Optional OpenDDS Features](#optional-opendds-features)
* [Build-Related Options](#build-related-options)
* [`OPENDDS_DEFAULT_NESTED`](#opendds_default_nested)
* [`OPENDDS_LANGUAGE_MAPPINGS`](#opendds_language_mappings)

## Requirements

Expand Down Expand Up @@ -197,6 +198,7 @@ built-in [`target_sources`](https://cmake.org/cmake/help/latest/command/target_s
- Command-line options can be supplied to the TAO/OpenDDS IDL compilers
using `TAO_IDL_OPTIONS` and/or `OPENDDS_IDL_OPTIONS` (if the default
behavior is not suitable).
- Add `OPENDDS_IDL_OPTIONS -Lc++11` to use the C++11 IDL Mapping.

When IDL sources are supplied, custom commands are generated which will
be invoked to compile the IDL sources into their component cpp/h files.
Expand Down Expand Up @@ -341,3 +343,24 @@ OPENDDS_TARGET_SOURCES(messenger
OPENDDS_IDL_OPTIONS --no-default-nested
)
```

### `OPENDDS_LANGUAGE_MAPPINGS`

After `OPENDDS_TARGET_SOURCES` is used on a target, it will have the
`OPENDDS_LANGUAGE_MAPPINGS` target property set. This signifies the IDL
language mappings available in the IDL bindings generated into the target based
on what is passed to `OPENDDS_IDL_OPTIONS`. It will be a list that can contain
one or more of the following:

- `"C++03"`
- Default IDL-to-C++ mapping generated by default.
- `"C++11"`
- IDL-to-C++11 mapping available when passing `-Lc++11`.
- `"FACE"`
- Will appear if `-GfaceTS` is passed.
- `"Java"`
- Currently unsupported in the CMake module, but this will appear in the
list if `-Wb,java` is passed.

If the CMake version is at least 3.12 then this property will exported with the
target.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project: dcpsexe, dcps_test, dcps_transports_for_test{
after += DDS_Cxx11_Messenger_Idl
libs += DDS_Cxx11_Messenger_Idl
libpaths += ../Idl
includes += ../Idl

Source_Files {
publisher.cpp
Expand Down
14 changes: 7 additions & 7 deletions tests/DCPS/C++11/Messenger/Publisher/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* See: http://www.opendds.org/license.html
*/

#include "../Idl/MessengerTypeSupportImpl.h"
#include <MessengerTypeSupportImpl.h>

#include "dds/DCPS/Marked_Default_Qos.h"
#include "dds/DCPS/PublisherImpl.h"
#include "dds/DCPS/Service_Participant.h"
#include "dds/DCPS/StaticIncludes.h"
#include "dds/DCPS/WaitSet.h"
#include <dds/DCPS/Marked_Default_Qos.h>
#include <dds/DCPS/PublisherImpl.h>
#include <dds/DCPS/Service_Participant.h>
#include <dds/DCPS/StaticIncludes.h>
#include <dds/DCPS/WaitSet.h>

#include "ace/Log_Msg.h"
#include <ace/Log_Msg.h>

#include <iostream>
#include <cstdlib>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project: dcpsexe, dcps_test, dcps_transports_for_test{
after += DDS_Cxx11_Messenger_Idl
libs += DDS_Cxx11_Messenger_Idl
libpaths += ../Idl
includes += ../Idl

Source_Files {
subscriber.cpp
Expand Down
14 changes: 7 additions & 7 deletions tests/DCPS/C++11/Messenger/Subscriber/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* See: http://www.opendds.org/license.html
*/

#include "../Idl/MessengerTypeSupportImpl.h"
#include <MessengerTypeSupportImpl.h>

#include "dds/DCPS/Marked_Default_Qos.h"
#include "dds/DCPS/PublisherImpl.h"
#include "dds/DCPS/Service_Participant.h"
#include "dds/DCPS/StaticIncludes.h"
#include "dds/DCPS/WaitSet.h"
#include <dds/DCPS/Marked_Default_Qos.h>
#include <dds/DCPS/PublisherImpl.h>
#include <dds/DCPS/Service_Participant.h>
#include <dds/DCPS/StaticIncludes.h>
#include <dds/DCPS/WaitSet.h>

#include "ace/Log_Msg.h"
#include <ace/Log_Msg.h>

#include <iostream>
#include <cstdlib>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
1 change: 1 addition & 0 deletions tests/cmake_integration/Messenger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ project(opendds_cmake_messenger_tests)

add_subdirectory(Messenger_1)
add_subdirectory(Messenger_2)
add_subdirectory(C++11_Messenger)
6 changes: 6 additions & 0 deletions tests/cmake_integration/Messenger/Messenger_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ foreach(t ${all_targets})
# https://github.com/objectcomputing/OpenDDS/issues/1336
# See https://cmake.org/cmake/help/latest/policy/CMP0023.html
target_link_libraries(${t} PUBLIC OpenDDS::OpenDDS)

# Assert the mapping used was C++03
get_property(mappings TARGET ${t} PROPERTY OPENDDS_LANGUAGE_MAPPINGS)
if(NOT "C++03" IN_LIST mappings)
message(FATAL_ERROR "${t}: C++03 NOT in mapping list: ${mappings}")
endif()
endforeach()

# Copy configs/scripts into build-output directory
Expand Down

0 comments on commit 756d10b

Please sign in to comment.