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

googleapis: use modern CMake integrations #15450

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 0 additions & 3 deletions recipes/googleapis/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ cmake_minimum_required(VERSION 3.20)

project(googleapis)

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

find_package(Protobuf REQUIRED CONFIG)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
Expand Down
49 changes: 21 additions & 28 deletions recipes/googleapis/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
import glob
from io import StringIO

from conans import CMake, tools

from conan import ConanFile
from conan.tools.files import get, copy
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.files import apply_conandata_patches, copy, get, export_conandata_patches, copy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from conan.tools.files import apply_conandata_patches, copy, get, export_conandata_patches, copy
from conan.tools.files import apply_conandata_patches, copy, get, export_conandata_patches

from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

from conan.errors import ConanInvalidConfiguration

from helpers import parse_proto_libraries

required_conan_version = ">=1.45.0"

required_conan_version = ">=1.50.0"

class GoogleAPIS(ConanFile):
name = "googleapis"
package_type = "library"
description = "Public interface definitions of Google APIs"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/googleapis/googleapis"
topics = "google", "protos", "api"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain"
options = {
"shared": [True, False],
"fPIC": [True, False]
Expand All @@ -38,26 +38,28 @@ class GoogleAPIS(ConanFile):
short_paths = True

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=os.path.join(self.export_sources_folder, "src"))
export_conandata_patches(self)

def source(self):
get(self, **self.conan_data["sources"][str(self.version)], destination=self.source_folder, strip_root=True)
self._patch_sources()
apply_conandata_patches(self)

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

def layout(self):
cmake_layout(self, src_folder="src")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options["protobuf"].shared = True

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) <= "5":
raise ConanInvalidConfiguration("Build with GCC 5 fails")

Expand All @@ -81,19 +83,13 @@ def _cmake_new_enough(self):
return True

def requirements(self):
self.requires('protobuf/3.21.4')
self.requires('protobuf/3.21.4', transitive_headers=True)

def build_requirements(self):
self.build_requires('protobuf/3.21.4')
# CMake >= 3.20 is required. There is a proto with dots in the name 'k8s.min.proto' and CMake fails to generate project files
if not self._cmake_new_enough:
self.build_requires('cmake/3.23.2')

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake
self.build_requires('cmake/3.23.5')

@functools.lru_cache(1)
def _parse_proto_libraries(self):
Expand Down Expand Up @@ -131,13 +127,13 @@ def deactivate_library(key):
# - Inconvenient macro names from usr/include/sys/syslimits.h in some macOS SDKs: GID_MAX
# Patched here: https://github.com/protocolbuffers/protobuf/commit/f138d5de2535eb7dd7c8d0ad5eb16d128ab221fd
# as of 3.21.4 issue still exist
if Version(self.deps_cpp_info["protobuf"].version) <= "3.21.5" and self.settings.os == "Macos" or \
if Version(self.dependencies["protobuf"].ref.version) <= "3.21.5" and self.settings.os == "Macos" or \
self.settings.os == "Android":
deactivate_library("//google/storagetransfer/v1:storagetransfer_proto")
deactivate_library("//google/storagetransfer/v1:storagetransfer_cc_proto")
# - Inconvenient macro names from /usr/include/math.h : DOMAIN
if (self.settings.os == "Linux" and self.settings.compiler == "clang" and self.settings.compiler.libcxx == "libc++") or \
self.settings.compiler in ["Visual Studio", "msvc"]:
is_msvc(self):
deactivate_library("//google/cloud/channel/v1:channel_proto")
deactivate_library("//google/cloud/channel/v1:channel_cc_proto")
# - Inconvenient names for android
Expand Down Expand Up @@ -169,14 +165,10 @@ def build(self):
f.write("# DO NOT EDIT - change the generation code in conanfile.py instead\n")
for it in filter(lambda u: u.is_used, proto_libraries):
f.write(it.cmake_content)
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
# Using **patch here results in an error with the required `patch_description` field.
tools.patch(patch_file=patch['patch_file'])

_DEPS_FILE = "res/generated_targets.deps"

def package(self):
Expand All @@ -199,6 +191,7 @@ def package_id(self):
self.info.requires["protobuf"].full_package_mode()

def package_info(self):
self.cpp_info.resdirs = ["res"]
with open(os.path.join(self.package_folder, self._DEPS_FILE), "r", encoding="utf-8") as f:
for line in f.read().splitlines():
(name, libtype, deps) = line.rstrip('\n').split(' ')
Expand Down
9 changes: 4 additions & 5 deletions recipes/googleapis/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.build import cross_building as tools_cross_building
from conan.tools.layout import cmake_layout
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conan.tools.build import can_run


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

def requirements(self):
self.requires(self.tested_reference_str)
Expand All @@ -25,5 +24,5 @@ def build(self):
cmake.build()

def test(self):
if not tools_cross_building(self):
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun")