diff --git a/recipes/astarte-device-sdk/all/conandata.yml b/recipes/astarte-device-sdk/all/conandata.yml new file mode 100644 index 0000000000000..5792d388f20a1 --- /dev/null +++ b/recipes/astarte-device-sdk/all/conandata.yml @@ -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" diff --git a/recipes/astarte-device-sdk/all/conanfile.py b/recipes/astarte-device-sdk/all/conanfile.py new file mode 100644 index 0000000000000..b024e3ec16702 --- /dev/null +++ b/recipes/astarte-device-sdk/all/conanfile.py @@ -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 (simone.orru@secomind.com)" + 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")) diff --git a/recipes/astarte-device-sdk/all/test_package/CMakeLists.txt b/recipes/astarte-device-sdk/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..3f40ebb0b618f --- /dev/null +++ b/recipes/astarte-device-sdk/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/astarte-device-sdk/all/test_package/conanfile.py b/recipes/astarte-device-sdk/all/test_package/conanfile.py new file mode 100644 index 0000000000000..2e77b4246fa81 --- /dev/null +++ b/recipes/astarte-device-sdk/all/test_package/conanfile.py @@ -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") diff --git a/recipes/astarte-device-sdk/all/test_package/test_package.cpp b/recipes/astarte-device-sdk/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..d7d76f512a15e --- /dev/null +++ b/recipes/astarte-device-sdk/all/test_package/test_package.cpp @@ -0,0 +1,13 @@ +#include +#include + +using AstarteDeviceSdk::AstarteDeviceGRPC; + +int main(void) { + std::string server_addr = "localhost:50051"; + std::string node_id("aa04dade-9401-4c37-8c6a-d8da15b083ae"); + std::shared_ptr device = + std::make_shared(server_addr, node_id); + + return EXIT_SUCCESS; +} diff --git a/recipes/astarte-device-sdk/config.yml b/recipes/astarte-device-sdk/config.yml new file mode 100644 index 0000000000000..b94f5b45b1bf5 --- /dev/null +++ b/recipes/astarte-device-sdk/config.yml @@ -0,0 +1,3 @@ +versions: + "0.8.1": + folder: all