forked from open62541/open62541-nodeset-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (144 loc) · 6.23 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.0)
project(nodesetLoader)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(ENABLE_CONAN "use conan for consuming dependencies" on)
option(ENABLE_TESTING "enable tests" off)
option(ENABLE_BACKEND_OPEN62541 "backend for open62541" off)
option(ENABLE_ASAN "build with address sanitizer enabled" off)
option(ENABLE_INTEGRATION_TEST "run detailled tests to compare address spaces" off)
option(ENABLE_DATATYPEIMPORT_TEST "run tests for importing datatypes" off)
option(CALC_COVERAGE "calculate code coverage" off)
option(USE_MEMBERTYPE_INDEX "necessary for open62541 backend with version <= 1.2.x" ON)
if(${ENABLE_CONAN})
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP
CMAKE_TARGETS
BUILD missing)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
endif()
#link against this library to gather coverage info
add_library(coverageLib INTERFACE)
if(${CALC_COVERAGE})
#set(GCOV_COMPILE_OPTIONS -g -O0 -fno-inline -fno-inline-small-functions -fno-default-inline -fprofile-arcs -ftest-coverage)
message(STATUS "Code coverage is enabled.")
# Note that --coverage is synonym for the necessary compiler and
# linker flags for the given compiler. For example, with GCC,
# --coverage translates to -fprofile-arcs -ftest-coverage when
# compiling and -lgcov when linking
#add_compile_options(--coverage -O0)
#add_link_options(--coverage)
target_compile_options(coverageLib INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags)
)
target_link_libraries(coverageLib INTERFACE --coverage)
endif()
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX /w44996") # Compiler warnings, error on warning
endif()
if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
set(C_COMPILE_DEFS -std=c99 -pipe -Wall -Wextra -Wpedantic -Werror
-Wno-unused-parameter
-Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls
-Wformat -Wformat-security -Wformat-nonliteral
-Wuninitialized -Winit-self
-Wcast-qual
-Wstrict-overflow
-Wnested-externs
-Wmultichar
-Wundef
-Wc++-compat
-Wsign-conversion
-Wconversion
-Wshadow
-fexceptions
-Wswitch-enum)
set(PTHREAD_LIB pthread)
endif()
if(${ENABLE_BACKEND_OPEN62541})
find_package(open62541 REQUIRED)
if(open62541_VERSION VERSION_LESS "1.3")
set(open62541_NODESET_BASE_DIR "${open62541_NODESET_DIR}")
else()
set(open62541_NODESET_BASE_DIR "${UA_NODESET_DIR}")
endif()
endif()
find_package(LibXml2 REQUIRED)
add_library(NodesetLoader
src/NodesetLoader.c
src/Sort.c
src/Nodeset.c
src/CharAllocator.c
src/AliasList.c
src/NamespaceList.c
src/nodes/Node.c
src/nodes/DataTypeNode.c
src/nodes/NodeContainer.c
src/nodes/InstanceNode.c
src/NodeId.c
src/PrintfLogger.c
src/Value.c
src/InternalRefService.c
src/Parser.c)
target_include_directories(NodesetLoader
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${LIBXML2_INCLUDE_DIRS})
target_link_libraries(NodesetLoader PRIVATE ${LIBXML2_LIBRARIES})
if(${CALC_COVERAGE})
target_link_libraries(NodesetLoader PUBLIC coverageLib)
endif()
if(${ENABLE_BACKEND_OPEN62541})
target_include_directories(NodesetLoader PRIVATE open62541::open62541)
target_link_libraries(NodesetLoader PRIVATE open62541::open62541)
if(${USE_MEMBERTYPE_INDEX})
target_compile_definitions(NodesetLoader PUBLIC -DUSE_MEMBERTYPE_INDEX=1)
endif()
endif()
target_compile_options(NodesetLoader PRIVATE ${C_COMPILE_DEFS})
set_target_properties(NodesetLoader PROPERTIES C_VISIBILITY_PRESET hidden)
if(${ENABLE_ASAN})
target_link_libraries(NodesetLoader INTERFACE "-g -fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope -fsanitize-coverage=trace-pc-guard,trace-cmp -fsanitize=leak -fsanitize=undefined")
endif()
if(ENABLE_TESTING)
find_package(Check REQUIRED)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
add_subdirectory(backends)
if(${CALC_COVERAGE})
add_subdirectory(coverage)
endif()
#install
if(NOT ${CALC_COVERAGE})
set(NODESETLOADER_PUBLIC_HEADER
${PROJECT_SOURCE_DIR}/include/NodesetLoader/NodesetLoader.h
${PROJECT_SOURCE_DIR}/include/NodesetLoader/NodeId.h
${PROJECT_SOURCE_DIR}/include/NodesetLoader/Logger.h
${PROJECT_SOURCE_DIR}/include/NodesetLoader/arch.h
${PROJECT_SOURCE_DIR}/include/NodesetLoader/ReferenceService.h
${PROJECT_SOURCE_DIR}/include/NodesetLoader/Extension.h
)
if(${ENABLE_BACKEND_OPEN62541})
list(APPEND NODESETLOADER_PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/backends/open62541/include/NodesetLoader/backendOpen62541.h)
list(APPEND NODESETLOADER_PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/backends/open62541/include/NodesetLoader/dataTypes.h)
endif()
set_target_properties(NodesetLoader PROPERTIES PUBLIC_HEADER "${NODESETLOADER_PUBLIC_HEADER}")
install(TARGETS NodesetLoader
EXPORT NodesetLoader
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION include/NodesetLoader)
install(FILES nodesetloader-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NodesetLoader)
install(EXPORT NodesetLoader DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/NodesetLoader)
endif()