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

Add libavrocpp/1.10.1 #4393

Merged
merged 15 commits into from
Feb 9, 2021
7 changes: 7 additions & 0 deletions recipes/libavrocpp/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1.2)
plopp marked this conversation as resolved.
Show resolved Hide resolved
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/libavrocpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
1.10.1:
url: "https://github.com/apache/avro/archive/release-1.10.1.tar.gz"
sha256: "8fd1f850ce37e60835e6d8335c0027a959aaa316773da8a9660f7d33a66ac142"
93 changes: 93 additions & 0 deletions recipes/libavrocpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import os

from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version


class LibavrocppConan(ConanFile):
name = "libavrocpp"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
description = "Avro is a data serialization system."
homepage = "https://avro.apache.org/"
topics = ("serialization", "deserialization")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_snappy": [True, False],
}
default_options = {"shared": False, "fPIC": True, "with_snappy": True}
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
return os.path.join("source_subfolder", "lang", "c++")

@property
def _build_subfolder(self):
return "build_subfolder"

_cmake = None

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
tools.replace_in_file(
plopp marked this conversation as resolved.
Show resolved Hide resolved
os.path.join(self._source_subfolder, "CMakeLists.txt"),
"project (Avro-cpp)",
"""project (Avro-cpp)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()""",
)

if self.options.with_snappy:
tools.replace_in_file(
os.path.join(self._source_subfolder, "CMakeLists.txt"),
"find_package(Snappy)",
"",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

So I looked into.. and yes it's an option

To compile requires boost headers, and the boost regex library. Optionally, it requires Snappy compression library. If Snappy is available, it builds support for Snappy compression and skips it otherwise.

https://github.com/apache/avro/blob/351f589913b9691322966fb77fe72269a0a2ec82/lang/c%2B%2B/CMakeLists.txt#L75-L79


My suggestion is to conditionally define the variable

https://github.com/apache/avro/blob/351f589913b9691322966fb77fe72269a0a2ec82/lang/c%2B%2B/FindSnappy.cmake#L28

If it's not required and found... well 🤯

This patch should not be required 🤞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried setting the variable to an empty string in _configure_cmake() when not using snappy:

if not self.options.with_snappy:
    self._cmake.definitions["SNAPPY_ROOT_DIR"] = ""

But that failed:

-- Could NOT find Snappy (missing: SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIR)
Disabled snappy codec. libsnappy not found.
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
/home/user/.conan/data/libavrocpp/1.10.1/_/_/build/a285fc00ea829acfc7280102b9b32a8043fbd51c/source_subfolder/lang/c++/SNAPPY_INCLUDE_DIR
   used as include directory in directory /home/user/.conan/data/libavrocpp/1.10.1/_/_/build/a285fc00ea829acfc7280102b9b32a8043fbd51c/source_subfolder/lang/c++
   used as include directory in directory /home/user/.conan/data/libavrocpp/1.10.1/_/_/build/a285fc00ea829acfc7280102b9b32a8043fbd51c/source_subfolder/lang/c++

I will leave the removal of the builtin call to find_package(snappy) in there meanwhile, and see if I can find a better way later.

self._cmake = CMake(self)
self._cmake.configure(source_folder=self._source_subfolder)
return self._cmake

def configure(self):
plopp marked this conversation as resolved.
Show resolved Hide resolved
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")

def requirements(self):
self.requires("boost/[>=1.38.0]")

def build_requirements(self):
self.build_requires("boost/[>=1.38.0]")
if self.options.with_snappy:
self.build_requires("snappy/1.1.8")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("avro-release-" + self.version, "source_subfolder")

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
self.copy("NOTICE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
plopp marked this conversation as resolved.
Show resolved Hide resolved
if self.options.shared:
self.cpp_info.components["avrocpp"].libs = ["avrocpp"]
self.cpp_info.components["avrocpp"].requires = ["boost::boost"]
else:
self.cpp_info.components["avrocpp_s"].libs = ["avrocpp_s"]
self.cpp_info.components["avrocpp_s"].requires = ["boost::boost"]
plopp marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions recipes/libavrocpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

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

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

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

if(AVROCPP_SHARED)
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp)
else()
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp_s)
endif()
19 changes: 19 additions & 0 deletions recipes/libavrocpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conans import ConanFile, CMake, tools


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

def build(self):
cmake = CMake(self)
cmake.definitions["AVROCPP_SHARED"] = self.options["libavrocpp"].shared
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
25 changes: 25 additions & 0 deletions recipes/libavrocpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "avro/Decoder.hh"
#include "avro/Encoder.hh"
#include "avro/Specific.hh"

int main()
{
int64_t dummy = 1234;
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
avro::encode(*e, dummy);

std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);

int64_t decoded;
avro::decode(*d, decoded);

if (dummy != decoded)
{
return 1;
}
return 0;
}
3 changes: 3 additions & 0 deletions recipes/libavrocpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
1.10.1:
folder: all