From 84ae726c9e131f33457c5a0d108eea0f14be82cc Mon Sep 17 00:00:00 2001 From: Edmund Blomley Date: Mon, 21 Apr 2025 01:26:31 +0200 Subject: [PATCH 1/4] Add installation script for open62541 to ease installation. --- devOpcuaSup/open62541/README.md | 20 +++++- devOpcuaSup/open62541/install_open62541.sh | 71 ++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100755 devOpcuaSup/open62541/install_open62541.sh diff --git a/devOpcuaSup/open62541/README.md b/devOpcuaSup/open62541/README.md index ea4ef730..8de35b01 100644 --- a/devOpcuaSup/open62541/README.md +++ b/devOpcuaSup/open62541/README.md @@ -32,11 +32,24 @@ The Open62541 project is focused on the server implementation of OPC UA. The client functionality is fully supported, complete and usable, but it does not get the attention that the server parts get. +### On Linux + +#### Using the Install Script + +You can use the `install_open62541.sh` script to automate the build of the open62541 library. +The script will: + +1. Download an appropiate version of the `open62541` source code +2. Build `open62541` as a static library with security support +3. Create the corresponding `CONFIG_SITE.local` configuration + +**Please note**: This requires `curl`, `Cmake` and the `openssl-devel`/`libssl-dev` library to be present. + +#### Manual Way + Do *not* use the download link on the open62541 web site. Use their GitHub Release Page instead. -### On Linux - * Unpack the open62541 distribution. Create a build directory on the top level and `cd` into it. We'll use the usual convention of calling it `build` . * The cmake build of Open62541 creates a static library by default. This type of library is needed for the EMBED type of Device Support build (see below). @@ -135,7 +148,8 @@ See the [Windows Installation How-To][windows-howto] for an overview and introdu Inside the `configure` subdirectory or one level above the TOP location, create a file `RELEASE.local` that sets `EPICS_BASE` to the absolute path of your EPICS installation. -Inside the `configure` subdirectory or one level above the TOP location, create a file `CONFIG_SITE.local` that sets the absolute path of your Open62541 installation as well as its build and deploy features if necessary. +If you have not used the install script, +inside the `configure` subdirectory or one level above the TOP location, create a file `CONFIG_SITE.local` that sets the absolute path of your Open62541 installation as well as its build and deploy features if necessary. You also need to configure the locations of the other dependencies that you installed. ```Makefile diff --git a/devOpcuaSup/open62541/install_open62541.sh b/devOpcuaSup/open62541/install_open62541.sh new file mode 100755 index 00000000..98fdf3a7 --- /dev/null +++ b/devOpcuaSup/open62541/install_open62541.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# This script installs the open62541 library for OPC UA support in EPICS. +# It downloads the specified version of open62541, builds it, and configures the EPICS environment. +# It requires curl, cmake and openssl-dev to be installed on the system. +# +# Usage: ./install_open62541.sh [version] +# If no version is specified, a default version is defined in the script. + +# Default version of open62541 to use +DEFAULT_VERSION="1.3.15" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +OPEN62541_VERSION=${1:-$DEFAULT_VERSION} + +# Check if cmake and curl are available +if ! command -v cmake &> /dev/null || ! command -v curl &> /dev/null; then + echo "Error: cmake and/or curl is not installed. Please install them and try again." + exit 1 +fi + +# Download and extract open62541 if not already present +echo "Downloading open62541 version $OPEN62541_VERSION..." +curl -L -o "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" "https://github.com/open62541/open62541/archive/refs/tags/v$OPEN62541_VERSION.tar.gz" +if [ $? -ne 0 ]; then + echo "Error: Failed to download open62541 version $OPEN62541_VERSION." + exit 1 +fi +temp_dir="`mktemp -d -p "$SCRIPT_DIR"`" +echo "Extracting open62541 archive..." +mkdir -p "$SCRIPT_DIR/lib-open62541" +tar -xzf "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" -C "$temp_dir" --strip-components=1 +rm "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" + +echo "Building open62541..." +cmake \ + -S "$temp_dir" \ + -B "$temp_dir"/build \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_INSTALL_PREFIX="$SCRIPT_DIR"/lib-open62541 \ + -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \ + -DOPEN62541_VERSION="v$OPEN62541_VERSION" \ + -DUA_ENABLE_ENCRYPTION=OPENSSL +if [ $? -ne 0 ]; then + echo "Error: cmake configuration failed." + rm -rf "$temp_dir" + exit 1 +fi +make -C "$temp_dir"/build +if [ $? -ne 0 ]; then + echo "Error: make failed." + rm -rf "$temp_dir" + exit 1 +fi +make -C "$temp_dir"/build install +if [ $? -ne 0 ]; then + echo "Error: make install failed." + rm -rf "$temp_dir" + exit 1 +fi +rm -rf "$temp_dir" + +echo "Writing configuration to CONFIG_SITE.local..." +cat < "$SCRIPT_DIR/../../configure/CONFIG_SITE.local" +OPEN62541 = \$(TOP)/devOpcuaSup/open62541/lib-open62541 +OPEN62541_DEPLOY_MODE = EMBED +OPEN62541_USE_CRYPTO = YES +USR_CXXFLAGS += -std=c++11 +EOL + +echo "open62541 version $OPEN62541_VERSION installed successfully. You should now be able to build the OPC UA support in EPICS." From 9505ce058c458b1ff91a814a1382f63b9ea6da25 Mon Sep 17 00:00:00 2001 From: Edmund Blomley Date: Sun, 27 Apr 2025 07:45:13 +0200 Subject: [PATCH 2/4] Reworked build logic. - Use fixed build dir - Remove build and lib dir before starting - Remove build dir only on failure - Combine download and extraction --- devOpcuaSup/open62541/install_open62541.sh | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/devOpcuaSup/open62541/install_open62541.sh b/devOpcuaSup/open62541/install_open62541.sh index 98fdf3a7..56ea2d01 100755 --- a/devOpcuaSup/open62541/install_open62541.sh +++ b/devOpcuaSup/open62541/install_open62541.sh @@ -10,6 +10,8 @@ # Default version of open62541 to use DEFAULT_VERSION="1.3.15" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILD_DIR="$SCRIPT_DIR/temp_build" +LIB_DIR="$SCRIPT_DIR/lib-open62541" OPEN62541_VERSION=${1:-$DEFAULT_VERSION} # Check if cmake and curl are available @@ -18,23 +20,26 @@ if ! command -v cmake &> /dev/null || ! command -v curl &> /dev/null; then exit 1 fi +echo "Removing any existing build and library directory..." +rm -rf "$BUILD_DIR" +rm -rf "$LIB_DIR" + +mkdir -p "$BUILD_DIR" +mkdir -p "$LIB_DIR" + # Download and extract open62541 if not already present echo "Downloading open62541 version $OPEN62541_VERSION..." -curl -L -o "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" "https://github.com/open62541/open62541/archive/refs/tags/v$OPEN62541_VERSION.tar.gz" +curl -L "https://github.com/open62541/open62541/archive/refs/tags/v$OPEN62541_VERSION.tar.gz" \ + | tar -xz -C "$BUILD_DIR" --strip-components=1 if [ $? -ne 0 ]; then - echo "Error: Failed to download open62541 version $OPEN62541_VERSION." + echo "Error: Failed to download and unpack." exit 1 fi -temp_dir="`mktemp -d -p "$SCRIPT_DIR"`" -echo "Extracting open62541 archive..." -mkdir -p "$SCRIPT_DIR/lib-open62541" -tar -xzf "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" -C "$temp_dir" --strip-components=1 -rm "$SCRIPT_DIR/open62541-$OPEN62541_VERSION.tar.gz" echo "Building open62541..." cmake \ - -S "$temp_dir" \ - -B "$temp_dir"/build \ + -S "$BUILD_DIR" \ + -B "$BUILD_DIR"/build \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX="$SCRIPT_DIR"/lib-open62541 \ @@ -43,22 +48,19 @@ cmake \ -DUA_ENABLE_ENCRYPTION=OPENSSL if [ $? -ne 0 ]; then echo "Error: cmake configuration failed." - rm -rf "$temp_dir" exit 1 fi -make -C "$temp_dir"/build +make -C "$BUILD_DIR"/build if [ $? -ne 0 ]; then echo "Error: make failed." - rm -rf "$temp_dir" exit 1 fi -make -C "$temp_dir"/build install +make -C "$BUILD_DIR"/build install if [ $? -ne 0 ]; then echo "Error: make install failed." - rm -rf "$temp_dir" exit 1 fi -rm -rf "$temp_dir" +rm -rf "$BUILD_DIR" echo "Writing configuration to CONFIG_SITE.local..." cat < "$SCRIPT_DIR/../../configure/CONFIG_SITE.local" From 819daf369a9883d23b35d343d1f77562b489ef6c Mon Sep 17 00:00:00 2001 From: Edmund Blomley Date: Sun, 27 Apr 2025 07:46:56 +0200 Subject: [PATCH 3/4] Fix capitalization of cmake --- devOpcuaSup/open62541/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devOpcuaSup/open62541/README.md b/devOpcuaSup/open62541/README.md index 8de35b01..ea300df7 100644 --- a/devOpcuaSup/open62541/README.md +++ b/devOpcuaSup/open62541/README.md @@ -18,7 +18,7 @@ Please contact the authors (v1.2 and v1.3 series have been tested; their system packages should also work. open62541 v1.4 changed the header file structure and does not work yet.) -* Cmake (3.x) if you're building Open62541 from sources. +* cmake (3.x) if you're building Open62541 from sources. * For OPC UA security support (authentication/encryption), we suggest using the openssl plugin for Open62541. For that to work, you need openssl on your system - both when compiling the client library and when generating any binaries (IOCs). On Linux, the name of the package you have to install depends on the distribution: development packages are called `openssl-devel` on RedHat/CentOS/Fedora and `libssl-dev` on Debian/Ubuntu, runtime packages are called `openssl` on RedHat/CentOS/Fedora and `libssl` on Debian/Ubuntu, respectively. @@ -43,7 +43,7 @@ The script will: 2. Build `open62541` as a static library with security support 3. Create the corresponding `CONFIG_SITE.local` configuration -**Please note**: This requires `curl`, `Cmake` and the `openssl-devel`/`libssl-dev` library to be present. +**Please note**: This requires `curl`, `cmake` and the `openssl-devel`/`libssl-dev` library to be present. #### Manual Way From a0cbec275f259039475a29bc5ebbed89f1cc44b1 Mon Sep 17 00:00:00 2001 From: Edmund Blomley Date: Sun, 27 Apr 2025 07:59:12 +0200 Subject: [PATCH 4/4] Add mention of `libxml2` dev files and add to local config. --- devOpcuaSup/open62541/README.md | 3 ++- devOpcuaSup/open62541/install_open62541.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/devOpcuaSup/open62541/README.md b/devOpcuaSup/open62541/README.md index ea300df7..3610af1b 100644 --- a/devOpcuaSup/open62541/README.md +++ b/devOpcuaSup/open62541/README.md @@ -43,7 +43,8 @@ The script will: 2. Build `open62541` as a static library with security support 3. Create the corresponding `CONFIG_SITE.local` configuration -**Please note**: This requires `curl`, `cmake` and the `openssl-devel`/`libssl-dev` library to be present. +**Please note**: This requires `curl`, `cmake` and the `openssl-devel`/`libssl-dev` library to be present. For support of structures also `libxml2-devel` / `libxml2-dev` +is required. #### Manual Way diff --git a/devOpcuaSup/open62541/install_open62541.sh b/devOpcuaSup/open62541/install_open62541.sh index 56ea2d01..4493aab7 100755 --- a/devOpcuaSup/open62541/install_open62541.sh +++ b/devOpcuaSup/open62541/install_open62541.sh @@ -67,6 +67,7 @@ cat < "$SCRIPT_DIR/../../configure/CONFIG_SITE.local" OPEN62541 = \$(TOP)/devOpcuaSup/open62541/lib-open62541 OPEN62541_DEPLOY_MODE = EMBED OPEN62541_USE_CRYPTO = YES +OPEN62541_USE_XMLPARSER = YES USR_CXXFLAGS += -std=c++11 EOL