forked from open62541pp/open62541pp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
313 lines (282 loc) · 9.87 KB
/
CMakeLists.txt
File metadata and controls
313 lines (282 loc) · 9.87 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
cmake_minimum_required(VERSION 3.12)
project(
open62541pp
VERSION 0.19.0
DESCRIPTION "C++ wrapper of open62541"
HOMEPAGE_URL "https://github.com/open62541pp/open62541pp"
LANGUAGES CXX
)
# set c++ standard explicitly, compile feature "cxx_std_17" does not set -std=c++17 compile flag
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# compiled binaries folders (same as open62541)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_library(open62541pp_project_options INTERFACE)
target_compile_features(open62541pp_project_options INTERFACE cxx_std_17)
option(UAPP_ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" OFF)
option(UAPP_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
target_compile_options(open62541pp_project_options INTERFACE
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-Wpedantic
$<$<BOOL:${UAPP_WARNINGS_AS_ERRORS}>:-Werror>
)
if(UAPP_ENABLE_COVERAGE)
target_compile_options(open62541pp_project_options INTERFACE --coverage -O0 -g)
target_link_libraries(open62541pp_project_options INTERFACE --coverage)
endif()
elseif(MSVC)
target_compile_options(open62541pp_project_options INTERFACE
/permissive-
/W4
/w14640
/wd4127 # conditional expression is constant
/wd4661 # explicit template instantiations in cpp files
/wd4702 # unreachable code, false positive
/wd4996 # deprecation gmtime, localtime
$<$<BOOL:${UAPP_WARNINGS_AS_ERRORS}>:/WX>
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(sanitizers "")
foreach(san IN ITEMS address leak undefined thread)
string(TOUPPER ${san} san_upper)
option(UAPP_ENABLE_SANITIZER_${san_upper} "Enable ${san} sanitizer" OFF)
if(UAPP_ENABLE_SANITIZER_${san_upper})
list(APPEND sanitizers ${san})
endif()
endforeach()
list(JOIN sanitizers "," sanitizers_joined)
if(sanitizers_joined)
message(STATUS "Sanitizers enabled: ${sanitizers_joined}")
target_compile_options(open62541pp_project_options INTERFACE -fsanitize=${sanitizers_joined})
target_link_options(open62541pp_project_options INTERFACE -fsanitize=${sanitizers_joined})
endif()
endif()
option(UAPP_ENABLE_CLANG_TIDY "Enable static analysis with clang-tidy" OFF)
if(UAPP_ENABLE_CLANG_TIDY)
message(STATUS "Static code analysis with clang-tidy enabled")
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
if(CLANG_TIDY_EXE)
message(STATUS "Found clang-tidy: ${CLANG_TIDY_EXE}")
if(UAPP_WARNINGS_AS_ERRORS)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-warnings-as-errors=*")
else()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
endif()
else()
message(SEND_ERROR "clang-tidy requested but executable not found")
endif()
endif()
# threads
find_package(Threads REQUIRED)
# open62541
option(UAPP_INTERNAL_OPEN62541 "Use internal open62541 library" ON)
if(UAPP_INTERNAL_OPEN62541)
# disable IPO if not defined, otherwise open62541 will enable it
# IPO increases link times, especially with sanitizers enabled
if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
endif()
# overwrite default open62541 options
# disable sanitizers in debug build (> v1.3)
if (NOT UA_ENABLE_DEBUG_SANITIZER)
set(UA_ENABLE_DEBUG_SANITIZER OFF CACHE BOOL "")
mark_as_advanced(UA_ENABLE_DEBUG_SANITIZER)
endif()
# disable sanitizers in debug build (<= v1.3) WORKAROUND
# https://github.com/open62541/open62541/blob/v1.3.5/CMakeLists.txt#L753-L764
if (NOT UA_ENABLE_UNIT_TESTS_MEMCHECK)
set(UA_ENABLE_UNIT_TESTS_MEMCHECK ON CACHE BOOL "")
mark_as_advanced(UA_ENABLE_UNIT_TESTS_MEMCHECK)
endif()
# disable warnings as errors for open62541
if(NOT UA_FORCE_WERROR)
set(UA_FORCE_WERROR OFF OFF CACHE BOOL "")
endif()
add_subdirectory(3rdparty/open62541) # target open62541::open62541
else()
find_package(open62541 REQUIRED)
endif()
# enable IPO if open62541 is compiled with IPO
get_target_property(open62541_ipo open62541::open62541 INTERPROCEDURAL_OPTIMIZATION)
if(open62541_ipo)
message(STATUS "IPO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
else()
message(STATUS "IPO not enabled")
endif()
# Print Alarms & Conditions feature flag from open62541
if(DEFINED UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)
if(UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)
message(STATUS "open62541 A&C support: ON (UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)")
else()
message(STATUS "open62541 A&C support: OFF (UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)")
endif()
else()
message(STATUS "open62541 A&C support: not defined (UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)")
endif()
# open62541pp library (static/shared depending on option BUILD_SHARED_LIBS)
include(GNUInstallDirs)
configure_file(
include/open62541pp/config.hpp.in
${PROJECT_BINARY_DIR}/include_generated/open62541pp/config.hpp
)
function(deprecated_header header_old header_new)
configure_file(
${PROJECT_SOURCE_DIR}/include/open62541pp/deprecated.hpp.in
${PROJECT_BINARY_DIR}/include_generated/open62541pp/${header_old}
)
endfunction()
deprecated_header(nodeids.hpp ua/nodeids.hpp)
deprecated_header(types_composed.hpp ua/types.hpp)
deprecated_header(typewrapper.hpp wrapper.hpp)
add_library(
open62541pp
src/callback.cpp
src/client.cpp
src/datatype.cpp
src/event.cpp
src/monitoreditem.cpp
src/node.cpp
src/plugin/accesscontrol.cpp
src/plugin/accesscontrol_default.cpp
src/plugin/create_certificate.cpp
src/plugin/log.cpp
src/plugin/nodesetloader.cpp
src/plugin/nodestore.cpp
src/server.cpp
src/services_attribute.cpp
src/services_method.cpp
src/services_monitoreditem.cpp
src/services_nodemanagement.cpp
src/services_subscription.cpp
src/services_view.cpp
src/session.cpp
src/string_utils.cpp
src/subscription.cpp
src/types.cpp
src/ua_types.cpp
)
add_library(open62541pp::open62541pp ALIAS open62541pp)
target_include_directories(
open62541pp
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include_generated>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(
open62541pp
PUBLIC
open62541::open62541
PRIVATE
Threads::Threads
$<BUILD_INTERFACE:open62541pp_project_options>
)
# open62541-nodeset-loader
option(UAPP_ENABLE_NODESETLOADER "Enable nodeset loader" OFF)
if(UAPP_ENABLE_NODESETLOADER)
# variable OPEN62541_VERSION required by open62541-nodeset-loader
get_target_property(OPEN62541_VERSION open62541::open62541 VERSION)
set(NODESETLOADER_ENABLE_BUILD_INTO_OPEN62541 ON CACHE BOOL "")
add_subdirectory(3rdparty/open62541-nodeset-loader EXCLUDE_FROM_ALL)
# build and link as object library
enable_language(C)
add_library(open62541pp_nodesetloader OBJECT ${NODESETLOADER_SOURCES})
target_include_directories(
open62541pp_nodesetloader
PUBLIC
${NODESETLOADER_PUBLIC_INCLUDES}
PRIVATE
${NODESETLOADER_PRIVATE_INCLUDES}
)
target_link_libraries(
open62541pp_nodesetloader
PUBLIC
open62541::open62541
PRIVATE
${NODESETLOADER_DEPS_LIBS}
)
target_compile_definitions(
open62541pp_nodesetloader
PUBLIC
NODESETLOADER_CLEANUP_CUSTOM_DATATYPES=1
)
set_target_properties(
open62541pp_nodesetloader
PROPERTIES
C_VISIBILITY_PRESET hidden
POSITION_INDEPENDENT_CODE ON # required for shared library
)
target_link_libraries(open62541pp PRIVATE $<BUILD_INTERFACE:open62541pp_nodesetloader>)
endif()
# tests
option(UAPP_BUILD_TESTS "Build unit tests" OFF)
if(UAPP_BUILD_TESTS)
message(STATUS "Unit tests enabled")
enable_testing()
add_subdirectory(tests)
endif()
# examples
option(UAPP_BUILD_EXAMPLES "Build examples" OFF)
if(UAPP_BUILD_EXAMPLES)
message(STATUS "Examples enabled")
add_subdirectory(examples)
endif()
# documentation
option(UAPP_BUILD_DOCUMENTATION "Build documentation" OFF)
if(UAPP_BUILD_DOCUMENTATION)
message(STATUS "Documentation enabled")
add_subdirectory(doc)
endif()
# install targets
install(
TARGETS open62541pp
EXPORT open62541ppTargets
)
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
install(
DIRECTORY "${PROJECT_BINARY_DIR}/include_generated/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
)
# install cmake config files
install(
EXPORT open62541ppTargets
NAMESPACE open62541pp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/open62541pp
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/open62541ppConfig.cmake.in"
"${PROJECT_BINARY_DIR}/open62541ppConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/open62541pp
)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/open62541ppConfigVersion.cmake"
VERSION ${CMAKE_PROJECT_VERSION}
COMPATIBILITY SameMinorVersion
)
install(
FILES
"${PROJECT_BINARY_DIR}/open62541ppConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/open62541ppConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/open62541pp
)