Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abseil: add shared option + fix link to libm + drop few patch versions + modernize #6383

Merged
merged 15 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 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 All @@ -8,4 +8,8 @@ if(MSVC)
add_definitions("-D_HAS_DEPRECATED_RESULT_OF")
endif()

if(NOT CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CONAN_ABSEIL_SYSTEM_PROCESSOR})
endif()

add_subdirectory(source_subfolder)
49 changes: 13 additions & 36 deletions recipes/abseil/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,32 @@ sources:
"20210324.2":
url: "https://github.com/abseil/abseil-cpp/archive/20210324.2.tar.gz"
sha256: "59b862f50e710277f8ede96f083a5bb8d7c9595376146838b9580be90374ee1f"
"20210324.1":
url: "https://github.com/abseil/abseil-cpp/archive/refs/tags/20210324.1.tar.gz"
sha256: "441db7c09a0565376ecacf0085b2d4c2bbedde6115d7773551bc116212c2a8d6"
"20210324.0":
url: "https://github.com/abseil/abseil-cpp/archive/refs/tags/20210324.0.tar.gz"
sha256: "dd7db6815204c2a62a2160e32c55e97113b0a0178b2f090d6bab5ce36111db4b"
"20200923.3":
url: "https://github.com/abseil/abseil-cpp/archive/20200923.3.tar.gz"
sha256: "ebe2ad1480d27383e4bf4211e2ca2ef312d5e6a09eba869fd2e8a5c5d553ded2"
"20200923.2":
url: "https://github.com/abseil/abseil-cpp/archive/20200923.2.tar.gz"
sha256: "bf3f13b13a0095d926b25640e060f7e13881bd8a792705dd9e161f3c2b9aa976"
"20200923.1":
url: "https://github.com/abseil/abseil-cpp/archive/20200923.1.tar.gz"
sha256: "808350c4d7238315717749bab0067a1acd208023d41eaf0c7360f29cc8bc8f21"
"20200923":
url: "https://github.com/abseil/abseil-cpp/archive/20200923.tar.gz"
sha256: "b3744a4f7a249d5eaf2309daad597631ce77ea62e0fc6abffbab4b4c3dc0fc08"
"20200225.3":
url: "https://github.com/abseil/abseil-cpp/archive/20200225.3.tar.gz"
sha256: "66d4d009050f39c104b03f79bdca9d930c4964016f74bf24867a43fbdbd00d23"
"20200225.2":
url: "https://github.com/abseil/abseil-cpp/archive/20200225.2.tar.gz"
sha256: "f41868f7a938605c92936230081175d1eae87f6ea2c248f41077c8f88316f111"
"20200205":
url: "https://github.com/abseil/abseil-cpp/archive/08a7e7bf972c8451855a5022f2faf3d3655db015.tar.gz"
sha256: 3c554df4909c5c55a6d251f6eadc2c78ff20db5ad4471fd9cbf8085c51b76797
patches:
"20200923.2":
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
"20211102.0":
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
"20200923.1":
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
"20210324.2":
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
"20200923":
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
- patch_file: "patches/0004-cpp-standard-20210324.patch"
base_path: "source_subfolder"
"20200225.3":
- patch_file: "patches/20200205-cmake-install.patch"
"20200923.3":
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
- patch_file: "patches/0004-cpp-standard-20200923.patch"
base_path: "source_subfolder"
"20200225.2":
- patch_file: "patches/20200205-cmake-install.patch"
"20200225.3":
- patch_file: "patches/0001-cmake-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
- patch_file: "patches/0002-missing-numeric_limits.h.patch"
base_path: "source_subfolder"
"20200205":
- patch_file: "patches/20200205-cmake-install.patch"
- patch_file: "patches/0003-absl-string-libm.patch"
base_path: "source_subfolder"
- patch_file: "patches/20200205-missing-numeric_limits.h.patch"
- patch_file: "patches/0004-cpp-standard-20200225.patch"
base_path: "source_subfolder"
120 changes: 55 additions & 65 deletions recipes/abseil/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,61 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import json
import os
import re

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.43.0"


class ConanRecipe(ConanFile):
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"

exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
short_paths = True

settings = "os", "arch", "compiler", "build_type"
options = {"fPIC": [True, False]}
default_options = {"fPIC": True}
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

short_paths = True
generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.options.shared and self._is_msvc:
# upstream tries its best to export symbols, but it's broken for the moment
raise ConanInvalidConfiguration("abseil shared not availabe for Visual Studio (yet)")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
Expand All @@ -47,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["CMAKE_SYSTEM_PROCESSOR"] = str(self.settings.arch)
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 Expand Up @@ -121,7 +108,7 @@ def _create_components_file_from_cmake_target_file(self, absl_target_file_path):
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]
components[potential_lib_name]["libs"] = [potential_lib_name] if cmake_target_nonamespace != "abseil_dll" else []
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:
Expand All @@ -132,16 +119,18 @@ def _create_components_file_from_cmake_target_file(self, absl_target_file_path):
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 == "Linux":
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 self.settings.os == "Macos":
elif tools.is_apple_os(self.settings.os):
for framework in ["CoreFoundation"]:
if framework in dependency:
components[potential_lib_name].setdefault("frameworks", []).append(framework)
Expand All @@ -159,23 +148,24 @@ def _components_helper_filepath(self):
return os.path.join(self.package_folder, "lib", "components.json")

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "absl")

components_json_file = tools.load(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", [])
if self._is_msvc and self.settings.compiler.get_safe("cppstd") == "20":
self.cpp_info.components[pkgconfig_name].defines.extend(["_HAS_DEPRECATED_RESULT_OF", "_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING"])

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"

def _register_components():
components_json_file = tools.load(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].names["cmake_find_package"] = cmake_target
self.cpp_info.components[pkgconfig_name].names["cmake_find_package_multi"] = cmake_target
self.cpp_info.components[pkgconfig_name].names["pkg_config"] = 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", [])
if self.settings.compiler == "Visual Studio" and self.settings.get_safe("compiler.cppstd") == "20":
self.cpp_info.components[pkgconfig_name].defines.extend(["_HAS_DEPRECATED_RESULT_OF", "_SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING"])

_register_components()
15 changes: 15 additions & 0 deletions recipes/abseil/all/patches/0003-absl-string-libm.patch
Original file line number Diff line number Diff line change
@@ -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"
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
4 changes: 2 additions & 2 deletions recipes/abseil/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.1.0)
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

# Test components
find_package(absl REQUIRED)
find_package(absl REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
Expand Down
5 changes: 3 additions & 2 deletions recipes/abseil/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
Expand Down
14 changes: 0 additions & 14 deletions recipes/abseil/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,7 @@ versions:
folder: all
"20210324.2":
folder: all
"20210324.1":
folder: all
"20210324.0":
folder: all
"20200923.3":
folder: all
"20200923.2":
folder: all
"20200923.1":
folder: all
"20200923":
folder: all
"20200225.3":
folder: all
"20200225.2":
folder: all
"20200205":
folder: all