Skip to content

Commit

Permalink
ensure C++ standard consistency
Browse files Browse the repository at this point in the history
revert #7443

it's almost impossible to predict if those headers are available. abseil has a mechanism to detect these headers, trust it. Since we are trying very hard to inject at build time the default C++ standard of the compiler or the one given in profile, it should be fine.
  • Loading branch information
SpaceIm committed Jan 24, 2022
1 parent e5c4fb0 commit f336e83
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion recipes/abseil/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.8)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
Expand Down
6 changes: 6 additions & 0 deletions recipes/abseil/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ patches:
"20210324.2":
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-cpp-standard-20210324.patch"
base_path: "source_subfolder"
"20200923.3":
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-cpp-standard-20200923.patch"
base_path: "source_subfolder"
"20200225.3":
- patch_file: "patches/0001-cmake-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-missing-numeric_limits.h.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-cpp-standard-20200225.patch"
base_path: "source_subfolder"
35 changes: 2 additions & 33 deletions recipes/abseil/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
required_conan_version = ">=1.43.0"


class AbseilRecipe(ConanFile):
class AbseilConan(ConanFile):
name = "abseil"
description = "Abseil Common Libraries (C++) from Google"
topics = ("algorithm", "container", "google", "common", "utility")
Expand Down Expand Up @@ -65,48 +65,17 @@ def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
if not tools.valid_min_cppstd(self, 11):
self._cmake.definitions["CMAKE_CXX_STANDARD"] = 11
self._cmake.definitions["ABSL_ENABLE_INSTALL"] = True
self._cmake.definitions["ABSL_PROPAGATE_CXX_STD"] = True
self._cmake.definitions["BUILD_TESTING"] = False
if tools.cross_building(self):
self._cmake.definitions["CONAN_ABSEIL_SYSTEM_PROCESSOR"] = str(self.settings.arch)
self._cmake.configure()
return self._cmake

@property
def _abseil_abi_macros(self):
return [
"ABSL_OPTION_USE_STD_ANY",
"ABSL_OPTION_USE_STD_OPTIONAL",
"ABSL_OPTION_USE_STD_STRING_VIEW",
"ABSL_OPTION_USE_STD_VARIANT",
]

def _abseil_abi_config(self):
"""Determine the Abseil ABI for polyfills (absl::any, absl::optional, absl::string_view, and absl::variant)"""
if self.settings.compiler.get_safe("cppstd"):
if self.settings.compiler.get_safe("cppstd") >= "17":
return "1"
return "0"
# As-of 2021-09-27 only GCC-11 defaults to C++17.
if (
self.settings.compiler == "gcc"
and tools.Version(self.settings.compiler.version) >= "11"
):
return "1"
return "0"

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
absl_option = self._abseil_abi_config()
for macro in self._abseil_abi_macros:
tools.replace_in_file(
os.path.join(self._source_subfolder, "absl", "base", "options.h"),
"#define {} 2".format(macro),
"#define {} {}".format(macro, absl_option),
)
cmake = self._configure_cmake()
cmake.build()

Expand Down
15 changes: 15 additions & 0 deletions recipes/abseil/all/patches/0004-cpp-standard-20200225.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -204,8 +204,12 @@ function(absl_cc_library)
endif()

# INTERFACE libraries can't have the CXX_STANDARD property set
+ if(ABSL_PROPAGATE_CXX_STD)
+ target_compile_features(${_NAME} PUBLIC cxx_std_11)
+ else()
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
+ endif()

# When being installed, we lose the absl_ prefix. We want to put it back
# to have properly named lib files. This is a no-op when we are not being
15 changes: 15 additions & 0 deletions recipes/abseil/all/patches/0004-cpp-standard-20200923.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -206,8 +206,12 @@ function(absl_cc_library)
endif()

# INTERFACE libraries can't have the CXX_STANDARD property set
+ if(ABSL_PROPAGATE_CXX_STD)
+ target_compile_features(${_NAME} PUBLIC cxx_std_11)
+ else()
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
+ endif()

# When being installed, we lose the absl_ prefix. We want to put it back
# to have properly named lib files. This is a no-op when we are not being
15 changes: 15 additions & 0 deletions recipes/abseil/all/patches/0004-cpp-standard-20210324.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -254,8 +254,12 @@ Cflags: -I\${includedir}${PC_CFLAGS}\n")
endif()

# INTERFACE libraries can't have the CXX_STANDARD property set
+ if(ABSL_PROPAGATE_CXX_STD)
+ target_compile_features(${_NAME} PUBLIC cxx_std_11)
+ else()
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD ${ABSL_CXX_STANDARD})
set_property(TARGET ${_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
+ endif()

# When being installed, we lose the absl_ prefix. We want to put it back
# to have properly named lib files. This is a no-op when we are not being

0 comments on commit f336e83

Please sign in to comment.