add abseil recipe

This commit is contained in:
aleksandr.vodyanov
2024-11-14 13:52:51 +03:00
commit 1853b851ff
17 changed files with 742 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
#cmakedefine01 USE_STD_STRING_VIEW
#cmakedefine01 USE_STD_ANY
#cmakedefine01 USE_STD_OPTIONAL
#cmakedefine01 USE_STD_VARIANT

View File

@@ -0,0 +1,44 @@
get_target_property(ABSL_INCLUDES absl::config INTERFACE_INCLUDE_DIRECTORIES)
set(CMAKE_REQUIRED_INCLUDES ${ABSL_INCLUDES})
check_cxx_source_compiles("
#include \"absl/base/config.h\"
#if defined(ABSL_HAVE_STD_STRING_VIEW) && ABSL_HAVE_STD_STRING_VIEW == 1
int main() {}
#else
#error \"no std::string_view\"
#endif
"
USE_STD_STRING_VIEW)
check_cxx_source_compiles("
#include \"absl/base/config.h\"
#if defined(ABSL_HAVE_STD_ANY) && ABSL_HAVE_STD_ANY == 1
int main() {}
#else
#error \"no std::any\"
#endif
"
USE_STD_ANY)
check_cxx_source_compiles("
#include \"absl/base/config.h\"
#if defined(ABSL_HAVE_STD_OPTIONAL) && ABSL_HAVE_STD_OPTIONAL == 1
int main() {}
#else
#error \"no std::optional\"
#endif
"
USE_STD_OPTIONAL)
check_cxx_source_compiles("
#include \"absl/base/config.h\"
#if defined(ABSL_HAVE_STD_VARIANT) && ABSL_HAVE_STD_VARIANT == 1
int main() {}
#else
#error \"no std::variant\"
#endif
"
USE_STD_VARIANT)
configure_file(${CMAKE_CURRENT_LIST_DIR}/abi.h.in ${PROJECT_BINARY_DIR}/abi.h)

View File

@@ -0,0 +1,79 @@
sources:
"20240722.0":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20240722.0"
"20240116.2":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20240116.2"
"20240116.1":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20240116.1"
"20230802.1":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20230802.1"
"20230125.3":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20230125.3"
"20220623.1":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20220623.1"
"20211102.0":
url: "ssh://git@git.avroid.tech:2222/Mirrors/abseil-cpp"
branch: "20211102.0"
patches:
"20240722.0":
- patch_file: "patches/0003-absl-string-libm-20240116.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/issues/1100"
"20240116.2":
- patch_file: "patches/0003-absl-string-libm-20240116.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/issues/1100"
- patch_file: "patches/20240116.1-0001-fix-filesystem-include.patch"
patch_description: "Fix GCC 7 including <filesystem> in C++17 mode when it is not available (until GCC 8)"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/commit/bb83aceacb554e79e7cd2404856f0be30bd00303"
- patch_file: "patches/0004-test-allocator-testonly.patch"
patch_description: "Do not build test_allocator target when tests are disabled"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/commit/779a3565ac6c5b69dd1ab9183e500a27633117d5"
"20240116.1":
- patch_file: "patches/0003-absl-string-libm-20240116.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/issues/1100"
- patch_file: "patches/20240116.1-0001-fix-filesystem-include.patch"
patch_description: "Fix GCC 7 including <filesystem> in C++17 mode when it is not available (until GCC 8)"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/commit/bb83aceacb554e79e7cd2404856f0be30bd00303"
- patch_file: "patches/0004-test-allocator-testonly.patch"
patch_description: "Do not build test_allocator target when tests are disabled"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/commit/779a3565ac6c5b69dd1ab9183e500a27633117d5"
"20230802.1":
- patch_file: "patches/0003-absl-string-libm-20230802.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/issues/1100"
- patch_file: "patches/20230802.1-0001-fix-mingw.patch"
patch_description: "Fix build with MinGW"
patch_type: "portability"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/commit/2f77684e8dc473a48dbc19167ffe69c40ce8ada4"
"20230125.3":
- patch_file: "patches/0003-absl-string-libm.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
"20220623.1":
- patch_file: "patches/0003-absl-string-libm.patch"
patch_description: "link libm to absl string"
patch_type: "portability"
- patch_file: "patches/0005-has-unique-object-representations.patch"
patch_description: "Workaround bug in GCC 7.2"
patch_source: "https://git.avroid.tech/Mirrors/abseil-cpp/pull/1250"
patch_type: "portability"
"20211102.0":
- patch_file: "patches/0003-absl-string-libm.patch"
patch_description: "link libm to absl string"
patch_type: "portability"

