from conan import ConanFile from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout from conan.tools.files import copy from conan.errors import ConanInvalidConfiguration import os class IgHEtherCATConan(ConanFile): name = "igh-ethercat" version = "1.5.2" license = "LGPL-2.1-only" author = "Florian Pose " url = "https://gitlab.com/etherlab.org/ethercat" description = "IgH EtherCAT Master userspace client library" topics = ("ethercat", "industrial", "automation", "fieldbus", "realtime") settings = "os", "compiler", "build_type", "arch" options = { "shared": [True, False], "fPIC": [True, False], "max_num_devices": ["ANY"], } default_options = { "shared": True, "fPIC": True, "max_num_devices": 1, } exports_sources = ( "CMakeLists.txt", "include/*", "lib/*", "master/globals.h", "master/ioctl.h", "globals.h", "COPYING", "COPYING.LESSER", ) def validate(self): if self.settings.os != "Linux": raise ConanInvalidConfiguration("IgH EtherCAT Master is only supported on Linux") # Validate max_num_devices is a positive integer try: max_devices = int(self.options.max_num_devices) if max_devices < 1: raise ConanInvalidConfiguration("max_num_devices must be >= 1") except ValueError: raise ConanInvalidConfiguration("max_num_devices must be an integer") def config_options(self): if self.settings.os == "Windows": del self.options.fPIC def configure(self): # This is a C library self.settings.rm_safe("compiler.libcxx") self.settings.rm_safe("compiler.cppstd") def requirements(self): self.build_requires("cmake/[>=3.15]") def layout(self): cmake_layout(self, src_folder=".") def generate(self): tc = CMakeToolchain(self) tc.variables["BUILD_SHARED_LIBS"] = self.options.shared tc.variables["EC_MAX_NUM_DEVICES"] = str(self.options.max_num_devices) tc.generate() def build(self): cmake = CMake(self) cmake.configure() cmake.build() def package(self): copy( self, "COPYING.LESSER", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"), ) copy( self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"), ) cmake = CMake(self) cmake.install() def package_info(self): self.cpp_info.libs = ["ethercat"] self.cpp_info.set_property("cmake_file_name", "ethercat") self.cpp_info.set_property("cmake_target_name", "EtherLab::ethercat") self.cpp_info.set_property("pkg_config_name", "libethercat") if self.settings.os == "Linux": self.cpp_info.system_libs = ["rt", "pthread"]