Skip to content

Commit cc89c36

Browse files
inPhraZdanimtbczoidojcar87
authored
libiec61850: new recipe (#26096)
* libiec61850: Add new recipe * Remove BUILD_SHARED_LIBS and BUILD_STATIC_LIBS assignments * Add cache_variables: FIND_PACKAGE_DISABLE_Doxygen * Add attribute: auto_shared_fpic * Remove unnecessary copies in package() * Get library version in test_package * simpler test_package * add system_libs for linux: rt, pthread * build shared/static target and remove redundant package_info * test_package * disable mbedtls * package include files, avoid install for lib artifacts, add hal to libs * only windows build is special * polish * fix * Update recipes/libiec61850/all/conanfile.py Co-authored-by: Carlos Zoido <[email protected]> * Update recipes/libiec61850/all/conanfile.py Co-authored-by: Carlos Zoido <[email protected]> * Update recipes/libiec61850/all/conanfile.py * Apply suggestions from code review * package correct libs shared-static * simplify * fix import * Update recipes/libiec61850/all/conanfile.py * use `cache_variables` for single-config varibles: `BUILD_EXAMPLES`, `BUILD_TESTS` * review * remove runtime files * remove runtime files * build only shared or static target * wip * libiec61850: publish latest version --------- Co-authored-by: danimtb <[email protected]> Co-authored-by: czoido <[email protected]> Co-authored-by: Luis Caro Campos <[email protected]>
1 parent 6bd75ec commit cc89c36

File tree

6 files changed

+126
-0
lines changed

6 files changed

+126
-0
lines changed

recipes/libiec61850/all/conandata.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
"1.6.0":
3+
url: "https://github.com/mz-automation/libiec61850/archive/refs/tags/v1.6.0.tar.gz"
4+
sha256: "0dd0adc7f13215e961d22511bcb1dadfdbdaab969f11a0d975775a6ebdff8099"

recipes/libiec61850/all/conanfile.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(test_package LANGUAGES CXX)
3+
4+
find_package(libiec61850)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_link_libraries(${PROJECT_NAME} iec61850)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
from conan import ConanFile
3+
from conan.tools.build import can_run
4+
from conan.tools.cmake import cmake_layout, CMake
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
11+
def layout(self):
12+
cmake_layout(self)
13+
14+
def requirements(self):
15+
self.requires(self.tested_reference_str)
16+
17+
def build(self):
18+
cmake = CMake(self)
19+
cmake.configure()
20+
cmake.build()
21+
22+
def test(self):
23+
if can_run(self):
24+
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
25+
self.run(bin_path, env="conanrun")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
4+
#include "libiec61850/iec61850_common.h"
5+
6+
int main(int argc, char **argv)
7+
{
8+
std::cout << "libiec61850 v" << LibIEC61850_getVersionString() << std::endl;
9+
return 0;
10+
}

recipes/libiec61850/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"1.6.0":
3+
folder: all

0 commit comments

Comments
 (0)