From 756d10b165aadbc9a39ef9bc6581d10929dfb8d9 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Mon, 8 Jun 2020 22:27:04 -0500 Subject: [PATCH] Support for C++11 Mapping in the CMake Module Fix for https://github.com/objectcomputing/OpenDDS/issues/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 https://github.com/oci-labs/pyopendds/issues/9. --- cmake/dds_idl_sources.cmake | 45 ++++++++++++++++++- docs/cmake.md | 23 ++++++++++ .../DDS_Cxx11_Messenger_Publisher.mpc | 1 + .../C++11/Messenger/Publisher/publisher.cpp | 14 +++--- .../DDS_Cxx11_Messenger_Subscriber.mpc | 1 + .../C++11/Messenger/Subscriber/subscriber.cpp | 14 +++--- .../Messenger/C++11_Messenger/.gitignore | 1 + .../Messenger/CMakeLists.txt | 1 + .../Messenger/Messenger_1/CMakeLists.txt | 6 +++ 9 files changed, 91 insertions(+), 15 deletions(-) create mode 100644 tests/cmake_integration/Messenger/C++11_Messenger/.gitignore diff --git a/cmake/dds_idl_sources.cmake b/cmake/dds_idl_sources.cmake index 7c4c6f51f05..e624e559d92 100644 --- a/cmake/dds_idl_sources.cmake +++ b/cmake/dds_idl_sources.cmake @@ -62,11 +62,32 @@ 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) @@ -74,6 +95,7 @@ function(opendds_target_idl_sources target) # 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}) @@ -81,6 +103,9 @@ function(opendds_target_idl_sources target) endforeach() if (NOT non_generated_idl_files) + list(REMOVE_DUPLICATES language_mappings) + set_property(TARGET ${target} + PROPERTY "OPENDDS_LANGUAGE_MAPPINGS" ${language_mappings}) return() endif() @@ -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) @@ -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() @@ -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 @@ -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() diff --git a/docs/cmake.md b/docs/cmake.md index d3d7649c9d5..a80af2e8036 100644 --- a/docs/cmake.md +++ b/docs/cmake.md @@ -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 @@ -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. @@ -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. diff --git a/tests/DCPS/C++11/Messenger/Publisher/DDS_Cxx11_Messenger_Publisher.mpc b/tests/DCPS/C++11/Messenger/Publisher/DDS_Cxx11_Messenger_Publisher.mpc index 38d162db215..0968dfd53e7 100644 --- a/tests/DCPS/C++11/Messenger/Publisher/DDS_Cxx11_Messenger_Publisher.mpc +++ b/tests/DCPS/C++11/Messenger/Publisher/DDS_Cxx11_Messenger_Publisher.mpc @@ -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 diff --git a/tests/DCPS/C++11/Messenger/Publisher/publisher.cpp b/tests/DCPS/C++11/Messenger/Publisher/publisher.cpp index 458605720dc..90bd01f8a5c 100644 --- a/tests/DCPS/C++11/Messenger/Publisher/publisher.cpp +++ b/tests/DCPS/C++11/Messenger/Publisher/publisher.cpp @@ -3,15 +3,15 @@ * See: http://www.opendds.org/license.html */ -#include "../Idl/MessengerTypeSupportImpl.h" +#include -#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 +#include +#include +#include +#include -#include "ace/Log_Msg.h" +#include #include #include diff --git a/tests/DCPS/C++11/Messenger/Subscriber/DDS_Cxx11_Messenger_Subscriber.mpc b/tests/DCPS/C++11/Messenger/Subscriber/DDS_Cxx11_Messenger_Subscriber.mpc index 45af19d74b1..2921b1edc38 100644 --- a/tests/DCPS/C++11/Messenger/Subscriber/DDS_Cxx11_Messenger_Subscriber.mpc +++ b/tests/DCPS/C++11/Messenger/Subscriber/DDS_Cxx11_Messenger_Subscriber.mpc @@ -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 diff --git a/tests/DCPS/C++11/Messenger/Subscriber/subscriber.cpp b/tests/DCPS/C++11/Messenger/Subscriber/subscriber.cpp index 38482d6a6a4..e38487819dc 100644 --- a/tests/DCPS/C++11/Messenger/Subscriber/subscriber.cpp +++ b/tests/DCPS/C++11/Messenger/Subscriber/subscriber.cpp @@ -3,15 +3,15 @@ * See: http://www.opendds.org/license.html */ -#include "../Idl/MessengerTypeSupportImpl.h" +#include -#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 +#include +#include +#include +#include -#include "ace/Log_Msg.h" +#include #include #include diff --git a/tests/cmake_integration/Messenger/C++11_Messenger/.gitignore b/tests/cmake_integration/Messenger/C++11_Messenger/.gitignore new file mode 100644 index 00000000000..796b96d1c40 --- /dev/null +++ b/tests/cmake_integration/Messenger/C++11_Messenger/.gitignore @@ -0,0 +1 @@ +/build diff --git a/tests/cmake_integration/Messenger/CMakeLists.txt b/tests/cmake_integration/Messenger/CMakeLists.txt index 4b9bf7d6162..c1d78ead414 100644 --- a/tests/cmake_integration/Messenger/CMakeLists.txt +++ b/tests/cmake_integration/Messenger/CMakeLists.txt @@ -4,3 +4,4 @@ project(opendds_cmake_messenger_tests) add_subdirectory(Messenger_1) add_subdirectory(Messenger_2) +add_subdirectory(C++11_Messenger) diff --git a/tests/cmake_integration/Messenger/Messenger_1/CMakeLists.txt b/tests/cmake_integration/Messenger/Messenger_1/CMakeLists.txt index e6706948423..57ab60b0636 100644 --- a/tests/cmake_integration/Messenger/Messenger_1/CMakeLists.txt +++ b/tests/cmake_integration/Messenger/Messenger_1/CMakeLists.txt @@ -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