forked from telefonicaid/fiware-orion
-
Notifications
You must be signed in to change notification settings - Fork 43
/
CMakeLists.txt
416 lines (377 loc) · 13.9 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
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U
#
# This file is part of Orion Context Broker.
#
# Orion Context Broker is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Orion Context Broker is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/.
#
# For those usages not covered by this license please contact with
# iot_support at tid dot es
#
# Project name and basic prerequisities
#
PROJECT(orionld)
cmake_minimum_required(VERSION 3.5)
find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread filesystem system regex)
pkg_check_modules(LIBMONGOC REQUIRED libmongoc-1.0)
pkg_check_modules(LIBBSON REQUIRED libbson-1.0)
pkg_check_modules(LIBMICROHTTPD REQUIRED libmicrohttpd)
pkg_check_modules(GNUTLS REQUIRED gnutls)
#
# DEBUG or RELEASE build ?
#
if (NOT CMAKE_BUILD_TYPE)
MESSAGE("CMAKE_BUILD_TYPE not set - setting it to RELEASE")
SET (CMAKE_BUILD_TYPE "RELEASE")
else (NOT CMAKE_BUILD_TYPE)
MESSAGE("CMAKE_BUILD_TYPE set to ${CMAKE_BUILD_TYPE}")
endif (NOT CMAKE_BUILD_TYPE)
set(error 0)
execute_process(COMMAND echo $USER
COMMAND tr 'a-z' 'A-Z'
OUTPUT_VARIABLE USER)
if (NOT DISTRO)
execute_process(COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/build/osDistro.sh
OUTPUT_VARIABLE DISTRO)
endif (NOT DISTRO)
# TRACES: To remove LM_T
# [ and 15 log macros more, of which only LM_T is used by the broker.
# The important ones: LM_W, LM_E, LM_X, LM_I are all kept as is ]
# comment the following line
add_definitions(-DLM_ON)
add_definitions(-DORIONLD)
add_definitions(-fPIC)
add_definitions(-std=c++17)
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
# Baseline compiler flags, any change here will affect all build types
#
# Compile RELEASE optimized for size, not speed
#
# set (CMAKE_CXX_FLAGS_RELEASE "-Os")
#
# FIXME P4: https://github.com/telefonicaid/fiware-orion/issues/2979
# 'template class std::auto_ptr' is deprecated in gcc 6.3.0 of Ubuntu 17.04, so -Werror cannot be used alone, at least not for now.
#
# The *real* fix would be to rewrite the part of the code producing these warnings, but for now,
# disabling the -Werror flag makes the problem go away (warnings will still be found and give errors in other distros).
#
# One example of this warning (there are many warnings, but as in header files, just a few places):
#
# mongoBackend/safeMongo.h:
# ----------------------------------------------------------------
# extern bool nextSafeOrError
# (
# const std::auto_ptr<mongo::DBClientCursor>& cursor,
# ...
# ----------------------------------------------------------------
#
# A grep of 'std::auto_ptr<' in the header files show 7 hits, and 13 hits in cpp files
#
# In PR https://github.com/telefonicaid/fiware-orion/pull/3069, a workaround for Ubuntu is implemented.
# This workaround consists of putting back the -Werror flag and instead solving the problem by
# adding another flag: -Wno-deprecated-declarations
#
IF (${DISTRO} MATCHES "Ubuntu_17.*")
set (CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -Werror -Wno-deprecated-declarations -fno-var-tracking-assignments")
ELSEIF (${DISTRO} MATCHES "Ubuntu_18.*")
set (CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -Werror -Wno-deprecated-declarations -fno-var-tracking-assignments")
ELSEIF (${DISTRO} MATCHES "Debian_9.*")
set (CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -Werror -Wno-deprecated-declarations -fno-var-tracking-assignments")
ELSEIF (${DISTRO} MATCHES "RedHat_8.*")
set (CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -DREDHAT_UBI=8.4 -D_GNU_SOURCE -Werror -Wno-deprecated-declarations -fno-var-tracking-assignments")
ELSE()
set (CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -Werror -Wno-deprecated-declarations -Wno-psabi -fno-var-tracking-assignments")
ENDIF ()
#
# Platform checks
#
MESSAGE( "Compiling in system ${CMAKE_SYSTEM}")
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ADD_DEFINITIONS(-DLINUX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLINUX")
ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
MESSAGE("CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}'")
if (${CMAKE_BUILD_TYPE} STREQUAL DEBUG)
MESSAGE("cmake: DEBUG compilation")
add_definitions(-DDEBUG -DDEBUG_$ENV{USER} -DDEBUG_${USER})
#
# OLD:
# Note that stack protection is activated only in debug compilation.
# This is due that this directive makes the compiler introduce code at the beginning/end of each functions,
# so it has a pretty big impact on performance
#
# Our unit tests don't pass the compilation with "stack protection", so we turn it off using
# remove_definitions().
#
#add_definitions(-fstack-check -fstack-protector)
add_definitions(-fstack-protector)
#
# NEW:
# The option -fstack-check makes valgrind report false positives (millions) in CentOS 6.
# This makes the output impossible to use and we have decided to remove these two options (both of them).
# The cause seems to be a bug in the compiler (gcc 4.4.7), fixed in some moment between that version
# and gcc 4.7.2 (see https://stackoverflow.com/questions/44758939/unexpected-valgrind-invalid-write-when-fstack-check-is-used
# for more detail). However, we don't want to use a compiler that is not meant for CentOS 6,
# which is the official distro for the context broker, so, we simply remove this option.
# They may be reinstated once Orion context broker updates the official distro to be CentOS 7 (which uses gcc 4.8.5)
#
if (COVERAGE)
MESSAGE("cmake: Coverage compilation")
# LM_T macros introduce condition branchs which are not never traversed. Removing LM_T macros doesn't have
# any impact in line coverage but removes "noise" in condition coverage, thus making coverage reports more useful
remove_definitions(-DLM_ON)
# Removing LM_T macros make that some variables get unused, thus -Wno-unused-variable have to be used
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -fprofile-arcs -ftest-coverage")
set (CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
endif (COVERAGE)
if (UNIT_TEST)
add_definitions( -DUNIT_TEST )
endif (UNIT_TEST)
else (${CMAKE_BUILD_TYPE} STREQUAL DEBUG)
MESSAGE("cmake: RELEASE compilation")
if (STRICT)
MESSAGE("cmake: Strict compilation")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif (STRICT)
endif (${CMAKE_BUILD_TYPE} STREQUAL DEBUG)
# -Wunused-but-set-variable is available from gcc 4.6.0 but can be set in 4.5.x
# OS X comes with gcc 4.2.1 (10.7) and does not accept this flag
#
# no-unused-but-set-variable (commented, not active):
# if the following piece of 'compiler directives' is uncommented, we no longer get warnings for
# variables that are defined but not used.
# For now we want these warnings as we desire as strict compilaton as possible.
#
#if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
#endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
#
# Libraries
#
SET (ORION_LIBS
common
rest # verbName(Verb) from [email protected]; jsonRequestTreat from [email protected]
orionld_mhd
orionld_service
orionld_serviceRoutines
orionld_distOp
orionld_regMatch
orionld_distOp
orionld_troe
orionld_kjTree
orionld_mqtt
orionld_dds
orionld_http
orionld_context
orionld_common
orionld_context
orionld_contextCache
orionld_regCache
orionld_notifications
orionld_db
orionld_mongoc
orionld_legacyDriver # legacyDriver uses mongoCppLegacy
orionld_mongoCppLegacy
orionld_db
orionld_mongoBackend
orionld_mongoCppLegacy
orionld_socketService
orionld_troe
orionld_dbModel
orionld_apiModel
orionld_pernot
serviceRoutines
serviceRoutinesV2
ngsiNotify
orionld_kjTree
jsonParse
jsonParseV2
rest # this is repeated for linking str2Verb from [email protected];
# verbName(Verb) from [email protected]
convenience
ngsi9
ngsi10
ngsi
cache
mongoBackend
orionld_context # Should not be necessary ... kjTreeFromNotification gets undefined reference to 'orionldAliasLookup' without this ...
orionld_legacyDriver # legacyDriver uses payloadCheck functions
orionld_mongoBackend # mongoBackend uses functions in orionld_mongoBackend
orionld_payloadCheck
orionld_kjTree # mongoBackend uses kjSort, that is temporarily in kjTree - to be moved to kjson
orionld_payloadCheck
orionld_mqtt
orionld_q
orionld_mongoc # subCache needs mongoc
orionld_dbModel
orionld_apiModel
orionld_common
orionld_entityMaps
orionld_types
parse
apiTypesV2
orionTypes
common
alarmMgr
metricsMgr
logSummary
orionld_prometheus
lm
pa
)
# Static libs common to orionld and unitTest binaries
SET (COMMON_STATIC_LIBS
mongoclient.a
kjson.a
khash.a
ktrace.a
kargs.a
kalloc.a
kbase.a
)
SET (DYNAMIC_LIBS
fastdds
fastcdr
foonathan_memory-0.7.3
ddsenabler
tinyxml2
prom
promhttp
curl
${GNUTLS_LIBRARIES}
pthread
gcrypt
ssl
rt
uuid
crypto
sasl2
icuuc
icudata
z
resolv
paho-mqtt3c
pq # for TRoE & Postgres
${LIBMONGOC_LIBRARIES}
${LIBBSON_LIBRARIES}
)
#
# Enabling testing
#
if (UNIT_TEST)
ENABLE_TESTING()
INCLUDE(Dart)
SET (CMAKE_TEST_TIMEOUT 60)
SET (DART_TIMEOUT 60)
ADD_SUBDIRECTORY(test)
endif (UNIT_TEST)
#
# Common include
#
include_directories("/usr/include")
include_directories("${LIBBSON_INCLUDE_DIRS}")
include_directories("${LIBMONGOC_INCLUDE_DIRS}")
include_directories("${PROJECT_SOURCE_DIR}/..")
include_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/prom/include")
include_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/promhttp/include")
#
# Library directories
#
MESSAGE("Building for ${BUILD_ARCH}")
if ("${BUILD_ARCH}" STREQUAL "x86_64")
link_directories("/usr/lib64")
else (NOT "${BUILD_ARCH}" STREQUAL "x86_64")
link_directories("/usr/lib")
endif ("${BUILD_ARCH}" STREQUAL "x86_64")
link_directories("/usr/lib/x86_64-linux-gnu")
link_directories("${PROJECT_SOURCE_DIR}/../kjson")
link_directories("${PROJECT_SOURCE_DIR}/../kalloc")
link_directories("${PROJECT_SOURCE_DIR}/../kbase")
link_directories("${PROJECT_SOURCE_DIR}/../khash")
link_directories("${PROJECT_SOURCE_DIR}/../ktrace")
link_directories("${PROJECT_SOURCE_DIR}/../kargs")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/prom/build")
link_directories("${PROJECT_SOURCE_DIR}/../prometheus-client-c/promhttp/build")
link_directories("${LIBMONGOC_LIBRARY_DIRS}")
link_directories("${GNUTLS_LIBRARY_DIRS}")
#
# Enabling test harness
#
if (UNIT_TEST)
ENABLE_TESTING()
INCLUDE(Dart)
SET (CMAKE_TEST_TIMEOUT 60)
SET (DART_TIMEOUT 60)
#ADD_SUBDIRECTORY(test/harness)
endif (UNIT_TEST)
#
# Continuing if OK
#
if (error EQUAL 0)
MESSAGE("cmake: OK")
ADD_SUBDIRECTORY(src/lib/logMsg)
ADD_SUBDIRECTORY(src/lib/parseArgs)
ADD_SUBDIRECTORY(src/lib/common)
ADD_SUBDIRECTORY(src/lib/orionTypes)
ADD_SUBDIRECTORY(src/lib/ngsi)
ADD_SUBDIRECTORY(src/lib/serviceRoutines)
ADD_SUBDIRECTORY(src/lib/serviceRoutinesV2)
ADD_SUBDIRECTORY(src/lib/convenience)
ADD_SUBDIRECTORY(src/lib/ngsi9)
ADD_SUBDIRECTORY(src/lib/ngsi10)
ADD_SUBDIRECTORY(src/lib/ngsiNotify)
ADD_SUBDIRECTORY(src/lib/apiTypesV2)
ADD_SUBDIRECTORY(src/lib/parse)
ADD_SUBDIRECTORY(src/lib/jsonParse)
ADD_SUBDIRECTORY(src/lib/jsonParseV2)
ADD_SUBDIRECTORY(src/lib/rest)
ADD_SUBDIRECTORY(src/lib/orionld/entityMaps)
ADD_SUBDIRECTORY(src/lib/orionld/pernot)
ADD_SUBDIRECTORY(src/lib/orionld/socketService)
ADD_SUBDIRECTORY(src/lib/orionld/notifications)
ADD_SUBDIRECTORY(src/lib/orionld/regMatch)
ADD_SUBDIRECTORY(src/lib/orionld/distOp)
ADD_SUBDIRECTORY(src/lib/orionld/q)
ADD_SUBDIRECTORY(src/lib/orionld/mhd)
ADD_SUBDIRECTORY(src/lib/orionld/service)
ADD_SUBDIRECTORY(src/lib/orionld/serviceRoutines)
ADD_SUBDIRECTORY(src/lib/orionld/troe)
ADD_SUBDIRECTORY(src/lib/orionld/common)
ADD_SUBDIRECTORY(src/lib/orionld/types)
ADD_SUBDIRECTORY(src/lib/orionld/context)
ADD_SUBDIRECTORY(src/lib/orionld/contextCache)
ADD_SUBDIRECTORY(src/lib/orionld/regCache)
ADD_SUBDIRECTORY(src/lib/orionld/kjTree)
ADD_SUBDIRECTORY(src/lib/orionld/db)
ADD_SUBDIRECTORY(src/lib/orionld/dbModel)
ADD_SUBDIRECTORY(src/lib/orionld/apiModel)
ADD_SUBDIRECTORY(src/lib/orionld/mongoBackend)
ADD_SUBDIRECTORY(src/lib/orionld/mongoCppLegacy)
ADD_SUBDIRECTORY(src/lib/orionld/mongoc)
ADD_SUBDIRECTORY(src/lib/orionld/payloadCheck)
ADD_SUBDIRECTORY(src/lib/orionld/mqtt)
ADD_SUBDIRECTORY(src/lib/orionld/dds)
ADD_SUBDIRECTORY(src/lib/orionld/http)
ADD_SUBDIRECTORY(src/lib/orionld/prometheus)
ADD_SUBDIRECTORY(src/lib/orionld/legacyDriver)
ADD_SUBDIRECTORY(src/lib/mongoBackend)
ADD_SUBDIRECTORY(src/lib/cache)
ADD_SUBDIRECTORY(src/lib/alarmMgr)
ADD_SUBDIRECTORY(src/lib/metricsMgr)
ADD_SUBDIRECTORY(src/lib/logSummary)
ADD_SUBDIRECTORY(src/app/orionld)
ADD_SUBDIRECTORY(test/functionalTest/ftClient)
else ()
MESSAGE("cmake: NOT OK")
endif (error EQUAL 0)