forked from systerel/S2OPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·120 lines (110 loc) · 4.21 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# Licensed to Systerel under one or more contributor license
# agreements. See the NOTICE file distributed with this work
# for additional information regarding copyright ownership.
# Systerel licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Script to build the S2OPC project:
#
# Options:
# - Variable CMAKE_TOOLCHAIN_FILE set with filename of toolchain config in root directory
# - Variable BUILD_SHARED_LIBS set to compile the shared library instead of static one
# - Variable CMAKE_INSTALL_PREFIX set to configure the install prefix of cmake
#
# Steps:
# - generate build information
# - configure build with cmake
# - build the library and tests
# - prepare test execution
CURDIR=`pwd`
EXEC_DIR=bin
set -e
if [[ $CMAKE_TOOLCHAIN_FILE ]]; then
BUILD_DIR=${BUILD_DIR:-build_toolchain}
else
BUILD_DIR=${BUILD_DIR:-build}
fi
# Check if the option which name is $1 is defined in env,
# and adds it and its value to CMAKE_OPTIONS
# else add default value defined in $2.
append_cmake_option ()
{
if [[ -n "${!1}" ]]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS -D$1=${!1}"
elif [[ -n "$2" ]]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS -D$1=$2"
fi
}
echo "Build log" > $CURDIR/build.log
echo "Build the library and tests with CMake" | tee -a $CURDIR/build.log
if [ -f "$BUILD_DIR/CMakeCache.txt" ]; then
echo "- CMake already configured" | tee -a $CURDIR/build.log
else
echo "- Generate ./$BUILD_DIR directory" | tee -a $CURDIR/build.log
mkdir -p $BUILD_DIR || exit 1
cd $BUILD_DIR > /dev/null || exit 1
echo "- Run CMake" | tee -a $CURDIR/build.log
append_cmake_option S2OPC_NANO_PROFILE
append_cmake_option S2OPC_NODE_MANAGEMENT
append_cmake_option S2OPC_EVENT_MANAGEMENT
append_cmake_option CMAKE_TOOLCHAIN_FILE
append_cmake_option BUILD_SHARED_LIBS
append_cmake_option CMAKE_INSTALL_PREFIX
append_cmake_option WITH_ASAN
append_cmake_option WITH_UBSAN
append_cmake_option WITH_TSAN
append_cmake_option WITH_COVERAGE
append_cmake_option WITH_COVERITY
append_cmake_option WITH_PYS2OPC
append_cmake_option WITH_CONST_ADDSPACE
append_cmake_option WITH_STATIC_SECURITY_DATA
append_cmake_option WITH_NO_ASSERT
append_cmake_option WITH_USER_ASSERT
append_cmake_option WITH_MINIMAL_FOOTPRINT
append_cmake_option WARNINGS_AS_ERRORS
append_cmake_option PUBSUB_STATIC_CONFIG
append_cmake_option CMAKE_BUILD_TYPE RelWithDebInfo
append_cmake_option CMAKE_EXE_LINKER_FLAGS
append_cmake_option S2OPC_CRYPTO_MBEDTLS
append_cmake_option S2OPC_CRYPTO_CYCLONE
append_cmake_option S2OPC_CLIENTSERVER_ONLY
append_cmake_option S2OPC_PUBSUB_ONLY
append_cmake_option ENABLE_TESTING
append_cmake_option ENABLE_SAMPLES
append_cmake_option USE_STATIC_EXT_LIBS
append_cmake_option POSITION_INDEPENDENT_EXECUTABLE
append_cmake_option SECURITY_HARDENING
append_cmake_option PYS2OPC_WHEEL_NAME
append_cmake_option WITH_GCC_STATIC_ANALYSIS
# append_cmake_option doesn't permit to handle multiple variables because of multiple evaluations of quotes
echo "cmake $CMAKE_OPTIONS -DCMAKE_C_FLAGS=\"$CMAKE_C_FLAGS\" .." >> $CURDIR/build.log
cmake $CMAKE_OPTIONS -DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" .. >> $CURDIR/build.log
cd - > /dev/null || exit 1
fi
if [[ $? != 0 ]]; then
echo "Error: build configuration failed" | tee -a $CURDIR/build.log
exit 1
fi
echo "- Run make" | tee -a $CURDIR/build.log
make -j $(nproc) -C $BUILD_DIR >> $CURDIR/build.log
if [[ $? != 0 ]]; then
echo "Error: build failed" | tee -a $CURDIR/build.log
exit 1
else
echo "Built library and tests with success" | tee -a $CURDIR/build.log
fi
if [[ $? == 0 ]]; then
echo "Completed with SUCCESS" | tee -a $CURDIR/build.log
exit 0
fi