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

modern-cpp-kafka: new recipe #11430

Merged
merged 8 commits into from
Jul 21, 2022
4 changes: 4 additions & 0 deletions recipes/modern-cpp-kafka/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2022.06.15":
url: https://github.com/morganstanley/modern-cpp-kafka/archive/refs/tags/v2022.06.15.tar.gz
sha256: 478fcf560057b7cf7b4be851838ebf0520806d057b172de23261606fce088d27
38 changes: 38 additions & 0 deletions recipes/modern-cpp-kafka/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from conans import ConanFile, tools
import os

required_conan_version = ">=1.33.0"


class ModernCppKafkaConan(ConanFile):
name = "modern-cpp-kafka"
description = "A C++ API for Kafka clients (i.e. KafkaProducer, KafkaConsumer, AdminClient)"
license = "Apache License 2.0"
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
topics = ("kafka", "librdkafka", "kafkaproducer", "kafkaconsumer")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/morganstanley/modern-cpp-kafka"
settings = "arch", "build_type", "compiler", "os"
no_copy_source = True

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

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

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))

def package_id(self):
self.info.header_only()

kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
def package_info(self):
self.cpp_info.set_property("cmake_target_name", "ModernCppKafka::ModernCppKafka")

self.cpp_info.names["cmake_find_package"] = "ModernCppKafka"
self.cpp_info.names["cmake_find_package_multi"] = "ModernCppKafka"

if self.settings.os in ["Linux", "Macos"]:
self.cpp_info.system_libs.append("pthread")
11 changes: 11 additions & 0 deletions recipes/modern-cpp-kafka/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(RdKafka REQUIRED CONFIG)
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
find_package(ModernCppKafka REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} RdKafka::rdkafka ModernCppKafka::ModernCppKafka)
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions recipes/modern-cpp-kafka/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
import os

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

def requirements(self):
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self.requires("librdkafka/1.8.2")
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved

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

def test(self):
if not tools.cross_building(self):
kenneth-jia marked this conversation as resolved.
Show resolved Hide resolved
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
8 changes: 8 additions & 0 deletions recipes/modern-cpp-kafka/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "kafka/Utility.h"

#include <iostream>

int main()
{
std::cout << "librdkafka version: " << kafka::utility::getLibRdKafkaVersion() << std::endl;
}
3 changes: 3 additions & 0 deletions recipes/modern-cpp-kafka/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2022.06.15":
folder: all