Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open62541pp: new recipe #23291

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/open62541pp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.12.0":
url: "https://github.com/open62541pp/open62541pp/archive/refs/tags/v0.12.0.tar.gz"
sha256: "4eec126609aedc9203358ad7638898bb287ac8bd76587fa4b5503f236234f9db"
113 changes: 113 additions & 0 deletions recipes/open62541pp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file

Check warning on line 7 in recipes/open62541pp/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused apply_conandata_patches imported from conan.tools.files

Check warning on line 7 in recipes/open62541pp/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused export_conandata_patches imported from conan.tools.files
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class Open62541ppConan(ConanFile):
name = "open62541pp"
description = "open62541++ is a C++ wrapper built on top of the amazing open62541 OPC UA (OPC Unified Architecture) library"
license = "MPL-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/open62541pp/open62541pp"
topics = ("opcua", "open62541")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"ipo": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"ipo": False,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
"msvc": "191",
"Visual Studio": "15",
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("open62541/1.3.9", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["UAPP_INTERNAL_OPEN62541"] = False
tc.variables["UAPP_BUILD_DOCUMENTATION"] = False
if is_msvc(self):
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self)
tc.variables["open62541_ipo"] = self.options.ipo
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
# Otherwise fails with
# INTERFACE_LIBRARY targets may only have whitelisted properties. The
# property "INTERPROCEDURAL_OPTIMIZATION" is not allowed.
# Set this in CMakeToolchain instead
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"get_target_property(open62541_ipo open62541::open62541 INTERPROCEDURAL_OPTIMIZATION)", "")

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rm(self, "*.pdb", self.package_folder, recursive=True)

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "open62541pp")
self.cpp_info.set_property("cmake_target_name", "open62541pp::open62541pp")

self.cpp_info.libs = ["open62541pp"]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
8 changes: 8 additions & 0 deletions recipes/open62541pp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

find_package(open62541pp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE open62541pp::open62541pp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/open62541pp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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")
32 changes: 32 additions & 0 deletions recipes/open62541pp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <open62541pp/open62541pp.h>

#include <iostream>


int main() {
opcua::Server server(4840 /* port */);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify the test package not to have to use server classes - reads like this could be hitting the network layer :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. The example is similar to the open62541 one: https://github.com/conan-io/conan-center-index/blob/master/recipes/open62541/all/test_package/test_package.c

I could provide a test without any server/client connection if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be ace yes :) thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, I was wrong. The example seems to be fine. The actual server connection is only instantiated if server.run() is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can simply move the test code to a dummy function that does not get called from main().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual server connection is only instantiated if server.run() is called.

Having this as a comment in the code itself then should be enough :)


server.setApplicationName("open62541pp server example");
server.setLogger([](auto level, auto category, auto msg) {
std::cout << "[" << opcua::getLogLevelName(level) << "] "
<< "[" << opcua::getLogCategoryName(category) << "] " << msg << std::endl;
});

const opcua::NodeId myIntegerNodeId{1, "the.answer"};
const std::string myIntegerName{"the answer"};

// add variable node
auto parentNode = server.getObjectsNode();
auto myIntegerNode = parentNode.addVariable(myIntegerNodeId, myIntegerName);

// set node attributes
myIntegerNode.writeDataType(opcua::DataTypeId::Int32);
myIntegerNode.writeDisplayName({"en-US", "the answer"});
myIntegerNode.writeDescription({"en-US", "the answer"});

// write value
myIntegerNode.writeValueScalar(42);

// read value
std::cout << "The answer is: " << myIntegerNode.readValueScalar<int>() << std::endl;
}
3 changes: 3 additions & 0 deletions recipes/open62541pp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.12.0":
folder: all
Loading