Skip to content
Open
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
5 changes: 5 additions & 0 deletions recipes/astarte-device-sdk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sources:
"0.8.1":
url:
- "https://github.com/astarte-platform/astarte-device-sdk-cpp/archive/v0.8.1.tar.gz"
sha256: "21f4cb1686e9b0e78ca2805f3615e4033f04130fd80326688f3bca225e1eabb0"
81 changes: 81 additions & 0 deletions recipes/astarte-device-sdk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
from conan.tools.build import check_min_cppstd, check_min_compiler_version
import os

required_conan_version = ">=2.1"

class AstarteConan(ConanFile):
name = "astarte-device-sdk"
package_type = "library"
languages = "C++"
license = "Apache-2.0"
author = "Simone Orru ([email protected])"
url = "https://github.com/astarte-platform/astarte-device-sdk-cpp"
homepage = "https://docs.astarte-platform.org/"
description = "Astarte device SDK package written in C++"
topics = ("mqtt", "astarte", "iot")

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

# Build configuration
build_policy = "missing"

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

def requirements(self):
self.requires("grpc/1.72.0")
self.requires("protobuf/6.30.1", override = True)
self.requires("spdlog/1.15.3", options={"use_std_fmt": "True"}, transitive_headers=True, transitive_libs=True)

def build_requirements(self):
self.tool_requires("protobuf/6.30.1")

def validate(self):
check_min_cppstd(self, 20)
compiler_restrictions = [
("gcc", "13", "Requires C++20 std::format"),
("clang", "15", "Requires C++20 std::format"),
("apple-clang", "15", "Requires C++20 std::format"),
("msvc", "193", "Requires C++20 std::format") # Visual Studio 2022
]
check_min_compiler_version(self, compiler_restrictions)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
# exports_sources = "CMakeLists.txt", "cmake/AstarteMQTTTransport.cmake", "cmake/AstarteGRPCTransport.cmake", "cmake/Config.cmake.in", "cmake/pkg-config-template.pc.in", "src/*", "include/*", "private/*"

def package_info(self):
self.cpp_info.libs = ["astarte_device_sdk", "astarte_msghub_proto"]
self.cpp_info.set_property("cmake_file_name", "astarte_device_sdk")
self.cpp_info.set_property("cmake_target_name", "astarte_device_sdk::astarte_device_sdk")

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ASTARTE_USE_SYSTEM_SPDLOG"] = "ON"
tc.variables["ASTARTE_USE_SYSTEM_GRPC"] = "ON"
tc.generate()
cmake_deps = CMakeDeps(self)
cmake_deps.generate()

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

def package(self):
copy(self, "LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"))

cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
7 changes: 7 additions & 0 deletions recipes/astarte-device-sdk/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.20)
project(test_package LANGUAGES CXX)

find_package(astarte_device_sdk REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE astarte_device_sdk::astarte_device_sdk)
25 changes: 25 additions & 0 deletions recipes/astarte-device-sdk/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


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

def layout(self):
cmake_layout(self)

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

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
13 changes: 13 additions & 0 deletions recipes/astarte-device-sdk/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cstdlib>
#include <astarte_device_sdk/device_grpc.hpp>

using AstarteDeviceSdk::AstarteDeviceGRPC;

int main(void) {
std::string server_addr = "localhost:50051";
std::string node_id("aa04dade-9401-4c37-8c6a-d8da15b083ae");
std::shared_ptr<AstarteDeviceGRPC> device =
std::make_shared<AstarteDeviceGRPC>(server_addr, node_id);

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/astarte-device-sdk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.8.1":
folder: all