Skip to content

Commit

Permalink
zenoh-c: add suggestions from @oteffahi
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Apr 16, 2024
1 parent 9632ebb commit 28789a8
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions recipes/zenoh-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv, Environment
from conan.tools.files import get, copy, replace_in_file, save, rmdir, rm, rename, mkdir
Expand All @@ -19,10 +21,22 @@ class ZenohCConan(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"logger_autoinit": [True, False],
"shared_memory": [True, False],
"extra_cargo_flags": ["ANY"],
}
default_options = {
"shared": False,
"fPIC": True,
"logger_autoinit": True,
"shared_memory": True,
"extra_cargo_flags": "",
}
options_description = {
"logger_autoinit": ("By default, zenoh-c enables Zenoh's logging library. "
"The logger can still be manually re-enabled with the zc_init_logger function."),
"shared_memory": "Enables transferring data through shared memory if the receiver and transmitter are on the same host",
"extra_cargo_flags": "Extra flags to pass to Cargo"
}

def config_options(self):
Expand All @@ -38,8 +52,20 @@ def configure(self):
def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
pass
def _is_supported_platform(self):
if self.settings.os == "Windows" and self.settings.arch == "x86_64":
return True
if self.settings.os in ["Linux", "FreeBSD"] and self.settings.arch in ["x86_64", "armv6", "armv7hf", "armv8"]:
return True
if is_apple_os(self) and self.settings.arch in ["x86_64", "armv8"]:
return True
return False

def validate(self):
if not self._is_supported_platform():
raise ConanInvalidConfiguration(
f"{self.settings.os}/{self.settings.arch} combination is not supported"
)

def build_requirements(self):
self.tool_requires("cmake/[>=3.16 <4]")
Expand All @@ -54,6 +80,9 @@ def generate(self):

tc = CMakeToolchain(self)
tc.variables["ZENOHC_INSTALL_STATIC_LIBRARY"] = not self.options.shared
tc.variables["ZENOHC_BUILD_WITH_LOGGER_AUTOINIT"] = self.options.logger_autoinit
tc.variables["ZENOHC_BUILD_WITH_SHARED_MEMORY"] = self.options.shared_memory
tc.variables["ZENOHC_CARGO_FLAGS"] = self.options.extra_cargo_flags
tc.generate()

# Don't add the Cargo dependencies to a global Cargo cache
Expand Down Expand Up @@ -106,3 +135,7 @@ def package_info(self):
self.cpp_info.libs = [self._lib_name]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["dl", "m", "pthread", "rt"])
elif self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["bcrypt", "crypt32", "iphlpapi", "ncrypt", "ntdll", "runtimeobject", "secur32", "userenv", "ws2_32"])
elif is_apple_os(self):
self.cpp_info.frameworks.extend(["Foundation", "Security"])

0 comments on commit 28789a8

Please sign in to comment.