forked from 3Hren/blackhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
357 lines (299 loc) · 10.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
cmake_minimum_required(VERSION 2.6)
# Choose new behaviour for CMP0042.
# See http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html for more details.
if (POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif (POLICY CMP0042)
OPTION(ENABLE_TESTING "Build the library with tests" OFF)
OPTION(ENABLE_EXAMPLES "Build examples" OFF)
OPTION(ENABLE_BENCHMARKING "Build the library with benchmarks" OFF)
OPTION(ENABLE_TESTING_THREADSAFETY "Build the thread-safety testing suite" OFF)
set(LIBRARY_NAME blackhole)
project(${LIBRARY_NAME})
find_package(Boost 1.46 REQUIRED COMPONENTS
system
thread)
include_directories(BEFORE SYSTEM
${PROJECT_SOURCE_DIR}/foreign/libcds
${PROJECT_SOURCE_DIR}/foreign/rapidjson/include)
include_directories(${PROJECT_SOURCE_DIR}/include)
add_library(${LIBRARY_NAME} SHARED
src/attribute.cpp
src/config/factory.cpp
src/config/json.cpp
src/config/node.cpp
src/config/option.cpp
src/datetime/generator.linux.cpp
src/datetime/generator.other.cpp
src/essentials.cpp
src/filter/severity.cpp
src/format.cpp
src/formatter/json.cpp
src/formatter/mod.cpp
src/formatter/string.cpp
src/formatter/string/error.cpp
src/formatter/string/grammar.cpp
src/formatter/string/parser.cpp
src/formatter/string/token.cpp
src/formatter/tskv.cpp
src/handler.cpp
src/handler/blocking.cpp
src/handler/dev.cpp
src/logger.cpp
src/procname.cpp
src/record.cpp
src/registry.cpp
src/root.cpp
src/scope/holder.cpp
src/scope/manager.cpp
src/scope/watcher.cpp
src/sink/asynchronous.cpp
src/sink/asynchronous.p.cpp
src/sink/console.cpp
src/sink/file.cpp
src/sink/null.cpp
src/sink/socket/tcp.cpp
src/sink/socket/udp.cpp
src/sink/syslog.cpp
src/termcolor.cpp
src/wrapper.cpp
)
# Set the Standard version.
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORTS_CXX14)
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX14)
add_definitions(-std=c++14)
elseif (COMPILER_SUPPORTS_CXX11)
add_definitions(-std=c++11)
elseif (COMPILER_SUPPORTS_CXX0X)
add_definitions(-std=c++0x)
else ()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif ()
# Set maximum warnings level depending on compiler.
# TODO: target_maximum_warnings(${LIBRARY_NAME})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${LIBRARY_NAME} PRIVATE
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-shadow
-Wno-weak-vtables
-pedantic
-pedantic-errors)
else ()
set_target_properties(${LIBRARY_NAME} PROPERTIES
COMPILE_FLAGS "-Wall"
COMPILE_FLAGS "-Wextra"
COMPILE_FLAGS "-Waddress"
COMPILE_FLAGS "-Warray-bounds"
COMPILE_FLAGS "-Wbuiltin-macro-redefined"
COMPILE_FLAGS "-Wconversion"
COMPILE_FLAGS "-Wctor-dtor-privacy"
COMPILE_FLAGS "-Winit-self"
COMPILE_FLAGS "-Wnon-virtual-dtor"
COMPILE_FLAGS "-Wold-style-cast"
COMPILE_FLAGS "-Woverloaded-virtual"
COMPILE_FLAGS "-Wsuggest-attribute=const"
COMPILE_FLAGS "-Wsuggest-attribute=noreturn"
COMPILE_FLAGS "-Wsuggest-attribute=pure"
COMPILE_FLAGS "-Wswitch"
COMPILE_FLAGS "-Wunreachable-code"
COMPILE_FLAGS "-pedantic"
COMPILE_FLAGS "-pedantic-errors"
LINK_FLAGS -Wl,--version-script=${PROJECT_SOURCE_DIR}/libblackhole1.version)
endif ()
target_link_libraries(${LIBRARY_NAME}
${Boost_LIBRARIES}
)
# The rule is that: any breakage of the ABI must be indicated by incrementing the SOVERSION.
# So, adding e.g. functions is no problem, modifying argument lists or removing functions would
# required the SOVERSION to be incremented. Similar rules hold of course for non-opaque
# data-structures.
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION 1.9.0)
set_target_properties(${LIBRARY_NAME} PROPERTIES SOVERSION 1)
if (ENABLE_TESTING_THREADSAFETY)
add_executable(${LIBRARY_NAME}-tests-rc-assign
tests/rc/assign)
target_link_libraries(${LIBRARY_NAME}-tests-rc-assign
${LIBRARY_NAME}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES})
add_executable(${LIBRARY_NAME}-tests-rc-filter
tests/rc/filter)
target_link_libraries(${LIBRARY_NAME}-tests-rc-filter
${LIBRARY_NAME}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES})
endif (ENABLE_TESTING_THREADSAFETY)
if (ENABLE_TESTING)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/foreign/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/tests/cmake")
find_package(Threads)
include(PrepareGoogleTesting)
prepare_google_testing()
include_directories(BEFORE SYSTEM
${PROJECT_SOURCE_DIR}/foreign/rapidjson/include
${PROJECT_SOURCE_DIR}/foreign/libcds)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/tests/include)
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
include(CodeCoverage)
find_program(GCOV_PATH gcov)
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)
if (NOT(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading")
endif ()
function(setup_target_for_coverage _targetname _testrunner _outputname)
ADD_CUSTOM_TARGET(${_targetname}
# Reset all execution counts to zero.
${LCOV_PATH} --directory . --zerocounters
# Run tests.
COMMAND ${_testrunner} ${ARGV3}
# Capture coverage data.
COMMAND ${LCOV_PATH} --compat-libtool --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' 'foreign/*' --output-file ${_outputname}.info.cleaned
# Generating the report.
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
# COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report.")
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report.")
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
setup_target_for_coverage(coverage ${LIBRARY_NAME}-tests .coverage)
set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
endif ()
add_executable(${LIBRARY_NAME}-tests
tests/attribute
tests/config/json
tests/config/option
tests/datetime
tests/facade
tests/record
tests/registry
tests/root
tests/severity
tests/src/mocks/formatter
tests/src/mocks/handler
tests/src/mocks/logger
tests/src/mocks/sink
tests/src/unit/detail/handler/blocking.cpp
tests/src/unit/detail/mpsc
tests/src/unit/detail/record
tests/src/unit/formatter/json
tests/src/unit/formatter/string.cpp
tests/src/unit/formatter/string/grammar.cpp
tests/src/unit/formatter/string/parser.cpp
tests/src/unit/formatter/string/token.cpp
tests/src/unit/formatter/tskv.cpp
tests/src/unit/sink/asynchronous
tests/src/unit/sink/console.cpp
tests/src/unit/sink/console/builder.cpp
tests/src/unit/sink/file.cpp
tests/src/unit/sink/file/flusher/bytecount.cpp
tests/src/unit/sink/file/flusher/repeat.cpp
tests/src/unit/sink/file/stream.cpp
tests/src/unit/sink/null
tests/src/unit/sink/syslog
tests/src/unit/sink/tcp
tests/src/unit/sink/udp.cpp
tests/src/unit/stdext/string_view
tests/src/unit/termcolor.cpp
tests/src/unit/time.cpp
tests/wrapper
)
add_dependencies(${LIBRARY_NAME}-tests googlemock)
target_link_libraries(${LIBRARY_NAME}-tests
${LIBRARY_NAME}
${CMAKE_THREAD_LIBS_INIT}
gmock
gtest
gtest_main)
endif (ENABLE_TESTING)
if (ENABLE_BENCHMARKING)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/foreign/modules")
include(PrepareGoogleBenchmark)
find_package(Threads)
prepare_google_benchmarking()
include_directories(
${PROJECT_SOURCE_DIR}/bench)
add_executable(${LIBRARY_NAME}-benchmarks
bench/attribute
bench/clock
bench/cpp14formatter
bench/datetime
bench/formatter/json
bench/formatter/string
bench/formatter/tskv.cpp
bench/logger
bench/main
bench/queue
bench/record
bench/recordbuf
bench/system/thread)
enable_google_benchmarking(${LIBRARY_NAME}-benchmarks)
target_link_libraries(${LIBRARY_NAME}-benchmarks
${LIBRARY_NAME}
benchmark
${CMAKE_THREAD_LIBS_INIT})
endif (ENABLE_BENCHMARKING)
function(enable_all_warnings TARGET)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-shadow
-Wno-weak-vtables
-pedantic
-pedantic-errors)
endif ()
endfunction()
if (ENABLE_EXAMPLES)
# Hello World example.
add_executable(1-hello
examples/1.hello)
enable_all_warnings(1-hello)
target_link_libraries(1-hello
blackhole)
# Configuration using manual builder.
add_executable(2-simple
examples/2.simple)
enable_all_warnings(2-simple)
target_link_libraries(2-simple
blackhole)
# Configuration using JSON config file.
add_executable(3-config
examples/3.config)
enable_all_warnings(3-config)
target_link_libraries(3-config
blackhole)
# Configuration using JSON config file with facade.
add_executable(4-config_facade
examples/4.config_facade)
enable_all_warnings(4-config_facade)
target_link_libraries(4-config_facade
blackhole)
file(COPY examples/3.config.json DESTINATION .)
endif (ENABLE_EXAMPLES)
install(
TARGETS
blackhole
LIBRARY DESTINATION lib COMPONENT runtime
ARCHIVE DESTINATION lib COMPONENT development)
install(
DIRECTORY
include/
DESTINATION include
COMPONENT development
PATTERN "detail" EXCLUDE)