Skip to content

Commit

Permalink
Updates for NDK 17.
Browse files Browse the repository at this point in the history
Added optional support for C++14.

Always assume that asio can use move semantics.

Embed TinyXML2 and Asio if THIRDPARTY is enabled, even if they are found on the system

Switch to asio 1.12.0
  • Loading branch information
esteve committed Jun 20, 2018
1 parent fb91928 commit a8f793e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 270 deletions.
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ if(MSVC OR MSVC_IDE)
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-unknown-pragmas -std=c++11")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
endif()
endif()

add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)

if(ANDROID)
if(NOT HAVE_CXX14 AND NOT HAVE_CXX1Y)
add_definitions(-DASIO_DISABLE_STD_STRING_VIEW)
endif()
endif()

###############################################################################
Expand Down Expand Up @@ -206,7 +222,7 @@ eprosima_find_thirdparty(Asio asio)
eprosima_find_thirdparty(TinyXML2 tinyxml2)

if(ANDROID)
find_eprosima_thirdparty(android-ifaddrs android-ifaddrs)
eprosima_find_thirdparty(android-ifaddrs android-ifaddrs)
endif()

###############################################################################
Expand Down
36 changes: 28 additions & 8 deletions cmake/common/check_configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,39 @@ macro(check_stdcxx)
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
check_cxx_compiler_flag(-std=c++14 SUPPORTS_CXX14)
set(HAVE_CXX14 0)
set(HAVE_CXX1Y 0)
set(HAVE_CXX11 0)
set(HAVE_CXX0X 0)
if(SUPPORTS_CXX14)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++14>)
set(HAVE_CXX14 1)
set(HAVE_CXX1Y 1)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
set(HAVE_CXX11 0)
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X)
if(SUPPORTS_CXX0X)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>)
check_cxx_compiler_flag(-std=c++1y SUPPORTS_CXX1Y)
if(SUPPORTS_CXX1Y)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++1y>)
set(HAVE_CXX1Y 1)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
set(HAVE_CXX0X 0)
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X)
if(SUPPORTS_CXX0X)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>)
set(HAVE_CXX0X 1)
else()
set(HAVE_CXX0X 0)
endif()
endif()
endif()
endif()
elseif(MSVC OR MSVC_IDE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindAsio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ASIO_INCLUDE_DIR

find_package(Asio CONFIG QUIET)
if(Asio_FOUND)
if(Asio_FOUND AND NOT THIRDPARTY)
message(STATUS "Found Asio")
else()
if(THIRDPARTY OR ANDROID)
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/FindTinyXML2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
option(TINYXML2_FROM_SOURCE "Integrate TinyXML2 source code inside Fast RTPS" OFF)

find_package(TinyXML2 CONFIG QUIET)
if(TinyXML2_FOUND)
if(TinyXML2_FOUND AND NOT THIRDPARTY)
message(STATUS "Found TinyXML2: ${TinyXML2_DIR}")
if(NOT TINYXML2_LIBRARY AND TARGET tinyxml2)
# in this case, we're probably using TinyXML2 version 5.0.0 or greater
# in which case tinyxml2 is an exported target and we should use that
set(TINYXML2_LIBRARY tinyxml2)
endif()
else()
if(THIRDPARTY)
if(THIRDPARTY OR ANDROID)
set(TINYXML2_FROM_SOURCE ON)
endif()

Expand Down
31 changes: 0 additions & 31 deletions include/fastrtps/transport/UDPv4Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,20 @@ class UDPv4Transport : public TransportInterface
{
public:

#if defined(ASIO_HAS_MOVE)
SocketInfo(asio::ip::udp::socket& socket) :
socket_(std::move(socket)), only_multicast_purpose_(false)
#else
SocketInfo(std::shared_ptr<asio::ip::udp::socket> socket) :
socket_(socket), only_multicast_purpose_(false)
#endif
{
}

SocketInfo(SocketInfo&& socketInfo) :
#if defined(ASIO_HAS_MOVE)
socket_(std::move(socketInfo.socket_)),
#else
socket_(socketInfo.socket_),
#endif
only_multicast_purpose_(socketInfo.only_multicast_purpose_)
{
}

SocketInfo& operator=(SocketInfo&& socketInfo)
{
#if defined(ASIO_HAS_MOVE)
socket_ = std::move(socketInfo.socket_);
#else
socket_ = socketInfo.socket_;
#endif
only_multicast_purpose_ = socketInfo.only_multicast_purpose_;
return *this;
}
Expand All @@ -99,11 +86,7 @@ class UDPv4Transport : public TransportInterface
return only_multicast_purpose_;
}

#if defined(ASIO_HAS_MOVE)
asio::ip::udp::socket socket_;
#else
std::shared_ptr<asio::ip::udp::socket> socket_;
#endif
bool only_multicast_purpose_;

private:
Expand Down Expand Up @@ -212,35 +195,21 @@ class UDPv4Transport : public TransportInterface
{return (memcmp(&lhs, &rhs, sizeof(Locator_t)) < 0); } };

//! For both modes, an input channel corresponds to a port.
#if defined(ASIO_HAS_MOVE)
std::map<uint32_t, asio::ip::udp::socket> mInputSockets;
#else
std::map<uint32_t, std::shared_ptr<asio::ip::udp::socket>> mInputSockets;
#endif

bool IsInterfaceAllowed(const asio::ip::address_v4& ip);
std::vector<asio::ip::address_v4> mInterfaceWhiteList;

bool OpenAndBindOutputSockets(Locator_t& locator);
bool OpenAndBindInputSockets(uint32_t port, bool is_multicast);

