mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-06 02:50:34 +08:00
Proper C++ version detection
This commit is contained in:
@@ -16,6 +16,21 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
/**
|
||||
* UAVCAN can be compiled in C++11 mode.
|
||||
* This macro allows to detect which version of the C++ standard is being used.
|
||||
*/
|
||||
#define UAVCAN_CPP11 2011
|
||||
#define UAVCAN_CPP03 2003
|
||||
|
||||
#if __cplusplus > 201200
|
||||
# error Unsupported C++ standard
|
||||
#elif (__cplusplus > 201100) || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
# define UAVCAN_CPP_VERSION UAVCAN_CPP11
|
||||
#else
|
||||
# define UAVCAN_CPP_VERSION UAVCAN_CPP03
|
||||
#endif
|
||||
|
||||
/**
|
||||
* UAVCAN can be explicitly told to ignore exceptions, or it can be detected automatically.
|
||||
*/
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
#include <limits>
|
||||
#include <uavcan/data_type.hpp>
|
||||
#include <uavcan/util/compile_time.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
#include <uavcan/marshal/type_util.hpp>
|
||||
#include <uavcan/marshal/integer_spec.hpp>
|
||||
#if __cplusplus > 201100
|
||||
# include <cmath>
|
||||
#else
|
||||
# include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
#ifndef UAVCAN_CPP_VERSION
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
#if UAVCAN_CPP_VERSION < UAVCAN_CPP11
|
||||
# include <math.h> // Needed for isfinite()
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include <uavcan/fatal_error.hpp>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
|
||||
#ifndef UAVCAN_CPP_VERSION
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
@@ -31,7 +35,7 @@ class LazyConstructor
|
||||
|
||||
template <typename U> struct ParamType { typedef const U& Type; };
|
||||
template <typename U> struct ParamType<U&> { typedef U& Type; };
|
||||
#if __cplusplus > 201100
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
template <typename U> struct ParamType<U&&> { typedef U&& Type; };
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,9 +3,20 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/impl_constants.hpp>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifndef UAVCAN_CPP_VERSION
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
#if UAVCAN_CPP_VERSION == UAVCAN_CPP11
|
||||
std::cout << "C++11" << std::endl;
|
||||
#elif UAVCAN_CPP_VERSION == UAVCAN_CPP03
|
||||
std::cout << "C++03" << std::endl;
|
||||
#else
|
||||
# error UAVCAN_CPP_VERSION
|
||||
#endif
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user