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

libavrocpp: install either static or shared + fix discovery of Snappy + do not sugget unofficial imported target names #15274

Merged
merged 7 commits into from
Jan 28, 2023
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
37 changes: 22 additions & 15 deletions recipes/libavrocpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import os

required_conan_version = ">=1.53.0"
required_conan_version = ">=1.54.0"


class LibavrocppConan(ConanFile):
name = "libavrocpp"
Expand All @@ -15,11 +16,11 @@ class LibavrocppConan(ConanFile):
topics = ("serialization", "deserialization","avro")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"shared": False,
"fPIC": True
}
short_paths = True
Expand Down Expand Up @@ -47,27 +48,33 @@ def requirements(self):
self.requires("snappy/1.1.9")

def validate(self):
if self.settings.compiler.cppstd:
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["SNAPPY_ROOT_DIR"] = self.deps_cpp_info["snappy"].rootpath.replace("\\", "/")
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self,
os.path.join(self.source_folder, "lang", "c++", "CMakeLists.txt"),
"${SNAPPY_LIBRARIES}", "${Snappy_LIBRARIES}"
cmakelists = os.path.join(self.source_folder, "lang", "c++", "CMakeLists.txt")
# Fix discovery & link to Snappy
replace_in_file(self, cmakelists, "SNAPPY_FOUND", "Snappy_FOUND")
replace_in_file(self, cmakelists, "${SNAPPY_LIBRARIES}", "Snappy::snappy")
replace_in_file(
self, cmakelists,
"target_include_directories(avrocpp_s PRIVATE ${SNAPPY_INCLUDE_DIR})",
"target_link_libraries(avrocpp_s PRIVATE Snappy::snappy)",
)
# Install either static or shared
target = "avrocpp" if self.options.shared else "avrocpp_s"
replace_in_file(self, cmakelists, "install (TARGETS avrocpp avrocpp_s" , f"install (TARGETS {target}")

def build(self):
self._patch_sources()
Expand All @@ -86,12 +93,12 @@ def package(self):
rm(self, dll_pattern_to_remove, os.path.join(self.package_folder, "bin"))

def package_info(self):
# FIXME: avro does not install under a CMake namespace https://github.com/apache/avro/blob/351f589913b9691322966fb77fe72269a0a2ec82/lang/c%2B%2B/CMakeLists.txt#L193
target = "avrocpp" if self.options.shared else "avrocpp_s"
self.cpp_info.components[target].libs = [target]
self.cpp_info.components[target].requires = ["boost::boost", "snappy::snappy"]
self.cpp_info.libs = ["avrocpp" if self.options.shared else "avrocpp_s"]
if self.options.shared:
self.cpp_info.components[target].defines.append("AVRO_DYN_LINK")
self.cpp_info.defines.append("AVRO_DYN_LINK")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

self.cpp_info.requires = [
"boost::headers", "boost::filesystem", "boost::iostreams", "boost::program_options",
"boost::regex", "boost::system", "snappy::snappy",
]
9 changes: 2 additions & 7 deletions recipes/libavrocpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(libavrocpp REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE libavrocpp::libavrocpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

if(TARGET libavrocpp::avrocpp)
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp)
else()
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp_s)
endif()
6 changes: 3 additions & 3 deletions recipes/libavrocpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class TestPackageConan(ConanFile):
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down