From 2fcb8f32f339f3a3cb550f10f565d6072f565012 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Jan 2017 08:10:58 +0200 Subject: Redo config as feature test macros --- butl/buildfile | 55 +++++++++++++++++++++++++++------------------------- butl/config | 52 ------------------------------------------------- butl/diagnostics | 11 ++++++----- butl/diagnostics.cxx | 2 +- butl/ft/exception | 39 +++++++++++++++++++++++++++++++++++++ butl/ft/lang | 29 +++++++++++++++++++++++++++ butl/ft/shared_mutex | 42 +++++++++++++++++++++++++++++++++++++++ butl/utility | 18 +++++++++-------- butl/utility.cxx | 4 ++-- 9 files changed, 158 insertions(+), 94 deletions(-) delete mode 100644 butl/config create mode 100644 butl/ft/exception create mode 100644 butl/ft/lang create mode 100644 butl/ft/shared_mutex diff --git a/butl/buildfile b/butl/buildfile index dd2e6bb..734195e 100644 --- a/butl/buildfile +++ b/butl/buildfile @@ -3,32 +3,34 @@ # license : MIT; see accompanying LICENSE file lib{butl}: \ -{hxx cxx}{ base64 } \ -{hxx cxx}{ char-scanner } \ -{hxx }{ config } \ -{hxx cxx}{ diagnostics } \ -{hxx }{ export } \ -{hxx ixx cxx}{ fdstream } \ -{hxx ixx cxx}{ filesystem } \ -{hxx }{ manifest-forward } \ -{hxx cxx}{ manifest-parser } \ -{hxx cxx}{ manifest-serializer } \ -{hxx }{ multi-index } \ -{hxx }{ optional } \ -{hxx cxx}{ pager } \ -{hxx ixx txx cxx}{ path } \ -{hxx }{ path-io } \ -{hxx }{ path-map } \ -{hxx txx }{ prefix-map } \ -{hxx ixx cxx}{ process } \ -{hxx cxx}{ sha256 } \ -{hxx }{ small-vector } \ -{hxx txx }{ string-table } \ -{hxx cxx}{ target-triplet } \ -{hxx cxx}{ timestamp } \ -{hxx ixx cxx}{ utility } \ -{hxx }{ vector-view } \ -{hxx }{ version } + {hxx cxx}{ base64 } \ + {hxx cxx}{ char-scanner } \ + {hxx cxx}{ diagnostics } \ + {hxx }{ export } \ + {hxx ixx cxx}{ fdstream } \ + {hxx ixx cxx}{ filesystem } \ + {hxx }{ manifest-forward } \ + {hxx cxx}{ manifest-parser } \ + {hxx cxx}{ manifest-serializer } \ + {hxx }{ multi-index } \ + {hxx }{ optional } \ + {hxx cxx}{ pager } \ + {hxx ixx txx cxx}{ path } \ + {hxx }{ path-io } \ + {hxx }{ path-map } \ + {hxx txx }{ prefix-map } \ + {hxx ixx cxx}{ process } \ + {hxx cxx}{ sha256 } \ + {hxx }{ small-vector } \ + {hxx txx }{ string-table } \ + {hxx cxx}{ target-triplet } \ + {hxx cxx}{ timestamp } \ + {hxx ixx cxx}{ utility } \ + {hxx }{ vector-view } \ + {hxx }{ version } \ +ft/{hxx }{ exception } \ +ft/{hxx }{ lang } \ +ft/{hxx }{ shared_mutex } # Exclude these from compilation on non-Windows targets. # @@ -66,3 +68,4 @@ libs{butl}: cxx.export.poptions += -DLIBBUTL_SHARED # Install into the butl/ subdirectory of, say, /usr/include/. # install.include = $install.include/butl/ +install.include.subdirs = true # Recreate subdirectories. diff --git a/butl/config b/butl/config deleted file mode 100644 index 0a5169f..0000000 --- a/butl/config +++ /dev/null @@ -1,52 +0,0 @@ -// file : butl/config -*- C++ -*- -// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#ifndef BUTL_CONFIG -#define BUTL_CONFIG - -#include // _LIBCPP_VERSION, __GLIBCXX__ - -// thread_local -// -// If this macro is undefined then we assume one can use __thread but only -// for values that do not require dynamic (runtime) initialization. -// -// Apparently Apple's Clang "temporarily disabled" C++11 thread_local -// until they can implement a "fast" version, which reportedly happened in -// XCode 8. So for now we will continue using __thread for this target. -// -#ifdef __apple_build_version__ -# if __apple_build_version__ >= 8000000 -# define BUTL_CXX11_THREAD_LOCAL -# endif -#else -# define BUTL_CXX11_THREAD_LOCAL -#endif - -// std::uncaught_exceptions() -// -// VC has it since 1900 which is the lowest version we support. -// -#if defined(_MSC_VER) -# define BUTL_CXX17_UNCAUGHT_EXCEPTIONS -// -// Clang's libc++ seems to have it for a while (but not before 1200) so we -// assume it's there from 1200 (it doesn't define a feature test macros). But -// not for MacOS, where it is explicitly marked as unavailable until MacOS -// 10.12. -// -#elif defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 1200 -# if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 -# define BUTL_CXX17_UNCAUGHT_EXCEPTIONS -# endif -// -// GCC libstdc++ has it since GCC 6 and it defines the feature test macro. -// We will also use this for any other runtime. -// -#elif defined(__cpp_lib_uncaught_exceptions) -# define BUTL_CXX17_UNCAUGHT_EXCEPTIONS -#endif - -#endif // BUTL_CONFIG diff --git a/butl/diagnostics b/butl/diagnostics index da24c69..694fae7 100644 --- a/butl/diagnostics +++ b/butl/diagnostics @@ -8,8 +8,9 @@ #include #include #include -#include // move(), forward() -#include // uncaught_exception(s)() +#include // move(), forward() +#include // uncaught_exceptions +#include // uncaught_exception(s)() #include #include @@ -42,7 +43,7 @@ namespace butl diag_record () : -#ifdef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifdef __cpp_lib_uncaught_exceptions uncaught_ (std::uncaught_exceptions ()), #endif empty_ (true), @@ -94,7 +95,7 @@ namespace butl #else diag_record (diag_record&& r) : -#ifdef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifdef __cpp_lib_uncaught_exceptions uncaught_ (r.uncaught_), #endif empty_ (r.empty_), @@ -115,7 +116,7 @@ namespace butl diag_record& operator= (const diag_record&) = delete; protected: -#ifdef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifdef __cpp_lib_uncaught_exceptions const int uncaught_; #endif mutable bool empty_; diff --git a/butl/diagnostics.cxx b/butl/diagnostics.cxx index 83c78ae..bdff3d8 100644 --- a/butl/diagnostics.cxx +++ b/butl/diagnostics.cxx @@ -31,7 +31,7 @@ namespace butl // Don't flush the record if this destructor was called as part of the // stack unwinding. // -#ifdef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifdef __cpp_lib_uncaught_exceptions if (uncaught_ == std::uncaught_exceptions ()) flush (); #else diff --git a/butl/ft/exception b/butl/ft/exception new file mode 100644 index 0000000..2dd3a38 --- /dev/null +++ b/butl/ft/exception @@ -0,0 +1,39 @@ +// file : butl/ft/exception -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_FT_EXCEPTION +#define BUTL_FT_EXCEPTION + +#include // _LIBCPP_VERSION +#include + +// __cpp_lib_uncaught_exceptions +// +#ifndef __cpp_lib_uncaught_exceptions + // + // VC has it since 1900. + // +# if defined(_MSC_VER) +# if _MSC_VER >= 1900 +# define __cpp_lib_uncaught_exceptions 201411 +# endif + // + // Clang's libc++ seems to have it for a while (but not before 1200) so we + // assume it's there from 1200. But not for MacOS, where it is explicitly + // marked as unavailable until MacOS 10.12. + // +# elif defined(_LIBCPP_VERSION) +# if _LIBCPP_VERSION >= 1200 && \ + (!defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200) +# define __cpp_lib_uncaught_exceptions 201411 +# endif + // + // GCC libstdc++ has it since GCC 6 and it defines the feature test macro. + // We will also use this for any other runtime. + // +# endif +#endif + +#endif // BUTL_FT_EXCEPTION diff --git a/butl/ft/lang b/butl/ft/lang new file mode 100644 index 0000000..8cfc441 --- /dev/null +++ b/butl/ft/lang @@ -0,0 +1,29 @@ +// file : butl/ft/lang -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_FT_LANG +#define BUTL_FT_LANG + +// __cpp_thread_local (extension) +// +// If this macro is undefined then one may choose to fallback to __thread. +// Note, however, that it only for values that do not require dynamic +// (runtime) initialization. +// +#ifndef __cpp_thread_local + // + // Apparently Apple's Clang "temporarily disabled" C++11 thread_local until + // they can implement a "fast" version, which reportedly happened in XCode + // 8. + // +# if defined(__apple_build_version__) +# if __apple_build_version__ >= 8000000 +# define __cpp_thread_local 201103 +# endif +# else +# define __cpp_thread_local 201103 +# endif +#endif + +#endif // BUTL_FT_LANG diff --git a/butl/ft/shared_mutex b/butl/ft/shared_mutex new file mode 100644 index 0000000..b4bab94 --- /dev/null +++ b/butl/ft/shared_mutex @@ -0,0 +1,42 @@ +// file : butl/ft/shared_mutex -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_FT_SHARED_MUTEX +#define BUTL_FT_SHARED_MUTEX + +#include // _LIBCPP_VERSION +#include + +// __cpp_lib_shared_mutex +// +#ifndef __cpp_lib_shared_mutex + // + // VC has it since 1900. + // +# if defined(_MSC_VER) +# if _MSC_VER >= 1900 +# define __cpp_lib_shared_mutex 201505 +# endif + // + // Clang's libc++ seems to have it for a while (but not before 1200) so we + // assume it's there from 1200. + // +# elif defined(_LIBCPP_VERSION) +# if _LIBCPP_VERSION >= 1200 +# define __cpp_lib_shared_mutex 201505 +# endif + // + // GCC libstdc++ has it since GCC 6 and it defines the feature test macro. + // We will also use this for any other runtime. + // +# endif +#endif + +// __cpp_lib_shared_mutex +// +#ifndef __cpp_lib_shared_timed_mutex +# define __cpp_lib_shared_timed_mutex 201402 +#endif + +#endif // BUTL_FT_SHARED_MUTEX diff --git a/butl/utility b/butl/utility index ac94171..208a840 100644 --- a/butl/utility +++ b/butl/utility @@ -6,15 +6,17 @@ #define BUTL_UTILITY #include -#include // ostream -#include // size_t -#include // move(), forward() -#include // strcmp(), strlen() -#include // exception, uncaught_exception(s)() +#include // ostream +#include // size_t +#include // move(), forward() +#include // strcmp(), strlen() +#include // uncaught_exceptions +#include // exception, uncaught_exception(s)() +#include // thread_local + //#include // hash #include -#include namespace butl { @@ -165,7 +167,7 @@ namespace butl return exception_guard (std::move (f)); } -#ifdef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifdef __cpp_lib_uncaught_exceptions template struct exception_guard { @@ -190,7 +192,7 @@ namespace butl // part of the exception stack unwindining. // extern -#ifdef BUTL_CXX11_THREAD_LOCAL +#ifdef __cpp_thread_local thread_local #else __thread diff --git a/butl/utility.cxx b/butl/utility.cxx index d971a3f..84c8a74 100644 --- a/butl/utility.cxx +++ b/butl/utility.cxx @@ -8,9 +8,9 @@ namespace butl { -#ifndef BUTL_CXX17_UNCAUGHT_EXCEPTIONS +#ifndef __cpp_lib_uncaught_exceptions -#ifdef BUTL_CXX11_THREAD_LOCAL +#ifdef __cpp_thread_local thread_local #else __thread -- cgit v1.1