From 771a4000079a36c99ab8d1bc9bd2de12187b0961 Mon Sep 17 00:00:00 2001 From: Frank Dischner Date: Wed, 26 Jan 2022 18:18:51 -0600 Subject: [PATCH] build: add support for AppleClang compiler --- CMakeLists.txt | 2 +- conanfile.py | 13 +++++++++++-- src/cmake/CheckLibcxxInUse.cmake | 2 +- src/core/CMakeLists.txt | 2 +- src/mp-unitsConfig.cmake | 4 ++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e3ac12c..21bf11b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ if(${projectPrefix}IWYU) MAX_LINE_LENGTH 120 NO_COMMENTS ) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(${projectPrefix}AS_SYSTEM_HEADERS ON) endif() endif() diff --git a/conanfile.py b/conanfile.py index 7bddf441..2074d1aa 100644 --- a/conanfile.py +++ b/conanfile.py @@ -70,6 +70,12 @@ class UnitsConan(ConanFile): (compiler == "msvc" and (version == "19.3" or version >= "19.30") and compiler.cppstd == 23) return not std_support + @property + def _use_range_v3(self): + compiler = self.settings.compiler + version = Version(self.settings.compiler.version) + return ("clang" in compiler and compiler.libcxx == "libc++" and version < "14.0") + def set_version(self): content = tools.load(os.path.join(self.recipe_folder, "src/CMakeLists.txt")) version = re.search(r"project\([^\)]+VERSION (\d+\.\d+\.\d+)[^\)]*\)", content).group(1) @@ -81,7 +87,7 @@ class UnitsConan(ConanFile): if self._use_libfmt: self.requires("fmt/8.0.1") - if compiler == "clang" and compiler.libcxx == "libc++" and version < "14.0": + if self._use_range_v3: self.requires("range-v3/0.11.0") def build_requirements(self): @@ -100,6 +106,9 @@ class UnitsConan(ConanFile): elif compiler == "clang": if version < "12": raise ConanInvalidConfiguration("mp-units requires at least clang++-12") + elif compiler == "apple-clang": + if version < "13": + raise ConanInvalidConfiguration("mp-units requires at least AppleClang 13") elif compiler == "Visual Studio": if version < "16": raise ConanInvalidConfiguration("mp-units requires at least Visual Studio 16.9") @@ -148,7 +157,7 @@ class UnitsConan(ConanFile): self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"] if compiler == "Visual Studio": self.cpp_info.components["core"].cxxflags = ["/utf-8"] - elif compiler == "clang" and compiler.libcxx == "libc++": + if self._use_range_v3: self.cpp_info.components["core"].requires.append("range-v3::range-v3") # rest diff --git a/src/cmake/CheckLibcxxInUse.cmake b/src/cmake/CheckLibcxxInUse.cmake index 4e122acf..7335da5c 100644 --- a/src/cmake/CheckLibcxxInUse.cmake +++ b/src/cmake/CheckLibcxxInUse.cmake @@ -23,7 +23,7 @@ cmake_minimum_required(VERSION 3.15) function(check_libcxx_in_use variable) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") message(CHECK_START "Checking if libc++ is being used") list(APPEND CMAKE_MESSAGE_INDENT " ") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 25730a63..31900e53 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -44,7 +44,7 @@ target_include_directories(mp-units-core ${unitsAsSystem} INTERFACE $ ) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(${projectPrefix}LIBCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14") find_package(range-v3 CONFIG REQUIRED) target_link_libraries(mp-units-core INTERFACE range-v3::range-v3) diff --git a/src/mp-unitsConfig.cmake b/src/mp-unitsConfig.cmake index afe3f7a1..8b63a787 100644 --- a/src/mp-unitsConfig.cmake +++ b/src/mp-unitsConfig.cmake @@ -21,7 +21,7 @@ # SOFTWARE. function(__check_libcxx_in_use variable) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") message(CHECK_START "Checking if libc++ is being used") list(APPEND CMAKE_MESSAGE_INDENT " ") @@ -43,7 +43,7 @@ find_dependency(fmt) find_dependency(gsl-lite) # add range-v3 dependency only for clang + libc++ -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") __check_libcxx_in_use(__units_libcxx) if(__units_libcxx AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14") find_dependency(range-v3)