From c30673fb7ebbf26133cb44ba36f2bb929be78b02 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 18 May 2019 12:59:08 +0200 Subject: [PATCH] Compiler version specific configuration support added --- CMakeLists.txt | 5 ++--- cmake/check_features.cmake | 30 ++++++++++++++++++++++++++++++ cmake/config.h.in | 25 +++++++++++++++++++++++++ conanfile.py | 4 +++- src/CMakeLists.txt | 13 ++++++++++--- src/include/units/bits/hacks.h | 5 +++++ 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 cmake/check_features.cmake create mode 100644 cmake/config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c0cebe..863addb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,16 +25,15 @@ project(units) # set path to custom cmake modules list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/cmake") # include common tools and workarounds -include(tools) +include(common/cmake/tools) # use Conan configuration if available conan_init(cmake) # compilation options and flags used in a project development process -include(compile_flags) +include(common/cmake/compile_flags) # add project code add_subdirectory(src) diff --git a/cmake/check_features.cmake b/cmake/check_features.cmake new file mode 100644 index 00000000..f0c66010 --- /dev/null +++ b/cmake/check_features.cmake @@ -0,0 +1,30 @@ +# The MIT License (MIT) +# +# Copyright (c) 2018 Mateusz Pusz +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +set(CMAKE_REQUIRED_FLAGS -std=c++2a) + +include(CheckTypeSize) + +set(CMAKE_EXTRA_INCLUDE_FILES type_traits) +check_type_size("std::type_identity" UNITS_HAS_STD_TYPE_IDENTITY LANGUAGE CXX) + +configure_file(../cmake/config.h.in include/units/bits/config.h) diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..90a14fa3 --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,25 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#cmakedefine UNITS_HAS_STD_TYPE_IDENTITY diff --git a/conanfile.py b/conanfile.py index c86ed588..f54fc631 100644 --- a/conanfile.py +++ b/conanfile.py @@ -85,4 +85,6 @@ class UnitsConan(ConanFile): self.cpp_info.includedirs = ['include'] def package_id(self): - self.info.header_only() + self.info.settings.clear() + self.info.settings.compiler = self.settings.compiler + self.info.settings.compiler.version = self.settings.compiler.version diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 423f7624..d0289ea7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,10 +29,13 @@ project(units ) # set path to custom cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") # include common tools and workarounds -include(tools) +include(common/cmake/tools) + +# check availability of C++20 features +include(check_features) # library definition add_library(units INTERFACE) @@ -59,7 +62,7 @@ target_link_libraries(units target_include_directories(units INTERFACE $ - $ + $ $ ) add_library(mp::units ALIAS units) @@ -75,6 +78,10 @@ install(DIRECTORY include/units DESTINATION include COMPONENT Devel ) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/units + DESTINATION include + COMPONENT Devel +) # generate configuration files and install the package configure_and_install(../cmake/common/cmake/simple_package-config.cmake.in mp SameMajorVersion) diff --git a/src/include/units/bits/hacks.h b/src/include/units/bits/hacks.h index a83800df..cfad810a 100644 --- a/src/include/units/bits/hacks.h +++ b/src/include/units/bits/hacks.h @@ -22,10 +22,13 @@ #pragma once +#include #include namespace std { +#ifndef UNITS_HAS_STD_TYPE_IDENTITY + // type_identity template struct type_identity { using type = T; }; @@ -33,6 +36,8 @@ namespace std { template using type_identity_t = typename type_identity::type; +#endif // UNITS_HAS_STD_TYPE_IDENTITY + // concepts using experimental::ranges::Same; using experimental::ranges::Integral;