|
| 1 | +# (C) Copyright 2025, SECO Mind Srl |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps |
| 6 | +from conan import ConanFile |
| 7 | +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir |
| 8 | +from conan.tools.build import check_min_cppstd, check_min_compiler_version |
| 9 | +import os |
| 10 | + |
| 11 | +required_conan_version = ">=2.1" |
| 12 | + |
| 13 | +class AstarteConan(ConanFile): |
| 14 | + name = "astarte-device-sdk" |
| 15 | + package_type = "library" |
| 16 | + languages = "C++" |
| 17 | + license = "Apache-2.0" |
| 18 | + author = "Simone Orru ([email protected])" |
| 19 | + url = "https://github.com/astarte-platform/astarte-device-sdk-cpp" |
| 20 | + homepage = "https://docs.astarte-platform.org/" |
| 21 | + description = "Astarte device SDK package written in C++" |
| 22 | + topics = ("mqtt", "astarte", "iot") |
| 23 | + |
| 24 | + # Settings and options |
| 25 | + settings = "os", "compiler", "build_type", "arch" |
| 26 | + options = {"shared": [True, False], "fPIC": [True, False]} |
| 27 | + default_options = {"shared": False, "fPIC": True} |
| 28 | + |
| 29 | + # Build configuration |
| 30 | + build_policy = "missing" |
| 31 | + |
| 32 | + def config_options(self): |
| 33 | + if self.settings.os == "Windows": |
| 34 | + del self.options.fPIC |
| 35 | + |
| 36 | + def requirements(self): |
| 37 | + self.requires("grpc/1.72.0") |
| 38 | + self.requires("protobuf/6.30.1", override = True) |
| 39 | + self.requires("spdlog/1.15.3", options={"use_std_fmt": "True"}, transitive_headers=True, transitive_libs=True) |
| 40 | + |
| 41 | + def build_requirements(self): |
| 42 | + self.tool_requires("protobuf/6.30.1") |
| 43 | + |
| 44 | + def validate(self): |
| 45 | + check_min_cppstd(self, 20) |
| 46 | + compiler_restrictions = [ |
| 47 | + ("gcc", "13", "Requires C++20 std::format"), |
| 48 | + ("clang", "15", "Requires C++20 std::format"), |
| 49 | + ("apple-clang", "15", "Requires C++20 std::format"), |
| 50 | + ("msvc", "193", "Requires C++20 std::format") # Visual Studio 2022 |
| 51 | + ] |
| 52 | + check_min_compiler_version(self, compiler_restrictions) |
| 53 | + |
| 54 | + def source(self): |
| 55 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 56 | + # exports_sources = "CMakeLists.txt", "cmake/AstarteMQTTTransport.cmake", "cmake/AstarteGRPCTransport.cmake", "cmake/Config.cmake.in", "cmake/pkg-config-template.pc.in", "src/*", "include/*", "private/*" |
| 57 | + |
| 58 | + def package_info(self): |
| 59 | + self.cpp_info.libs = ["astarte_device_sdk", "astarte_msghub_proto"] |
| 60 | + self.cpp_info.set_property("cmake_file_name", "astarte_device_sdk") |
| 61 | + self.cpp_info.set_property("cmake_target_name", "astarte_device_sdk::astarte_device_sdk") |
| 62 | + |
| 63 | + def generate(self): |
| 64 | + tc = CMakeToolchain(self) |
| 65 | + tc.variables["ASTARTE_USE_SYSTEM_SPDLOG"] = "ON" |
| 66 | + tc.variables["ASTARTE_USE_SYSTEM_GRPC"] = "ON" |
| 67 | + tc.generate() |
| 68 | + cmake_deps = CMakeDeps(self) |
| 69 | + cmake_deps.generate() |
| 70 | + |
| 71 | + def build(self): |
| 72 | + cmake = CMake(self) |
| 73 | + cmake.configure() |
| 74 | + cmake.build() |
| 75 | + |
| 76 | + def package(self): |
| 77 | + copy(self, "LICENSE", |
| 78 | + src=self.source_folder, |
| 79 | + dst=os.path.join(self.package_folder, "licenses")) |
| 80 | + |
| 81 | + cmake = CMake(self) |
| 82 | + cmake.install() |
| 83 | + |
| 84 | + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) |
| 85 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
0 commit comments