diff --git a/recipes/libiec61850/all/conandata.yml b/recipes/libiec61850/all/conandata.yml new file mode 100644 index 0000000000000..9b1ec43758314 --- /dev/null +++ b/recipes/libiec61850/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.6.0": + url: "https://github.com/mz-automation/libiec61850/archive/refs/tags/v1.6.0.tar.gz" + sha256: "0dd0adc7f13215e961d22511bcb1dadfdbdaab969f11a0d975775a6ebdff8099" diff --git a/recipes/libiec61850/all/conanfile.py b/recipes/libiec61850/all/conanfile.py new file mode 100644 index 0000000000000..0503db52a7890 --- /dev/null +++ b/recipes/libiec61850/all/conanfile.py @@ -0,0 +1,77 @@ +import os +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import get, copy, replace_in_file, rmdir, rm +from conan.tools.scm import Version + +required_conan_version = ">=2.1" + +class Libiec61850Conan(ConanFile): + name = "libiec61850" + description = "An open-source library for the IEC 61850 protocols." + license = "LGPL-3.0" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://libiec61850.com/libiec61850" + topics = ("iec61850", "mms", "goose", "sampled values") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + languages = ["C"] + implements = ["auto_shared_fpic"] + + def layout(self): + cmake_layout(self, src_folder="src") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["BUILD_EXAMPLES"] = False + tc.cache_variables["BUILD_TESTS"] = False + tc.cache_variables["FIND_PACKAGE_DISABLE_Doxygen"] = True + tc.generate() + + def build(self): + target_type = "-shared" if self.options.get_safe("shared") else "" + replace_in_file(self, os.path.join(self.source_folder, "hal", "CMakeLists.txt"), + "install (TARGETS hal hal-shared", f"install (TARGETS hal{target_type}") + replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"), + "install (TARGETS iec61850 iec61850-shared", f"install (TARGETS iec61850{target_type}") + cmake = CMake(self) + cmake.configure() + target = "iec61850-shared" if self.options.get_safe("shared") else "iec61850" + cmake.build(target=target) + + def package(self): + copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "share")) + for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]: + rm(self, pattern=dll_pattern_to_remove, folder=os.path.join(self.package_folder, "bin"), + recursive=True) + + if Version(self.version) == "1.6.0": + # https://github.com/mz-automation/libiec61850/commit/a133aa8d573d63555899580869643590db9a7d85 + copy(self, "tls_ciphers.h", os.path.join(self.source_folder, "hal", "inc"), + os.path.join(self.package_folder, "include", "libiec61850")) + + def package_info(self): + self.cpp_info.components["iec61850"].libs = ["iec61850"] + self.cpp_info.components["iec61850"].set_property("cmake_target_name", "iec61850") + self.cpp_info.components["hal"].libs = ["hal-shared"] if self.options.get_safe("shared") else ["hal"] + self.cpp_info.components["iec61850"].requires=["hal"] + self.cpp_info.components["iec61850"].set_property("pkg_config_name", "libiec61850") + if self.settings.os in ["Linux"]: + self.cpp_info.components["iec61850"].system_libs.append("pthread") + self.cpp_info.components["iec61850"].system_libs.append("rt") diff --git a/recipes/libiec61850/all/test_package/CMakeLists.txt b/recipes/libiec61850/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..e88f51214b2c9 --- /dev/null +++ b/recipes/libiec61850/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(libiec61850) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} iec61850) diff --git a/recipes/libiec61850/all/test_package/conanfile.py b/recipes/libiec61850/all/test_package/conanfile.py new file mode 100644 index 0000000000000..c37539acafafe --- /dev/null +++ b/recipes/libiec61850/all/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake + + +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/libiec61850/all/test_package/test_package.cpp b/recipes/libiec61850/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..0cd36d83e092c --- /dev/null +++ b/recipes/libiec61850/all/test_package/test_package.cpp @@ -0,0 +1,10 @@ +#include +#include + +#include "libiec61850/iec61850_common.h" + +int main(int argc, char **argv) +{ + std::cout << "libiec61850 v" << LibIEC61850_getVersionString() << std::endl; + return 0; +} diff --git a/recipes/libiec61850/config.yml b/recipes/libiec61850/config.yml new file mode 100644 index 0000000000000..225152169dbd8 --- /dev/null +++ b/recipes/libiec61850/config.yml @@ -0,0 +1,3 @@ +versions: + "1.6.0": + folder: all