#if defined(ASIO_HAS_MOVE)
asio::ip::udp::socket OpenAndBindUnicastOutputSocket(const asio::ip::address_v4&, uint32_t& port);
asio::ip::udp::socket OpenAndBindInputSocket(uint32_t port, bool is_multicast);

bool SendThroughSocket(const octet* sendBuffer,
uint32_t sendBufferSize,
const Locator_t& remoteLocator,
asio::ip::udp::socket& socket);
#else
std::shared_ptr<asio::ip::udp::socket> OpenAndBindUnicastOutputSocket(const asio::ip::address_v4&, uint32_t& port);
std::shared_ptr<asio::ip::udp::socket> OpenAndBindInputSocket(uint32_t port, bool is_multicast);

bool SendThroughSocket(const octet* sendBuffer,
uint32_t sendBufferSize,
const Locator_t& remoteLocator,
std::shared_ptr<asio::ip::udp::socket> socket);
#endif
};

} // namespace rtps
Expand Down
31 changes: 0 additions & 31 deletions include/fastrtps/transport/UDPv6Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,20 @@ class UDPv6Transport : public TransportInterface
{
public:

#if defined(ASIO_HAS_MOVE)
SocketInfo(asio::ip::udp::socket& socket) :
socket_(std::move(socket)), only_multicast_purpose_(false)
#else
SocketInfo(std::shared_ptr<asio::ip::udp::socket> socket) :
socket_(socket), only_multicast_purpose_(false)
#endif
{
}

SocketInfo(SocketInfo&& socketInfo) :
#if defined(ASIO_HAS_MOVE)
socket_(std::move(socketInfo.socket_)),
#else
socket_(socketInfo.socket_),
#endif
only_multicast_purpose_(socketInfo.only_multicast_purpose_)
{
}

SocketInfo& operator=(SocketInfo&& socketInfo)
{
#if defined(ASIO_HAS_MOVE)
socket_ = std::move(socketInfo.socket_);
#else
socket_ = socketInfo.socket_;
#endif
only_multicast_purpose_ = socketInfo.only_multicast_purpose_;
return *this;
}
Expand All @@ -101,11 +88,7 @@ class UDPv6Transport : public TransportInterface
return only_multicast_purpose_;
}

#if defined(ASIO_HAS_MOVE)
asio::ip::udp::socket socket_;
#else
std::shared_ptr<asio::ip::udp::socket> socket_;
#endif
bool only_multicast_purpose_;

private:
Expand Down Expand Up @@ -214,11 +197,7 @@ class UDPv6Transport : public TransportInterface
struct LocatorCompare{ bool operator()(const Locator_t& lhs, const Locator_t& rhs) const
{return (memcmp(&lhs, &rhs, sizeof(Locator_t)) < 0); } };
//! For both modes, an input channel corresponds to a port.
#if defined(ASIO_HAS_MOVE)
std::map<uint32_t, asio::ip::udp::socket> mInputSockets;
#else
std::map<uint32_t, std::shared_ptr<asio::ip::udp::socket>> mInputSockets;
#endif

bool IsInterfaceAllowed(const asio::ip::address_v6& ip);
std::vector<asio::ip::address_v6> mInterfaceWhiteList;
Expand All @@ -227,23 +206,13 @@ class UDPv6Transport : public TransportInterface
bool OpenAndBindOutputSockets(Locator_t& locator);
bool OpenAndBindInputSockets(uint32_t port, bool is_multicast);

#if defined(ASIO_HAS_MOVE)
asio::ip::udp::socket OpenAndBindUnicastOutputSocket(const asio::ip::address_v6&, uint32_t& port);
asio::ip::udp::socket OpenAndBindInputSocket(uint32_t port, bool is_multicast);

bool SendThroughSocket(const octet* sendBuffer,
uint32_t sendBufferSize,
const Locator_t& remoteLocator,
asio::ip::udp::socket& socket);
#else
std::shared_ptr<asio::ip::udp::socket> OpenAndBindUnicastOutputSocket(const asio::ip::address_v6&, uint32_t& port);
std::shared_ptr<asio::ip::udp::socket> OpenAndBindInputSocket(uint32_t port, bool is_multicast);

bool SendThroughSocket(const octet* sendBuffer,
uint32_t sendBufferSize,
const Locator_t& remoteLocator,
std::shared_ptr<asio::ip::udp::socket> socket);
#endif
};

} // namespace rtps
Expand Down
14 changes: 1 addition & 13 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ if(TINYXML2_SOURCE_DIR)
list(APPEND ${PROJECT_NAME}_source_files
${TINYXML2_SOURCE_DIR}/tinyxml2.cpp
)
set_sources(../../thirdparty/tinyxml2/tinyxml2.cpp)
set_sources(${TINYXML2_SOURCE_DIR}/tinyxml2.cpp)
endif()

if(ANDROID)
Expand All @@ -202,18 +202,6 @@ if(INTERNAL_DEBUG)
add_definitions(-D__INTERNALDEBUG)
endif()

add_definitions(
-DBOOST_ASIO_STANDALONE
-DASIO_STANDALONE
)

if(ANDROID)
add_definitions(
-DASIO_DISABLE_MOVE
-DASIO_DISABLE_STD_STRING_VIEW
)
endif()

set(${PROJECT_NAME}_include_dirs
${ASIO_INCLUDE_DIR}
${TINYXML2_INCLUDE_DIR}
Expand Down
Loading

0 comments on commit a8f793e

Please sign in to comment.