From 625f452daaaf39fd6177e98890058db4556e5cc2 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 15 Mar 2021 21:11:26 +0100 Subject: [PATCH] build: libc++ support added --- conanfile.py | 2 +- example/CMakeLists.txt | 28 ++++++------ src/CMakeLists.txt | 29 +++++++++--- src/include/units/bits/external/hacks.h | 60 ++++++++++++++++--------- test/unit_test/static/CMakeLists.txt | 18 ++++++-- 5 files changed, 91 insertions(+), 46 deletions(-) diff --git a/conanfile.py b/conanfile.py index 87080e65..958edd9a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -103,7 +103,7 @@ class UnitsConan(ConanFile): # del self.options.build_docs def requirements(self): - if self.settings.compiler == "clang": + if self.settings.compiler == "clang" and self.settings.compiler.libcxx == "libc++": self.requires("range-v3/0.11.0") def build_requirements(self): diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a8f130f6..fdab19df 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -43,20 +43,20 @@ add_example(avg_speed) add_example(hello_units) add_example(total_energy) -add_executable(glide_computer - geographic.cpp geographic.h - glide_computer.cpp glide_computer.h - glide_computer_example.cpp -) -target_link_libraries(glide_computer PRIVATE mp-units::mp-units) +if(NOT UNITS_LIBCXX) + add_executable(glide_computer + geographic.cpp geographic.h + glide_computer.cpp glide_computer.h + glide_computer_example.cpp + ) + target_link_libraries(glide_computer PRIVATE mp-units::mp-units) -# TODO "atomic constraint should be a constant expression" error in std::invocable - -find_package(linear_algebra CONFIG REQUIRED) -add_example(linear_algebra) -target_link_libraries(linear_algebra - PRIVATE - linear_algebra::linear_algebra -) + find_package(linear_algebra CONFIG REQUIRED) + add_example(linear_algebra) + target_link_libraries(linear_algebra + PRIVATE + linear_algebra::linear_algebra + ) +endif() add_subdirectory(alternative_namespaces) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c73d7254..bb269aa0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -30,8 +30,21 @@ project(mp-units set(UNITS_DOWNCAST_MODE ON CACHE STRING "Select downcasting mode") set_property(CACHE UNITS_DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF) -# set path to custom cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") +# check if libc++ is being used +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(CHECK_START "Checking if libc++ is being used") + list(APPEND CMAKE_MESSAGE_INDENT " ") + + include(CheckSymbolExists) + check_symbol_exists(_LIBCPP_VERSION "ciso646" UNITS_LIBCXX) + + list(POP_BACK CMAKE_MESSAGE_INDENT) + if(UNITS_LIBCXX) + message(CHECK_PASS "found") + else() + message(CHECK_FAIL "not found") + endif() +endif() find_package(fmt CONFIG REQUIRED) find_package(gsl-lite CONFIG REQUIRED) @@ -51,11 +64,13 @@ target_include_directories(mp-units ) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - find_package(range-v3) - target_link_libraries(mp-units - INTERFACE - range-v3::range-v3 - ) + if(UNITS_LIBCXX) + find_package(range-v3) + target_link_libraries(mp-units + INTERFACE + range-v3::range-v3 + ) + endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(mp-units INTERFACE diff --git a/src/include/units/bits/external/hacks.h b/src/include/units/bits/external/hacks.h index e9fec31f..551e76d5 100644 --- a/src/include/units/bits/external/hacks.h +++ b/src/include/units/bits/external/hacks.h @@ -31,15 +31,24 @@ #define COMP_MSVC _MSC_VER #endif -#if defined(COMP_CLANG) && !defined(UNITS_LIBCXX) -#define UNITS_LIBCXX 0 +#if COMP_CLANG + +#include +#if _LIBCPP_VERSION +#define UNITS_LIBCXX _LIBCPP_VERSION #endif -#if COMP_CLANG && UNITS_LIBCXX +#endif + +#if COMP_CLANG == 12 && UNITS_LIBCXX #include #include #include +#include +#include +#include +#include #endif @@ -67,35 +76,46 @@ concept default_constructible = constructible_from; #elif COMP_CLANG && UNITS_LIBCXX // concepts -using concepts::three_way_comparable; -using concepts::three_way_comparable_with; -// using concepts::common_reference_with; using concepts::common_with; using concepts::constructible_from; using concepts::convertible_to; -// using concepts::default_constructible; +using concepts::copy_constructible; using concepts::derived_from; -// using concepts::equality_comparable; +using concepts::equality_comparable; using concepts::equality_comparable_with; -// // using concepts::floating_point; -// using concepts::integral; +using concepts::integral; +using concepts::move_constructible; using concepts::regular; -// using concepts::same_as; -// using concepts::totally_ordered; -// using concepts::totally_ordered_with; +using concepts::three_way_comparable; +using concepts::three_way_comparable_with; +using concepts::totally_ordered; using ranges::compare_three_way; -// namespace ranges { +namespace ranges { -// using ::ranges::forward_range; -// using ::ranges::range_value_t; +using ::ranges::begin; +using ::ranges::end; +using ::ranges::distance; -// } +using ::ranges::forward_range; +using ::ranges::input_range; +using ::ranges::range_value_t; -// // missing in Range-v3 -// template -// concept floating_point = std::is_floating_point_v; +using ::ranges::lower_bound; +using ::ranges::transform; + +} + +// missing in Range-v3 +template +concept floating_point = std::is_floating_point_v; + +template +concept default_initializable = + std::constructible_from && + requires { T{}; } && + requires { ::new (static_cast(nullptr)) T; }; template concept invocable = diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 2afd85bc..a9d0c5ac 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -24,9 +24,13 @@ cmake_minimum_required(VERSION 3.2) add_library(unit_tests_static_truncating quantity_test.cpp - quantity_kind_test.cpp - quantity_point_kind_test.cpp ) +if(NOT UNITS_LIBCXX) + target_sources(unit_tests_static_truncating PRIVATE + quantity_kind_test.cpp + quantity_point_kind_test.cpp + ) +endif() target_link_libraries(unit_tests_static_truncating PRIVATE mp-units::mp-units @@ -41,7 +45,6 @@ add_library(unit_tests_static chrono_test.cpp concepts_test.cpp custom_rep_test_min_expl.cpp - custom_rep_test_min_impl.cpp custom_unit_test.cpp data_test.cpp dimension_op_test.cpp @@ -50,7 +53,6 @@ add_library(unit_tests_static fps_test.cpp kind_test.cpp math_test.cpp - quantity_point_test.cpp ratio_test.cpp si_test.cpp si_cgs_test.cpp @@ -61,6 +63,14 @@ add_library(unit_tests_static unit_test.cpp us_test.cpp ) + +if(NOT UNITS_LIBCXX) + target_sources(unit_tests_static PRIVATE + custom_rep_test_min_impl.cpp + quantity_point_test.cpp + ) +endif() + target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating