Skip to content

Commit

Permalink
feature c++11 compatibility (eclipse-cyclonedds#280)
Browse files Browse the repository at this point in the history
* implement c++11 legacy mode

* Bugfix/c++11 windows (eclipse-cyclonedds#1)

* fix boost include for windows CDRStreamer.cpp
* fix cplusplus macro for tests
* fix cplusplus macro for ddscxx

* remove redundant code

* remove redundat code

* add azure pipeline for legacy c++11 mode

* add c++11 test on windows

* run c++11 azure build only once not multiple times

* c++11 legacy mode improvements

* remove unneeded feature list

* fix azure pipeline run
  • Loading branch information
trittsv authored Jun 14, 2022
1 parent abffed2 commit 4c96197
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 245 deletions.
1 change: 1 addition & 0 deletions .azure/templates/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ steps:
-DSANITIZER=${SANITIZER:-none} \
-DENABLE_SHM=${ICEORYX:-off} \
-DENABLE_COVERAGE=${COVERAGE:-off} \
-DENABLE_LEGACY=${LEGACY:-off} \
-DBUILD_TESTING=on \
-DBUILD_EXAMPLES=on \
-DWERROR=on \
Expand Down
229 changes: 0 additions & 229 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ option(BUILD_TESTING "Build the testing tree." OFF)
# deprecated.
option(BUILD_EXAMPLES "Build examples." OFF)

# Legacy c++11 compatibility - for projects which cant use
# the latest compiler features because they have to
# support some limited/legacy platforms (e.g. older QNX versions)
# this will add boost as a dependency
# c++11 seems like a good tradeoff between the old and the new world
option(ENABLE_LEGACY "Legacy c++11 compatibility." OFF)
set(cyclonedds_cpp_std_to_use 17)
if(ENABLE_LEGACY)
set(cyclonedds_cpp_std_to_use 11)
set(DDSCXX_USE_BOOST "1")
find_package(Boost)
include_directories(${Boost_INCLUDE_DIR})
endif()

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(CTest)
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ To obtain the C++ binding for Cyclone DDS, do
Depending on whether you want to develop applications using the C++ binding
for Cyclone DDS or contribute to it you can follow different procedures.

### Build configuration

There are some configuration options specified using CMake defines in addition to the standard options like `CMAKE_BUILD_TYPE`:
* `-DBUILD_IDLLIB=OFF`: to disable IDL preprocessor lib build
* `-DBUILD_DOCS=ON`: to build the documentation
* `-DBUILD_TESTING=ON`: to build the testing tree
* `-DBUILD_EXAMPLES=ON`: to build examples
* `-DENABLE_LEGACY=YES`: to enable legacy c++11 mode, adds boost as dependency (otherwise it uses c++17)
* `-DENABLE_SHM=YES`: to enable shared memory support
* `-DENABLE_TYPE_DISCOVERY=YES`: to enable type discovery support
* `-DENABLE_TOPIC_DISCOVERY=YES`: to enable topic discovery support
* `-DENABLE_COVERAGE=YES`: to enable coverage build

### For application developers

To build and install the required libraries needed to develop your own
Expand Down
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ strategy:
image: windows-2019
build_type: Release
generator: 'Visual Studio 16 2019'
'Windows 2019 with Visual Studio 2019 (Release, x86_64, c++11)':
image: windows-2019
build_type: Release
generator: 'Visual Studio 16 2019'
legacy: on

pool:
vmImage: $(image)
Expand Down
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[requires]
gtest/1.10.0
boost/1.78.0

[generators]
cmake
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ if(DEFINED ENV{SYSTEM_TEAMFOUNDATIONSERVERURI})
endif()
endif()

set_property(TARGET ddscxxHelloworldPublisher PROPERTY CXX_STANDARD 17)
set_property(TARGET ddscxxHelloworldSubscriber PROPERTY CXX_STANDARD 17)
set_property(TARGET ddscxxHelloworldPublisher PROPERTY CXX_STANDARD ${cyclonedds_cpp_std_to_use})
set_property(TARGET ddscxxHelloworldSubscriber PROPERTY CXX_STANDARD ${cyclonedds_cpp_std_to_use})
3 changes: 3 additions & 0 deletions features.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
/* Whether or not support for topic discovery is included */
#cmakedefine DDSCXX_HAS_TOPIC_DISCOVERY @DDSCXX_HAS_TOPIC_DISCOVERY@

/* Whether to use boost for c++11 compatibility or not */
#cmakedefine DDSCXX_USE_BOOST @DDSCXX_USE_BOOST@

#endif /* __OMG_DDS_DDSCXX_FEATURES_HPP__ */
6 changes: 5 additions & 1 deletion src/ddscxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ endif()
# SOVERSION should increase on incompatible ABI change
set_target_properties(ddscxx PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

if(ENABLE_LEGACY)
target_compile_definitions(ddscxx PUBLIC "DDSCXX_USE_BOOST")
endif()

# Create a pseudo-target that other targets (i.e. examples, tests) can depend
# on and can also be provided as import-target by a package-file when building
# those targets outside the regular Cyclone build-tree (i.e. the installed tree)
add_library(${CMAKE_PROJECT_NAME}::ddscxx ALIAS ddscxx)

add_coverage(ddscxx)

set_property(TARGET ddscxx PROPERTY CXX_STANDARD 17)
set_property(TARGET ddscxx PROPERTY CXX_STANDARD ${cyclonedds_cpp_std_to_use})
target_link_libraries(ddscxx PUBLIC CycloneDDS::ddsc)
target_include_directories(
ddscxx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
#include <map>
#include <atomic>
#include <mutex>

#if DDSCXX_USE_BOOST
#include <boost/type_traits.hpp>
#define DDSCXX_STD_IMPL boost
#else
#include <type_traits>
#define DDSCXX_STD_IMPL std
#endif

#include "cdr_enums.hpp"

namespace org {
Expand All @@ -28,7 +36,7 @@ namespace cyclonedds {
namespace core {
namespace cdr {

#define decl_ref_type(x) std::remove_cv_t<std::remove_reference_t<decltype(x)>>
#define decl_ref_type(x) DDSCXX_STD_IMPL::remove_cv_t<DDSCXX_STD_IMPL::remove_reference_t<decltype(x)>>

/**
* @brief
Expand Down Expand Up @@ -74,8 +82,8 @@ DDSCXX_WARNING_MSVC_ON(4251)
*
* @return The bit bound for the primitive type.
*/
template<typename T, std::enable_if_t<std::is_arithmetic<T>::value || std::is_enum<T>::value, bool> = true >
constexpr bit_bound get_bit_bound() {
template<typename T, DDSCXX_STD_IMPL::enable_if_t<std::is_arithmetic<T>::value || std::is_enum<T>::value, bool> = true >
bit_bound get_bit_bound() {
switch (sizeof(T)) {
case 1:
return bb_8_bits;
Expand All @@ -102,7 +110,7 @@ constexpr bit_bound get_bit_bound() {
*
* @return bb_unset always.
*/
template<typename T, std::enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, bool> = true >
template<typename T, DDSCXX_STD_IMPL::enable_if_t<!std::is_enum<T>::value && !std::is_arithmetic<T>::value, bool> = true >
constexpr bit_bound get_bit_bound() { return bb_unset;}

typedef struct entity_properties entity_properties_t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ class OMG_DDS_API xcdr_v2_stream : public cdr_stream {

private:
typedef struct consecutives {
bool is_array = false;
bool d_header_present = false;
consecutives(bool is_array = false, bool d_header_present = false) : is_array(is_array), d_header_present(d_header_present) {}
bool is_array;
bool d_header_present;
} consecutives_t;

static const uint32_t bytes_1; /**< length field code indicating length is 1 byte*/
Expand Down
Loading

0 comments on commit 4c96197

Please sign in to comment.