1
0
Fork 0

make it explicit when RTTI is beneficial

This commit is contained in:
Kevin Matz 2021-07-28 10:37:33 -04:00
parent 5851e1d55e
commit 4702ac333d
4 changed files with 29 additions and 2 deletions

View File

@ -7,6 +7,7 @@ set(DEFAULT_BUILD_TYPE "Release")
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(SOURCE_FILES
acn/acn.h
@ -29,6 +30,7 @@ set(SOURCE_FILES
acn/sdt-udp.h
acn/sdt.cpp
acn/sdt.h
build/has_rtti.h
dmx/universe.cpp
dmx/universe.h
sacn/data.cpp

15
build/has_rtti.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#if defined(__clang__)
#if __has_feature(cxx_rtti)
#define RTTI_ENABLED
#endif
#elif defined(__GNUG__)
#if defined(__GXX_RTTI)
#define RTTI_ENABLED
#endif
#elif defined(_MSC_VER)
#if defined(_CPPRTTI)
#define RTTI_ENABLED
#endif
#endif

View File

@ -8,6 +8,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
find_package(QT NAMES Qt6 Qt5 COMPONENTS Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network REQUIRED)

View File

@ -23,6 +23,7 @@
*/
#include "universe.h"
#include "../build/has_rtti.h"
namespace SACN {
@ -44,10 +45,18 @@ UniverseSource::UniverseSource()
*/
UniverseSource::UniverseSource(std::shared_ptr<DATA::Pdu> pdu)
{
auto root_header = (RLP::rlp_header*)pdu->parent()->header();
#if defined(RTTI_ENABLED)
auto root_header = dynamic_cast<RLP::rlp_header*>(pdu->parent()->header());
#else
auto root_header = static_cast<RLP::rlp_header*>(pdu->parent()->header());
#endif
cid_ = root_header->cid;
auto frame_header = (DATA::frame_header*)pdu->header();
#if defined(RTTI_ENABLED)
auto frame_header = dynamic_cast<DATA::frame_header*>(pdu->header());
#else
auto frame_header = static_cast<DATA::frame_header*>(pdu->header());
#endif
description_ = std::string((char*)frame_header->source_name);
universe_ = frame_header->universe;
priority_ = frame_header->priority;