View File

@@ -0,0 +1,271 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import export_conandata_patches, apply_conandata_patches, copy, get, load, replace_in_file, rmdir, save
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
import json
import os
import re
import textwrap
required_conan_version = ">=1.53.0"
class AbseilConan(ConanFile):
name = "abseil"
description = "Abseil Common Libraries (C++) from Google"
topics = ("algorithm", "container", "google", "common", "utility")
homepage = "https://github.com/abseil/abseil-cpp"
url = "https://github.com/conan-io/conan-center-index"
license = "Apache-2.0"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
short_paths = True
@property
def _min_cppstd(self):
return "11" if Version(self.version) < "20230125.0" else "14"
@property
def _compilers_minimum_version(self):
return {
"14": {
"gcc": "6",
"clang": "5",
"apple-clang": "10",
"Visual Studio": "15",
"msvc": "191",
},
}.get(self._min_cppstd, {})
def export_sources(self):
copy(self, "abi_trick/*", self.recipe_folder, self.export_sources_folder)
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)
if self.options.shared and is_msvc(self) and Version(self.version) < "20230802.1":
# upstream tries its best to export symbols, but it's broken for the moment
raise ConanInvalidConfiguration(f"{self.ref} shared not availabe for Visual Studio, please use version 20230802.1 or newer")
def build_requirements(self):
# https://github.com/abseil/abseil-cpp/blob/20240722.0/CMakeLists.txt#L19
if Version(self.version) >= "20240722.0":
self.tool_requires("cmake/[>=3.16 <4]")
def layout(self):
cmake_layout(self, src_folder="src")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["ABSL_ENABLE_INSTALL"] = True
tc.variables["ABSL_PROPAGATE_CXX_STD"] = True
tc.variables["BUILD_TESTING"] = False
# We force CMP0067 policy to NEW for our abi trick in _patch_sources()
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0067"] = "NEW"
if is_msvc(self):
# see https://github.com/abseil/abseil-cpp/issues/649
tc.preprocessor_definitions["_HAS_DEPRECATED_RESULT_OF"] = 1
tc.generate()
def _patch_sources(self):
apply_conandata_patches(self)
# In case of cross-build, set CMAKE_SYSTEM_PROCESSOR if not set by toolchain or user
if cross_building(self):
toolchain_file = os.path.join(self.generators_folder, "conan_toolchain.cmake")
cmake_system_processor_block = textwrap.dedent("""
if(NOT CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR {})
endif()
""".format(str(self.settings.arch)))
save(self, toolchain_file, cmake_system_processor_block, append=True)
# Trick to capture ABI
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
abi_trick_block = textwrap.dedent("""\
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../abi_trick")
include(conan_abi_test)
""")
save(self, cmakelists, abi_trick_block, append=True)
def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
abi_file = _ABIFile(self, os.path.join(self.build_folder, "abi.h"))
abi_file.replace_in_options_file(os.path.join(self.source_folder, "absl", "base", "options.h"))
cmake.build()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
# Load components hierarchy before removing CMake files generated by abseil installation
cmake_folder = os.path.join(self.package_folder, "lib", "cmake")
absl_targets_file = os.path.join(cmake_folder, "absl", "abslTargets.cmake")
components = self._load_components_from_cmake_target_file(absl_targets_file)
rmdir(self, cmake_folder)
# Create a json helper file in order to populate package_info() at consume time
self._create_components_file(self._components_helper_filepath, components)
# Create a build-module that will propagate the required cxx_std to consumers of this recipe's targets
# TODO: Revisit with feedback from https://github.com/conan-io/conan/issues/10281
self._create_cxx_std_module_file(self._cxx_std_module_filepath, components)
def _load_components_from_cmake_target_file(self, absl_target_file_path):
components = {}
abs_target_content = load(self, absl_target_file_path)
# Replace the line endings to support building with MSys2 on Windows
abs_target_content = abs_target_content.replace("\r\n", "\n")
cmake_functions = re.findall(r"(?P<func>add_library|set_target_properties)[\n|\s]*\([\n|\s]*(?P<args>[^)]*)\)", abs_target_content)
for (cmake_function_name, cmake_function_args) in cmake_functions:
cmake_function_args = re.split(r"[\s|\n]+", cmake_function_args, maxsplit=2)
cmake_imported_target_name = cmake_function_args[0]
cmake_target_nonamespace = cmake_imported_target_name.replace("absl::", "")
potential_lib_name = "absl_" + cmake_target_nonamespace
components.setdefault(potential_lib_name, {"cmake_target": cmake_target_nonamespace})
if cmake_function_name == "add_library":
cmake_imported_target_type = cmake_function_args[1]
if cmake_imported_target_type in ["STATIC", "SHARED"]:
components[potential_lib_name]["libs"] = [potential_lib_name] if cmake_target_nonamespace != "abseil_dll" else ['abseil_dll']
elif cmake_function_name == "set_target_properties":
target_properties = re.findall(r"(?P<property>INTERFACE_COMPILE_DEFINITIONS|INTERFACE_INCLUDE_DIRECTORIES|INTERFACE_LINK_LIBRARIES)[\n|\s]+(?P<values>.+)", cmake_function_args[2])
for target_property in target_properties:
property_type = target_property[0]
if property_type == "INTERFACE_LINK_LIBRARIES":
values_list = target_property[1].replace('"', "").split(";")
for dependency in values_list:
if dependency.startswith("absl::"): # abseil targets
components[potential_lib_name].setdefault("requires", []).append(dependency.replace("absl::", "absl_"))
else: # system libs or frameworks
if self.settings.os in ["Linux", "FreeBSD"]:
if dependency == "Threads::Threads":
components[potential_lib_name].setdefault("system_libs", []).append("pthread")
elif "-lm" in dependency:
components[potential_lib_name].setdefault("system_libs", []).append("m")
elif "-lrt" in dependency:
components[potential_lib_name].setdefault("system_libs", []).append("rt")
elif self.settings.os == "Windows":
for system_lib in ["bcrypt", "advapi32", "dbghelp"]:
if system_lib in dependency:
components[potential_lib_name].setdefault("system_libs", []).append(system_lib)
elif is_apple_os(self):
for framework in ["CoreFoundation"]:
if framework in dependency:
components[potential_lib_name].setdefault("frameworks", []).append(framework)
elif property_type == "INTERFACE_COMPILE_DEFINITIONS":
values_list = target_property[1].replace('"', "").split(";")
for definition in values_list:
if definition == r"\$<\$<PLATFORM_ID:AIX>:_LINUX_SOURCE_COMPAT>":
if self.settings.os == "AIX":
components[potential_lib_name].setdefault("defines", []).append("_LINUX_SOURCE_COMPAT")
else:
components[potential_lib_name].setdefault("defines", []).append(definition)
return components
def _create_components_file(self, output_file, components):
content = json.dumps(components, indent=4)
save(self, output_file, content)
@property
def _components_helper_filepath(self):
return os.path.join(self.package_folder, "lib", "components.json")
def _create_cxx_std_module_file(self, output_file, components):
content = ""
cxx_std_required = _ABIFile(self, os.path.join(self.build_folder, "abi.h")).cxx_std()
for _, values in components.items():
cmake_target = values["cmake_target"]
content += f"target_compile_features(absl::{cmake_target} INTERFACE cxx_std_{cxx_std_required})\n"
save(self, output_file, content)
@property
def _cxx_std_module_filepath(self):
return os.path.join(self.package_folder, "lib", "cmake", "conan_trick", "cxx_std.cmake")
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "absl")
components_json_file = load(self, self._components_helper_filepath)
abseil_components = json.loads(components_json_file)
for pkgconfig_name, values in abseil_components.items():
cmake_target = values["cmake_target"]
self.cpp_info.components[pkgconfig_name].set_property("cmake_target_name", "absl::{}".format(cmake_target))
self.cpp_info.components[pkgconfig_name].set_property("pkg_config_name", pkgconfig_name)
self.cpp_info.components[pkgconfig_name].libs = values.get("libs", [])
self.cpp_info.components[pkgconfig_name].defines = values.get("defines", [])
self.cpp_info.components[pkgconfig_name].system_libs = values.get("system_libs", [])
self.cpp_info.components[pkgconfig_name].frameworks = values.get("frameworks", [])
self.cpp_info.components[pkgconfig_name].requires = values.get("requires", [])
self.cpp_info.components[pkgconfig_name].names["cmake_find_package"] = cmake_target
self.cpp_info.components[pkgconfig_name].names["cmake_find_package_multi"] = cmake_target
self.cpp_info.names["cmake_find_package"] = "absl"
self.cpp_info.names["cmake_find_package_multi"] = "absl"
self.cpp_info.set_property("cmake_build_modules", [self._cxx_std_module_filepath])
self.cpp_info.components["absl_config"].build_modules["cmake_find_package"] = [self._cxx_std_module_filepath]
self.cpp_info.components["absl_config"].build_modules["cmake_find_package_multi"] = [self._cxx_std_module_filepath]
class _ABIFile:
abi = {}
def __init__(self, conanfile, filepath):
self.conanfile = conanfile
abi_h = load(self.conanfile, filepath)
for line in abi_h.splitlines():
if line.startswith("#define"):
tokens = line.split()
if len(tokens) == 3:
self.abi[tokens[1]] = tokens[2]
def replace_in_options_file(self, options_filepath):
for name, value in self.abi.items():
replace_in_file(self.conanfile, options_filepath,
"#define ABSL_OPTION_{} 2".format(name),
"#define ABSL_OPTION_{} {}".format(name, value))
def cxx_std(self):
return 17 if any([v == "1" for k, v in self.abi.items()]) else 11

View File

@@ -0,0 +1,15 @@
--- a/absl/strings/CMakeLists.txt
+++ b/absl/strings/CMakeLists.txt
@@ -31,9 +31,12 @@
PUBLIC
)
+find_library(LIBM m)
absl_cc_library(
NAME
strings
+ LINKOPTS
+ $<$<BOOL:${LIBM}>:-lm>
HDRS
"ascii.h"
"charconv.h"

View File

@@ -0,0 +1,15 @@
--- a/absl/strings/CMakeLists.txt
+++ b/absl/strings/CMakeLists.txt
@@ -32,9 +32,12 @@
PUBLIC
)
+find_library(LIBM m)
absl_cc_library(
NAME
strings
+ LINKOPTS
+ $<$<BOOL:${LIBM}>:-lm>
HDRS
"ascii.h"
"charconv.h"

View File

@@ -0,0 +1,15 @@
--- a/absl/strings/CMakeLists.txt
+++ b/absl/strings/CMakeLists.txt
@@ -14,9 +14,12 @@
# limitations under the License.
#
+find_library(LIBM m)
absl_cc_library(
NAME
strings
+ LINKOPTS
+ $<$<BOOL:${LIBM}>:-lm>
HDRS
"ascii.h"
"charconv.h"

View File

@@ -0,0 +1,10 @@
--- a/absl/container/CMakeLists.txt
+++ b/absl/container/CMakeLists.txt
@@ -213,6 +213,7 @@ absl_cc_library(
DEPS
absl::config
GTest::gmock
+ TESTONLY
)
absl_cc_test(

View File

@@ -0,0 +1,11 @@
--- a/absl/hash/internal/hash.h 2022-06-24 06:22:47.000000000 +1200
+++ b/absl/hash/internal/hash.h 2022-07-28 17:00:02.241173356 +1200
@@ -444,7 +444,7 @@
// On other platforms, we assume that pointers-to-members do not have
// padding.
#ifdef __cpp_lib_has_unique_object_representations
- static_assert(std::has_unique_object_representations_v<T C::*>);
+ static_assert(std::has_unique_object_representations<T C::*>::value);
#endif // __cpp_lib_has_unique_object_representations
return n;
#endif

View File

@@ -0,0 +1,40 @@
--- a/absl/synchronization/internal/pthread_waiter.h
+++ b/absl/synchronization/internal/pthread_waiter.h
@@ -16,7 +16,7 @@
#ifndef ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
#define ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__MINGW32__)
#include <pthread.h>
#include "absl/base/config.h"
@@ -55,6 +55,6 @@ class PthreadWaiter : public WaiterCrtp<PthreadWaiter> {
ABSL_NAMESPACE_END
} // namespace absl
-#endif // ndef _WIN32
+#endif // !defined(_WIN32) && !defined(__MINGW32__)
#endif // ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
--- a/absl/synchronization/internal/win32_waiter.h
+++ b/absl/synchronization/internal/win32_waiter.h
@@ -20,7 +20,8 @@
#include <sdkddkver.h>
#endif
-#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#if defined(_WIN32) && !defined(__MINGW32__) && \
+ _WIN32_WINNT >= _WIN32_WINNT_VISTA
#include "absl/base/config.h"
#include "absl/synchronization/internal/kernel_timeout.h"
@@ -65,6 +66,7 @@ class Win32Waiter : public WaiterCrtp<Win32Waiter> {
ABSL_NAMESPACE_END
} // namespace absl
-#endif // defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA
+#endif // defined(_WIN32) && !defined(__MINGW32__) &&
+ // _WIN32_WINNT >= _WIN32_WINNT_VISTA
#endif // ABSL_SYNCHRONIZATION_INTERNAL_WIN32_WAITER_H_

View File

@@ -0,0 +1,53 @@
From bb83aceacb554e79e7cd2404856f0be30bd00303 Mon Sep 17 00:00:00 2001
From: Derek Mauro <dmauro@google.com>
Date: Tue, 12 Mar 2024 08:33:40 -0700
Subject: [PATCH] Fix GCC7 C++17 build
GCC did not support <filesystem> until GCC8.
Fixes #1635
PiperOrigin-RevId: 615051227
Change-Id: If7cd5802ead40805b1ff1c3bdfc10ba6d2858ef0
---
absl/hash/hash_test.cc | 2 +-
absl/hash/internal/hash.h | 12 ++++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index f4a94f9129f..b7d89b01807 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -24,6 +24,15 @@
#include <TargetConditionals.h>
#endif
+#include "absl/base/config.h"
+
+// For feature testing and determining which headers can be included.
+#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L
+#include <version>
+#else
+#include <ciso646>
+#endif
+
#include <algorithm>
#include <array>
#include <bitset>
@@ -47,7 +56,6 @@
#include <utility>
#include <vector>
-#include "absl/base/config.h"
#include "absl/base/internal/unaligned_access.h"
#include "absl/base/port.h"
#include "absl/container/fixed_array.h"
@@ -61,7 +69,7 @@
#include "absl/types/variant.h"
#include "absl/utility/utility.h"
-#if ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
+#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && \
!defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
#include <filesystem> // NOLINT
#endif

View File

@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)
find_package(absl REQUIRED CONFIG)
# Test components
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
# Abseil now requires at least C++14 since 20230125.0
if(absl_VERSION VERSION_LESS "20230125.0")
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
endif()
if(cxx_std_14 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
add_executable(${PROJECT_NAME}_14 test_package.cpp)
target_link_libraries(${PROJECT_NAME}_14 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
target_compile_features(${PROJECT_NAME}_14 PRIVATE cxx_std_14)
endif()
if(cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
add_executable(${PROJECT_NAME}_17 test_package.cpp)
target_link_libraries(${PROJECT_NAME}_17 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
target_compile_features(${PROJECT_NAME}_17 PRIVATE cxx_std_17)
endif()
# old abseil used std::result_of (which was removed in C++20) https://github.com/abseil/abseil-cpp/issues/649
if(CXX20_SUPPORTED)
if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
add_executable(${PROJECT_NAME}_20 test_package.cpp)
target_link_libraries(${PROJECT_NAME}_20 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
target_compile_features(${PROJECT_NAME}_20 PRIVATE cxx_std_20)
endif()
if(cxx_std_23 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
add_executable(${PROJECT_NAME}_23 test_package.cpp)
target_link_libraries(${PROJECT_NAME}_23 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
target_compile_features(${PROJECT_NAME}_23 PRIVATE cxx_std_23)
endif()
endif()
# Test also (unofficial) global target
add_executable(${PROJECT_NAME}_global test_package.cpp)
if(TARGET abseil::abseil)
target_link_libraries(${PROJECT_NAME}_global PRIVATE abseil::abseil)
else()
target_link_libraries(${PROJECT_NAME}_global PRIVATE absl::absl)
endif()
# Abseil now requires at least C++14 since 20230125.0
if(absl_VERSION VERSION_LESS "20230125.0")
target_compile_features(${PROJECT_NAME}_global PRIVATE cxx_std_11)
else()
target_compile_features(${PROJECT_NAME}_global PRIVATE cxx_std_14)
endif()

View File

@@ -0,0 +1,33 @@
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
def requirements(self):
self.requires(self.tested_reference_str)
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["CXX20_SUPPORTED"] = Version(self.dependencies["abseil"].ref.version) > "20210324.2"
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(f"{bin_path} -s", env="conanrun")
bin_global_path = os.path.join(self.cpp.build.bindirs[0], "test_package_global")
self.run(f"{bin_global_path} -s", env="conanrun")

View File

@@ -0,0 +1,56 @@
#include <string>
#include <utility>
#include <iostream>
#include <vector>
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/numeric/int128.h"
#include "absl/time/time.h"
#include "absl/types/variant.h"
int main()
{
absl::flat_hash_set<std::string> set1;
absl::flat_hash_map<int, std::string> map1;
absl::flat_hash_set<std::string> set2 = {
{"huey"},
{"dewey"},
{"louie"},
};
absl::flat_hash_map<int, std::string> map2 = {
{1, "huey"},
{2, "dewey"},
{3, "louie"},
};
absl::flat_hash_set<std::string> set3(set2);
absl::flat_hash_map<int, std::string> map3(map2);
absl::flat_hash_set<std::string> set4;
set4 = set3;
absl::flat_hash_map<int, std::string> map4;
map4 = map3;
absl::flat_hash_set<std::string> set5(std::move(set4));
absl::flat_hash_map<int, std::string> map5(std::move(map4));
absl::flat_hash_set<std::string> set6;
set6 = std::move(set5);
absl::flat_hash_map<int, std::string> map6;
map6 = std::move(map5);
const absl::uint128 big = absl::Uint128Max();
std::cout << absl::StrCat("Arg ", "foo", "\n");
std::vector<std::string> v = absl::StrSplit("a,b,,c", ',');
absl::Time t1 = absl::Now();
absl::Time t2 = absl::Time();
absl::Time t3 = absl::UnixEpoch();
absl::variant<int> v1 = absl::variant<int>();
absl::bad_variant_access e1;
std::string const year = absl::FormatTime("%Y", absl::Now(), absl::UTCTimeZone());
std::cout << "year " << year << std::endl;
}

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)

View File

@@ -0,0 +1,20 @@
from conans import ConanFile, CMake, tools
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
def build(self):
cmake = CMake(self)
cmake.definitions["CXX20_SUPPORTED"] = tools.Version(self.deps_cpp_info["abseil"].version) > "20210324.2"
cmake.configure()
cmake.build()
def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(f"{bin_path} -s", run_environment=True)
bin_global_path = os.path.join("bin", "test_package_global")
self.run(f"{bin_global_path} -s", run_environment=True)

15
recipes/abseil/config.yml Normal file
View File

@@ -0,0 +1,15 @@
versions:
"20240722.0":
folder: all
"20240116.2":
folder: all
"20240116.1":
folder: all
"20230802.1":
folder: all
"20230125.3":
folder: all
"20220623.1":
folder: all
"20211102.0":
folder: all