|
| 1 | +import os |
| 2 | +from conan import ConanFile |
| 3 | +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout |
| 4 | +from conan.tools.files import get, copy, replace_in_file, rmdir, rm |
| 5 | +from conan.tools.scm import Version |
| 6 | + |
| 7 | +required_conan_version = ">=2.1" |
| 8 | + |
| 9 | +class Libiec61850Conan(ConanFile): |
| 10 | + name = "libiec61850" |
| 11 | + description = "An open-source library for the IEC 61850 protocols." |
| 12 | + license = "LGPL-3.0" |
| 13 | + url = "https://github.com/conan-io/conan-center-index" |
| 14 | + homepage = "https://libiec61850.com/libiec61850" |
| 15 | + topics = ("iec61850", "mms", "goose", "sampled values") |
| 16 | + |
| 17 | + package_type = "library" |
| 18 | + settings = "os", "arch", "compiler", "build_type" |
| 19 | + options = { |
| 20 | + "shared": [True, False], |
| 21 | + "fPIC": [True, False], |
| 22 | + } |
| 23 | + default_options = { |
| 24 | + "shared": False, |
| 25 | + "fPIC": True, |
| 26 | + } |
| 27 | + |
| 28 | + languages = ["C"] |
| 29 | + implements = ["auto_shared_fpic"] |
| 30 | + |
| 31 | + def layout(self): |
| 32 | + cmake_layout(self, src_folder="src") |
| 33 | + |
| 34 | + def source(self): |
| 35 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 36 | + |
| 37 | + def generate(self): |
| 38 | + tc = CMakeToolchain(self) |
| 39 | + tc.cache_variables["BUILD_EXAMPLES"] = False |
| 40 | + tc.cache_variables["BUILD_TESTS"] = False |
| 41 | + tc.cache_variables["FIND_PACKAGE_DISABLE_Doxygen"] = True |
| 42 | + tc.generate() |
| 43 | + |
| 44 | + def build(self): |
| 45 | + target_type = "-shared" if self.options.get_safe("shared") else "" |
| 46 | + replace_in_file(self, os.path.join(self.source_folder, "hal", "CMakeLists.txt"), |
| 47 | + "install (TARGETS hal hal-shared", f"install (TARGETS hal{target_type}") |
| 48 | + replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), |
| 49 | + "install (TARGETS iec61850 iec61850-shared", f"install (TARGETS iec61850{target_type}") |
| 50 | + cmake = CMake(self) |
| 51 | + cmake.configure() |
| 52 | + target = "iec61850-shared" if self.options.get_safe("shared") else "iec61850" |
| 53 | + cmake.build(target=target) |
| 54 | + |
| 55 | + def package(self): |
| 56 | + copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) |
| 57 | + cmake = CMake(self) |
| 58 | + cmake.install() |
| 59 | + rmdir(self, os.path.join(self.package_folder, "share")) |
| 60 | + for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]: |
| 61 | + rm(self, pattern=dll_pattern_to_remove, folder=os.path.join(self.package_folder, "bin"), |
| 62 | + recursive=True) |
| 63 | + |
| 64 | + if Version(self.version) == "1.6.0": |
| 65 | + # https://github.com/mz-automation/libiec61850/commit/a133aa8d573d63555899580869643590db9a7d85 |
| 66 | + copy(self, "tls_ciphers.h", os.path.join(self.source_folder, "hal", "inc"), |
| 67 | + os.path.join(self.package_folder, "include", "libiec61850")) |
| 68 | + |
| 69 | + def package_info(self): |
| 70 | + self.cpp_info.components["iec61850"].libs = ["iec61850"] |
| 71 | + self.cpp_info.components["iec61850"].set_property("cmake_target_name", "iec61850") |
| 72 | + self.cpp_info.components["hal"].libs = ["hal-shared"] if self.options.get_safe("shared") else ["hal"] |
| 73 | + self.cpp_info.components["iec61850"].requires=["hal"] |
| 74 | + self.cpp_info.components["iec61850"].set_property("pkg_config_name", "libiec61850") |
| 75 | + if self.settings.os in ["Linux"]: |
| 76 | + self.cpp_info.components["iec61850"].system_libs.append("pthread") |
| 77 | + self.cpp_info.components["iec61850"].system_libs.append("rt") |
0 commit comments