forked from AliceO2Group/InfoLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
466 lines (410 loc) · 15.5 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
####################################
# cmake InfoLogger
####################################
# cmake settings
CMAKE_MINIMUM_REQUIRED(VERSION 3.17.0 FATAL_ERROR)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
# define project
project(
InfoLogger
DESCRIPTION "O2 Logging library and services"
LANGUAGES NONE
)
# simplified build mode for doc only
if(ONLYDOC)
add_subdirectory(doc)
return()
endif()
# global compilation options
enable_language(C)
enable_language(CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# define directories
# build-time binaries
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
# installation
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR lib)
# add local modules directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# add subdirectories
add_subdirectory(doc)
# dependencies to build the InfoLogger components
# NB: cmake/InfoLoggerConfig.cmake defines dependencies for clients using the library
#find_package(Common REQUIRED)
find_package(Boost REQUIRED)
find_package(MySQL)
find_package(SWIG 4.2.0)
# flag to build only client library
#set(INFOLOGGER_BUILD_LIBONLY 1)
if(INFOLOGGER_BUILD_LIBONLY)
message("Enabling library only.")
else()
message("Enabling all InfoLogger modules.")
endif()
##################################
# Common-O2
##################################
# reuse locally some of the Common files to embed in standalone library
include(ExternalProject)
externalproject_add (Common-standalone
GIT_REPOSITORY "https://github.com/AliceO2Group/Common.git"
GIT_TAG "v1.6.3"
LOG_DOWNLOAD 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
BUILD_COMMAND ""
CONFIGURE_COMMAND ""
TEST_COMMAND ""
INSTALL_COMMAND ""
)
externalproject_get_property(Common-standalone source_dir)
set(COMMON_STANDALONE_SRC_DIR ${source_dir})
set(COMMON_STANDALONE_INCLUDE_DIRS ${COMMON_STANDALONE_SRC_DIR}/include ${Boost_INCLUDE_DIRS})
foreach (modul Configuration Daemon LineBuffer SimpleLog Thread Timer)
add_library(
objCommon${modul} OBJECT
${COMMON_STANDALONE_SRC_DIR}/src/${modul}.cxx
)
set_source_files_properties(${COMMON_STANDALONE_SRC_DIR}/src/${modul}.cxx PROPERTIES GENERATED TRUE)
target_include_directories(objCommon${modul}
PRIVATE ${COMMON_STANDALONE_INCLUDE_DIRS}
)
add_dependencies(objCommon${modul} Common-standalone)
endforeach (modul)
# define include dirs
#get_target_property(COMMON_INCLUDE_DIRS AliceO2::Common INTERFACE_INCLUDE_DIRECTORIES)
if(NOT COMMON_INCLUDE_DIRS)
set(COMMON_INCLUDE_DIRS ${COMMON_STANDALONE_INCLUDE_DIRS})
endif()
set(INFOLOGGER_INCLUDE_DIRS_PUBLIC include)
set(INFOLOGGER_INCLUDE_DIRS_PRIVATE ${COMMON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INFOLOGGER_INCLUDE_DIRS ${INFOLOGGER_INCLUDE_DIRS_PUBLIC} ${INFOLOGGER_INCLUDE_DIRS_PRIVATE})
#####################################
# infoLogger client library
#####################################
# object file: client (to infoLoggerD)
add_library (objInfoLoggerClient OBJECT
src/InfoLogger.cxx
src/InfoLoggerScripting.cxx
src/InfoLoggerContext.cxx
src/InfoLoggerClient.cxx
src/infoLoggerMessageDecode.c
src/InfoLoggerMessageHelper.cxx
src/infoLoggerUtils.cxx
src/utility.c
src/simplelog.cxx
)
target_include_directories(objInfoLoggerClient
PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
)
add_dependencies(objInfoLoggerClient Common-standalone)
# list of object files for the library
set(INFOLOGGER_LIB_OBJECTS
$<TARGET_OBJECTS:objInfoLoggerClient>
$<TARGET_OBJECTS:objCommonConfiguration>
$<TARGET_OBJECTS:objCommonSimpleLog>
$<TARGET_OBJECTS:objCommonLineBuffer>
$<TARGET_OBJECTS:objCommonTimer>
)
# shared library
add_library (InfoLogger SHARED
$<TARGET_OBJECTS:objInfoLoggerClient>
${INFOLOGGER_LIB_OBJECTS}
)
set_target_properties(InfoLogger PROPERTIES
OUTPUT_NAME O2Infologger
)
target_include_directories(InfoLogger
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INFOLOGGER_INCLUDE_DIRS_PUBLIC}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(InfoLogger
PUBLIC
# AliceO2::Common
Boost::boost
pthread
)
install(TARGETS InfoLogger
EXPORT InfoLoggerTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# export targets for shared library
install(EXPORT InfoLoggerTargets
FILE InfoLoggerTargets.cmake
NAMESPACE AliceO2::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/InfoLogger
)
install(FILES cmake/InfoLoggerConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/InfoLogger)
# install include files
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/InfoLogger DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
##########################################
# infoLogger - services and other modules
if(NOT INFOLOGGER_BUILD_LIBONLY)
##########################################
# object file: transport (to infoLoggerS)
add_library (objInfoLoggerTransport OBJECT
src/permanentFIFO.c
src/simplelog.cxx
src/transport_client.c
src/transport_files.c
src/transport_proxy.c
src/transport_server.c
src/utility.c
)
target_include_directories(objInfoLoggerTransport
PRIVATE ${INFOLOGGER_INCLUDE_DIRS}
)
add_dependencies(objInfoLoggerTransport Common-standalone)
# static library
add_library (libInfoLogger-static STATIC
${INFOLOGGER_LIB_OBJECTS}
)
set_target_properties(libInfoLogger-static PROPERTIES
OUTPUT_NAME O2Infologger
)
target_include_directories(libInfoLogger-static
INTERFACE
${INFOLOGGER_INCLUDE_DIRS_PUBLIC}
)
add_dependencies(libInfoLogger-static Common-standalone)
target_link_libraries(libInfoLogger-static pthread)
# executable: log (command line tool to inject log messages)
add_executable(
o2-infologger-log
src/log.cxx
)
target_link_libraries(
o2-infologger-log
libInfoLogger-static
)
target_include_directories(
o2-infologger-log
PRIVATE
${COMMON_STANDALONE_INCLUDE_DIRS}
)
# executable: infoLoggerD
add_executable(
o2-infologger-daemon
src/infoLoggerD.cxx
$<TARGET_OBJECTS:objInfoLoggerTransport>
$<TARGET_OBJECTS:objCommonConfiguration>
$<TARGET_OBJECTS:objCommonSimpleLog>
$<TARGET_OBJECTS:objCommonDaemon>
)
target_link_libraries(
o2-infologger-daemon
pthread
)
target_include_directories(
o2-infologger-daemon
PRIVATE
${COMMON_STANDALONE_INCLUDE_DIRS}
)
# executable: infoLoggerServer
if(MYSQL_FOUND)
add_definitions(-DWITH_MYSQL)
endif()
add_executable(
o2-infologger-server
$<TARGET_OBJECTS:objInfoLoggerTransport>
$<TARGET_OBJECTS:objCommonConfiguration>
$<TARGET_OBJECTS:objCommonSimpleLog>
$<TARGET_OBJECTS:objCommonDaemon>
$<TARGET_OBJECTS:objCommonThread>
$<TARGET_OBJECTS:objCommonTimer>
src/infoLoggerServer.cxx
src/InfoLoggerDispatch.cxx
src/InfoLoggerDispatchBrowser.cxx
src/ConfigInfoLoggerServer.cxx
src/infoLoggerMessageDecode.c
src/InfoLoggerMessageHelper.cxx
src/InfoLoggerMessageList.cxx
src/infoLoggerUtils.cxx
$<$<BOOL:${MYSQL_FOUND}>:src/InfoLoggerDispatchSQL.cxx>
)
target_include_directories(
o2-infologger-server
PRIVATE
${INFOLOGGER_INCLUDE_DIRS_PUBLIC}
${COMMON_STANDALONE_INCLUDE_DIRS}
${MYSQL_INCLUDE_DIRS}
)
target_link_libraries(
o2-infologger-server
pthread
${MYSQL_LIBRARIES}
)
# executable: o2-infologger-admindb
add_executable(
o2-infologger-admindb
$<TARGET_OBJECTS:objCommonConfiguration>
$<TARGET_OBJECTS:objCommonSimpleLog>
src/infoLoggerAdminDB.cxx
)
target_include_directories(
o2-infologger-admindb
PRIVATE
${COMMON_STANDALONE_INCLUDE_DIRS}
${MYSQL_INCLUDE_DIRS}
)
target_link_libraries(
o2-infologger-admindb
${MYSQL_LIBRARIES}
)
# generate libraries for other languages with SWIG
if(SWIG_FOUND)
include (UseSWIG)
message("Generating extra languages libraries with SWIG")
set_property(SOURCE src/infoLogger.i PROPERTY CPLUSPLUS ON)
# bug in UseSwig.cmake, this one does not work, argument not passed to swig command:
# set_property(SOURCE src/infoLogger.i PROPERTY SWIG_MODULE_NAME infoLoggerModuleName)
# see https://gitlab.kitware.com/cmake/cmake/issues/18374
# workaround: add -module option to variable CMAKE_SWIG_FLAGS
# library for TCL
find_package(TCL)
if (TCL_FOUND)
message("Bindings for Tcl will be generated")
set(CMAKE_SWIG_FLAGS -module infoLoggerForTcl)
swig_add_library(infoLoggerForTcl LANGUAGE tcl SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
target_include_directories(${SWIG_MODULE_infoLoggerForTcl_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${TCL_INCLUDE_PATH})
target_link_libraries(${SWIG_MODULE_infoLoggerForTcl_REAL_NAME} ${TCL_LIBRARY})
set_target_properties(${SWIG_MODULE_infoLoggerForTcl_REAL_NAME} PROPERTIES OUTPUT_NAME infoLoggerForTcl)
install(TARGETS ${SWIG_MODULE_infoLoggerForTcl_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# library for Python
find_package(Python3 COMPONENTS Interpreter Development)
if (PYTHON3_FOUND)
message("Bindings for Python will be generated")
#message("Python_FOUND:${Python3_FOUND}")
#message("Python_VERSION:${Python3_VERSION}")
#message("Python_Development_FOUND:${Python3_Development_FOUND}")
#message("Python_LIBRARIES:${Python3_LIBRARIES}")
#message("Python include: ${Python3_INCLUDE_DIRS}")
set(CMAKE_SWIG_FLAGS -module infoLoggerForPython)
swig_add_library(infoLoggerForPython LANGUAGE python SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
target_include_directories(${SWIG_MODULE_infoLoggerForPython_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS})
target_link_libraries(${SWIG_MODULE_infoLoggerForPython_REAL_NAME} ${Python3_LIBRARIES})
message("linking with ${Python3_LIBRARIES}")
#set_target_properties(${SWIG_MODULE_infoLoggerForPython_REAL_NAME} PROPERTIES OUTPUT_NAME _infoLoggerForPython)
install(TARGETS ${SWIG_MODULE_infoLoggerForPython_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/infoLoggerForPython.py DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
#library for Go
find_program(GO_EXECUTABLE go)
if (GO_EXECUTABLE)
message("Bindings for Go will be generated")
message("Using ${GO_EXECUTABLE}")
set(GO_PATH ${CMAKE_CURRENT_BINARY_DIR}/go_workspace)
message("Using GOPATH=${GO_PATH}")
file(MAKE_DIRECTORY ${GO_PATH})
file(MAKE_DIRECTORY ${GO_PATH}/src)
set( ENV{GOPATH} ${GO_PATH})
set(CMAKE_SWIG_FLAGS -module infoLoggerForGo -cgo -intgosize 64)
swig_add_library(infoLoggerForGo LANGUAGE go TYPE STATIC SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
target_include_directories(${SWIG_MODULE_infoLoggerForGo_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS})
install(TARGETS ${SWIG_MODULE_infoLoggerForGo_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/infoLoggerForGo.go DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
#library for Javascript / node.js
find_program(NODE_EXECUTABLE node)
execute_process(COMMAND ${NODE_EXECUTABLE} --version COMMAND tr -d 'v' OUTPUT_VARIABLE NODEJS_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(NODE_DIR ${NODE_EXECUTABLE} DIRECTORY)
find_path(NODEJS_INCLUDE_DIRS NAMES node.h NO_DEFAULT_PATH PATHS ${Nodejs_ROOT} ${Nodejs_ROOT}/include ${NODE_DIR}/../include/node)
if (NODEJS_INCLUDE_DIRS AND ("${NODEJS_VERSION}" VERSION_GREATER_EQUAL "8.9") AND ("${NODEJS_VERSION}" VERSION_LESS "12"))
message("Bindings for node.js will be generated")
message("Using NODEJS_INCLUDE_DIRS=${NODEJS_INCLUDE_DIRS}")
message("Node.js version ${NODEJS_VERSION}")
if (${SWIG_VERSION} VERSION_LESS "4.0.0")
message("SWIG>=4.0.0 needed to generate node.js wrapper, reusing cached one")
set(SWIG_MODULE_infoLoggerForNodejs_REAL_NAME infoLoggerForNodejs)
add_library (infoLoggerForNodejs SHARED src/infoLoggerJAVASCRIPT_wrap.cxx ${INFOLOGGER_LIB_OBJECTS})
target_include_directories(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${NODEJS_INCLUDE_DIRS})
set_target_properties(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PROPERTIES PREFIX "")
else()
set(CMAKE_SWIG_FLAGS -module infoLoggerForNodejs -v8)
swig_add_library(infoLoggerForNodejs LANGUAGE javascript SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
endif()
target_include_directories(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${NODEJS_INCLUDE_DIRS})
target_compile_definitions(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE -DBUILDING_NODE_EXTENSION)
set_target_properties(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PROPERTIES OUTPUT_NAME infoLogger SUFFIX ".node")
set(no_lookup_compilers "Clang" "AppleClang")
if ( ${CMAKE_CXX_COMPILER_ID} IN_LIST no_lookup_compilers)
set_target_properties(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
install(TARGETS ${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()
# test programs
message("Generating test executables")
enable_testing()
set(TEST_SRCS
test/testInfoLogger.c
test/testInfoLogger.cxx
test/testInfoLoggerPerf.cxx
test/testInfoLoggerDB.cxx
)
set(TEST_EXES
libc
lib
perf
db
)
foreach (f n IN ZIP_LISTS TEST_SRCS TEST_EXES)
set(exe "o2-infologger-test-${n}")
add_executable(${exe} ${f} ${INFOLOGGER_LIB_OBJECTS})
target_link_libraries(${exe} InfoLogger)
target_include_directories(${exe} PRIVATE ${COMMON_STANDALONE_INCLUDE_DIRS} src)
add_test(NAME "test-${n}" COMMAND ${exe})
endforeach()
target_include_directories(
o2-infologger-test-db
PRIVATE
${INFOLOGGER_INCLUDE_DIRS_PUBLIC}
${COMMON_STANDALONE_INCLUDE_DIRS}
${MYSQL_INCLUDE_DIRS}
)
target_link_libraries(
o2-infologger-test-db
pthread
${MYSQL_LIBRARIES}
)
# define what should be built
# exclude modules requiring optional dependencies not found
if(NOT MYSQL_FOUND)
message("MySQL not found, some infoLogger modules are disabled for this build")
set_target_properties(o2-infologger-admindb PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(o2-infologger-test-db PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
# Install
set (INSTALL_TARGETS o2-infologger-log o2-infologger-daemon o2-infologger-server o2-infologger-admindb libInfoLogger-static)
# Install has undefined behavior for properties with EXLUDE_FROM_ALL property set
# Here we want to skip such targets
foreach (t ${INSTALL_TARGETS})
get_target_property(IS_EXCLUDED ${t} EXCLUDE_FROM_ALL)
if(NOT ${IS_EXCLUDED})
install(TARGETS ${t} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endforeach()
install(PROGRAMS src/infoBrowser.tcl DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME o2-infologger-browser)
install(PROGRAMS src/infoLoggerTester.tcl DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME o2-infologger-tester)
install(PROGRAMS newMysql.sh DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME o2-infologger-newdb)
# service files
set(SERVICE_SRCS infoLoggerD.service infoLoggerServer.service)
set(SERVICE_NAMES o2-infologger-daemon.service o2-infologger-server.service)
foreach (f n IN ZIP_LISTS SERVICE_SRCS SERVICE_NAMES)
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/o2.d/infologger/systemd/ RENAME ${n} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach()
# sample config files
FILE(GLOB CFG_FILES *.cfg)
foreach (f ${CFG_FILES})
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/o2.d/infologger/ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach()
#####################################
endif()
# (NOT INFOLOGGER_BUILD_LIBONLY)
#####################################