From b27a42207633beda9a9d02036c0ff8d941ebf882 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 17 Dec 2019 21:10:35 +0100 Subject: [PATCH] Preeliminary clang support added --- conanfile.py | 12 ++++---- src/CMakeLists.txt | 15 +++++++--- src/include/units/bits/external/hacks.h | 37 +++++++++++++++++-------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/conanfile.py b/conanfile.py index fba6d3c0..d81d33e7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -59,10 +59,12 @@ class UnitsConan(ConanFile): return tools.get_env("CONAN_RUN_TESTS", False) def configure(self): - if self.settings.compiler != "gcc": - raise ConanInvalidConfiguration("Library works only with gcc") - if Version(self.settings.compiler.version) < "9": - raise ConanInvalidConfiguration("Library requires at least gcc-9") + if self.settings.compiler != "gcc": # and self.settings.compiler != "clang": + raise ConanInvalidConfiguration("Library works only with gcc") # and clang") + if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "9": + raise ConanInvalidConfiguration("Library requires at least g++-9") + if self.settings.compiler == "clang" and Version(self.settings.compiler.version) < "11": + raise ConanInvalidConfiguration("Library requires at least clang++-11") if self.settings.compiler.cppstd not in ["20", "gnu20"]: raise ConanInvalidConfiguration("Library requires at least C++20 support") @@ -75,7 +77,7 @@ class UnitsConan(ConanFile): return cmake def requirements(self): - if Version(self.settings.compiler.version) < "10": + if self.settings.compiler == "clang" or Version(self.settings.compiler.version) < "10": self.requires("range-v3/0.10.0@ericniebler/stable") def build(self): diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f0d6720..1c0e8430 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,12 +60,18 @@ target_include_directories(units $ $ ) -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - target_compile_options(units +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_link_libraries(units INTERFACE - -Wno-literal-suffix - -Wno-non-template-friend + CONAN_PKG::range-v3 ) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(units + INTERFACE + -Wno-literal-suffix + -Wno-non-template-friend + ) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) target_compile_options(units INTERFACE @@ -77,6 +83,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) ) endif() endif() + add_library(mp::units ALIAS units) # installation info diff --git a/src/include/units/bits/external/hacks.h b/src/include/units/bits/external/hacks.h index c1bb861a..3539ae33 100644 --- a/src/include/units/bits/external/hacks.h +++ b/src/include/units/bits/external/hacks.h @@ -24,6 +24,13 @@ #include +#if __clang__ +#define COMP_CLANG __clang_major__ +#elif __GNUC__ +#define COMP_GCC __GNUC__ +#define COMP_GCC_MINOR __GNUC_MINOR__ +#endif + #ifdef NDEBUG #define Expects(cond) (void)(cond); #else @@ -31,23 +38,36 @@ #define Expects(cond) assert(cond); #endif -#if __GNUC__ < 10 +#if COMP_GCC >= 10 || COMP_CLANG >= 11 -#include -#define AUTO -#define SAME_AS(T) T +#include #else -#include +#include + +#endif + +#if COMP_GCC >= 10 || COMP_CLANG >= 11 + #define AUTO auto #define SAME_AS(T) std::same_as +#else + +#define AUTO +#define SAME_AS(T) T + #endif namespace std { -#if __GNUC__ < 10 +#if COMP_GCC >= 10 + + template + concept default_constructible = constructible_from; + +#else // concepts using concepts::common_reference_with; @@ -71,11 +91,6 @@ namespace std { template concept regular_invocable = invocable; -#else - -template -concept default_constructible = constructible_from; - #endif } // namespace std