-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
207 lines (175 loc) · 9.15 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
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
# LICENSE:
# Copyright (c) 2016, Piotr Nikiel, CERN
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Authors:
# Piotr Nikiel <piotr@nikiel.info>
# Ben Farnham <firstNm.secondNm@cern.ch>
project(open62541-compat LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.3)
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0057 NEW) # enables IN_LIST operator
include (cmake/Open62541CompatFetchContent.cmake)
option(PULL_OPEN62541 "Pull open62541 from their github instead of using the bundled one (not recommended!)" OFF)
option(STANDALONE_BUILD "Build it as a stand-alone library instead of for Quasar" OFF )
option(STANDALONE_BUILD_SHARED "When building in stand-alone, build shared library rather than static library" OFF)
option(SKIP_TESTS "do not build the tests (not advised)" OFF)
message(STATUS "STANDALONE_BUILD [${STANDALONE_BUILD}] STANDALONE_BUILD_SHARED [${STANDALONE_BUILD_SHARED}]")
# "OPEN62541_VERSION" will be used only if you use PULL_OPEN62541
SET (OPEN62541_VERSION "v1.0" CACHE STRING "Which open62541 commit/tag/branch to take")
option (UA_ENABLE_AMALGAMATION "Whether open62541 should amalgamate" ON )
option (UA_ENABLE_METHODCALLS "Whether open62541 should have methods enabled" ON )
option (SERVERCONFIG_LOADER "Whether we should support ServerConfig.xml loading, resembling UA-SDK" OFF )
if(${PULL_OPEN62541})
function ( fetch_open62541 )
message(STATUS "fetching open62541 from github. *NOTE* fetching tag [${OPEN62541_VERSION}]")
Open62541CompatFetchContent_Declare(
open62541
GIT_REPOSITORY https://github.com/open62541/open62541.git
GIT_TAG ${OPEN62541_VERSION}
GIT_SHALLOW "1"
SOURCE_DIR ${PROJECT_BINARY_DIR}/open62541
BINARY_DIR ${PROJECT_BINARY_DIR}/open62541
)
Open62541CompatFetchContent_Populate( open62541 )
message(STATUS "open62541 fetched")
endfunction()
function ( build_open62541 )
message(STATUS "generating platform specific build for open62541 library for [${CMAKE_GENERATOR}]")
add_subdirectory( ${PROJECT_BINARY_DIR}/open62541
${PROJECT_BINARY_DIR}/open62541
EXCLUDE_FROM_ALL # EXCLUDE_FROM_ALL will not add install() targets from open62541 which we clearly don't want/need
)
set_target_properties( open62541 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/open62541 )
endfunction()
endif(${PULL_OPEN62541})
SET( SRCS
src/nodemanagerbase.cpp
src/open62541_compat.cpp
src/uabytestring.cpp
src/uastring.cpp
src/uavariant.cpp
src/uadatavariablecache.cpp
src/statuscode.cpp
src/uanodeid.cpp
src/uadatavalue.cpp
src/uadatetime.cpp
src/uabytearray.cpp
src/opcua_basedatavariabletype.cpp
src/uaserver.cpp
src/logit_logger.cpp
src/uaclient/uasession.cpp
)
if(NOT ${PULL_OPEN62541}) # this is the default behaviour
include_directories(extern/open62541/include)
list(APPEND SRCS extern/open62541/src/open62541.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DUA_ARCHITECTURE_POSIX -Werror -Wall -Wextra -Wpedantic -Wno-static-in-inline -Wno-overlength-strings -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 -fno-strict-aliasing -fexceptions -fstack-protector-strong -Wno-unused-function -Wshadow -Wconversion -fvisibility=hidden")
endif(NOT ${PULL_OPEN62541})
if(${PULL_OPEN62541}) # this is not default
fetch_open62541()
build_open62541()
set(OPEN62541_SDK_LIB -lopen62541)
endif(${PULL_OPEN62541})
add_definitions(-DNOMINMAX) # doesn't include windows' min() and max() which break std c++ code. Should be neutral to non-windows code.
if(SERVERCONFIG_LOADER)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/ServerConfig.cxx ${PROJECT_BINARY_DIR}/ServerConfig.hxx
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND xsdcxx cxx-tree --namespace-map http://cern.ch/quasar/ServerConfig=ServerConfig --output-dir ${PROJECT_BINARY_DIR} --std c++11 ${PROJECT_SOURCE_DIR}/xsd/ServerConfig.xsd
DEPENDS xsd/ServerConfig.xsd
)
include_directories( ${PROJECT_BINARY_DIR} )
set(SRCS ${SRCS} ${PROJECT_BINARY_DIR}/ServerConfig.cxx)
add_definitions(-DHAS_SERVERCONFIG_LOADER)
endif(SERVERCONFIG_LOADER)
if(NOT STANDALONE_BUILD)
add_library ( open62541-compat OBJECT ${SRCS} )
if(${PULL_OPEN62541}) # fetching open62541 (NOT default)
add_custom_target( quasar_opcua_backend_is_ready DEPENDS open62541-compat )
else(${PULL_OPEN62541}) # using bundled open62541 (default)
add_custom_target( quasar_opcua_backend_is_ready ) # ready anytime basically.
endif(${PULL_OPEN62541})
else()
# We need some C++11 (via cmake platform agnostic flag)
set(CMAKE_CXX_STANDARD 11)
if( NOT WIN32 )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-literal-suffix" ) # gcc specific flags
endif()
#
# Decide on open62541-compat build output (shared/static)
#
if (STANDALONE_BUILD_SHARED)
set(OPEN62541_COMPAT_LIB_FORMAT SHARED)
add_definitions(-fPIC)
else()
set(OPEN62541_COMPAT_LIB_FORMAT STATIC)
endif()
include_directories( include )
include_directories( ${PROJECT_BINARY_DIR}/open62541 )
#
# Load stand-alone build toolchain file (used for defining build-specific boost (BOOST_LIBS), amongst other things)
#
if(DEFINED OPEN62541-COMPAT_BUILD_CONFIG_FILE)
message("OPEN62541-COMPAT_BUILD_CONFIG_FILE is defined -- including [[${OPEN62541-COMPAT_BUILD_CONFIG_FILE}]]")
include(${OPEN62541-COMPAT_BUILD_CONFIG_FILE})
endif()
if( NOT DEFINED BOOST_LIBS)
# try to resolve using find_package
set(Boost_NO_BOOST_CMAKE ON)
find_package(Boost REQUIRED system chrono date_time thread program_options)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Failed to find boost installation. Install it (dev packages), if necessary make sure that BOOST_ROOT is exported, or use a dedicated build config file (some of which are attached to open62541-compat repository, e.g. boost_standard_install_cc7")
else()
message(STATUS "Found system boost, version [${Boost_VERSION}], include dir [${Boost_INCLUDE_DIRS}] library dir [${Boost_LIBRARY_DIRS}], libs [${Boost_LIBRARIES}]")
include_directories( ${Boost_INCLUDE_DIRS} )
set( BOOST_LIBS ${Boost_LIBRARIES} )
endif()
endif()
message(STATUS "Using boost libraries: BOOST_LIBS [${BOOST_LIBS}]")
include (LogIt.cmake)
process_LogIt()
message(STATUS "After process_LogIt, LOGIT_TARGET_OBJECTS=${LOGIT_TARGET_OBJECTS}")
link_directories(
${PROJECT_BINARY_DIR}/open62541
${PROJECT_BINARY_DIR}/open62541/build
${PROJECT_BINARY_DIR}/open62541/Release/
${PROJECT_BINARY_DIR}/open62541/Debug/ )
add_library( open62541-compat ${OPEN62541_COMPAT_LIB_FORMAT} ${SRCS} ${LOGIT_TARGET_OBJECTS} )
#
# Set required libs, note windows build requires winsock.
#
target_link_libraries( open62541-compat ${BOOST_LIBS} ${OPEN62541_SDK_LIB} ${LOGITLIB})
if(WIN32)
target_link_libraries( open62541-compat ws2_32 )
endif()
#
# Build unit tests (googletest). For the moment only build unit tests in stand-alone mode
# until such time as the quasar framework has a comprehensive strategy for testing optional
# modules.
#
if( NOT SKIP_TESTS )
add_subdirectory( ${PROJECT_SOURCE_DIR}/test )
else()
message( STATUS "explicitly requested not to build unit tests!" )
endif()
add_subdirectory(examples)
endif()
if(${PULL_OPEN62541}) # this is not default
add_dependencies( open62541-compat open62541 )
endif(${PULL_OPEN62541})
install(TARGETS open62541-compat DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
if(NOT ${PULL_OPEN62541}) # this is the default behaviour
install(FILES extern/open62541/include/open62541.h DESTINATION include)
endif (NOT ${PULL_OPEN62541}) # this is the default behaviour