diff --git a/recipes/abseil/all/conanfile.py b/recipes/abseil/all/conanfile.py index ff8d10ce2247b..29c0102ea96b7 100644 --- a/recipes/abseil/all/conanfile.py +++ b/recipes/abseil/all/conanfile.py @@ -56,9 +56,39 @@ def _configure_cmake(self): 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()