-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
532 lines (475 loc) · 19.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
532 lines (475 loc) · 19.2 KB
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
cmake_minimum_required(VERSION 3.15)
# Set CMake policy to suppress deprecation warnings from dependencies
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0077 NEW)
# Get version from environment variable or git tag
if(DEFINED ENV{MYGRAMDB_VERSION} AND NOT "$ENV{MYGRAMDB_VERSION}" STREQUAL "")
set(PROJECT_VERSION_FROM_ENV "$ENV{MYGRAMDB_VERSION}")
message(STATUS "Version from environment: ${PROJECT_VERSION_FROM_ENV}")
project(MygramDB VERSION ${PROJECT_VERSION_FROM_ENV} LANGUAGES CXX C)
else()
# Get version from git tag
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
# Parse version from tag (remove 'v' prefix if present)
if(GIT_TAG)
string(REGEX REPLACE "^v" "" PROJECT_VERSION_FROM_GIT "${GIT_TAG}")
message(STATUS "Version from git tag: ${PROJECT_VERSION_FROM_GIT}")
else()
set(PROJECT_VERSION_FROM_GIT "0.0.0")
message(WARNING "No git tag found, using default version: ${PROJECT_VERSION_FROM_GIT}")
endif()
project(MygramDB VERSION ${PROJECT_VERSION_FROM_GIT} LANGUAGES CXX C)
endif()
# C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# macOS specific settings
if(APPLE)
# Get macOS SDK path
execute_process(
COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE MACOS_SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Use SDK path if available
if(MACOS_SDK_PATH)
message(STATUS "Using macOS SDK path: ${MACOS_SDK_PATH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isysroot ${MACOS_SDK_PATH}")
# Explicitly specify the path to C++ standard library headers
include_directories(SYSTEM "${MACOS_SDK_PATH}/usr/include/c++/v1")
include_directories(SYSTEM "${MACOS_SDK_PATH}/usr/include")
endif()
# Add Homebrew paths
if(EXISTS "/usr/local/include")
include_directories(SYSTEM "/usr/local/include")
link_directories("/usr/local/lib")
endif()
if(EXISTS "/opt/homebrew/include")
include_directories(SYSTEM "/opt/homebrew/include")
link_directories("/opt/homebrew/lib")
endif()
# macOS-specific compilation options
add_compile_options(-Wno-unused-command-line-argument -Qunused-arguments)
endif()
# Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Architecture flags: use baseline arch for portable builds, -march=native for local builds
# CI/RPM sets MYGRAMDB_PORTABLE_BUILD=ON to avoid "Illegal instruction" on different CPUs
if(MYGRAMDB_PORTABLE_BUILD)
# Detect architecture and use appropriate baseline
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64")
# ARM64: use baseline ARMv8-A for maximum compatibility
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a")
message(STATUS "Portable build: using -march=armv8-a for ARM64")
else()
# x86_64: use baseline x86-64 for maximum compatibility
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64")
message(STATUS "Portable build: using -march=x86-64 for x86_64")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
message(STATUS "Local build: using -march=native")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
endif()
# Export compile commands for clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Options
option(BUILD_TESTS "Build tests" ON)
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
option(BUILD_FUZZERS "Build local randomized fuzz targets (not registered with CTest)" OFF)
set(FUZZER_ENGINE "standalone" CACHE STRING "Fuzzing engine: standalone or libfuzzer")
set_property(CACHE FUZZER_ENGINE PROPERTY STRINGS standalone libfuzzer)
option(ENABLE_COVERAGE "Enable code coverage" OFF)
option(USE_ICU "Use ICU for Unicode normalization" ON)
# Fuzzing instrumentation is applied to the whole build, never to the harness
# alone. The harness constructs library types directly, so instrumenting only
# its translation unit leaves inline and template code compiled two ways in one
# binary; the resulting crashes look like product defects and are not.
if(BUILD_FUZZERS)
if(NOT FUZZER_ENGINE STREQUAL "standalone" AND NOT FUZZER_ENGINE STREQUAL "libfuzzer")
message(FATAL_ERROR "FUZZER_ENGINE must be 'standalone' or 'libfuzzer', got '${FUZZER_ENGINE}'")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined")
if(FUZZER_ENGINE STREQUAL "libfuzzer")
# Every translation unit gets coverage instrumentation; only the harness
# links the driver itself.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer-no-link")
endif()
message(STATUS "Fuzzing enabled: engine ${FUZZER_ENGINE}, whole build instrumented")
endif()
# AddressSanitizer
if(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
# ThreadSanitizer
if(ENABLE_TSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
endif()
# UndefinedBehaviorSanitizer
if(ENABLE_UBSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
endif()
# Code Coverage
if(ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Enabling code coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
else()
message(WARNING "Code coverage is only supported with GCC or Clang")
endif()
endif()
# Find packages
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
# ICU detection (similar to suzume-feedmill)
if(USE_ICU)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(ICU icu-uc icu-io icu-i18n)
if(ICU_FOUND)
message(STATUS "Found ICU via pkg-config")
message(STATUS " Include dirs: ${ICU_INCLUDE_DIRS}")
message(STATUS " Libraries: ${ICU_LIBRARIES}")
endif()
endif()
# Fallback to manual detection if pkg-config didn't work
if(NOT ICU_FOUND)
if(APPLE)
# macOS-specific paths
execute_process(
COMMAND brew --prefix icu4c
OUTPUT_VARIABLE BREW_ICU_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE BREW_ICU_RESULT
)
if(BREW_ICU_RESULT EQUAL 0 AND BREW_ICU_PREFIX)
message(STATUS "Found Homebrew icu4c at: ${BREW_ICU_PREFIX}")
set(ICU_BREW_INCLUDE "${BREW_ICU_PREFIX}/include")
set(ICU_BREW_LIB "${BREW_ICU_PREFIX}/lib")
endif()
find_path(ICU_INCLUDE_DIRS unicode/uchar.h
HINTS
${ICU_BREW_INCLUDE}
/opt/homebrew/opt/icu4c/include
/usr/local/opt/icu4c/include
/opt/homebrew/include
/usr/local/include
)
find_library(ICU_UC_LIBRARY
NAMES icuuc
HINTS
${ICU_BREW_LIB}
/opt/homebrew/opt/icu4c/lib
/usr/local/opt/icu4c/lib
/opt/homebrew/lib
/usr/local/lib
)
find_library(ICU_IO_LIBRARY
NAMES icuio
HINTS
${ICU_BREW_LIB}
/opt/homebrew/opt/icu4c/lib
/usr/local/opt/icu4c/lib
/opt/homebrew/lib
/usr/local/lib
)
find_library(ICU_I18N_LIBRARY
NAMES icui18n
HINTS
${ICU_BREW_LIB}
/opt/homebrew/opt/icu4c/lib
/usr/local/opt/icu4c/lib
/opt/homebrew/lib
/usr/local/lib
)
else()
# Linux-specific paths
find_path(ICU_INCLUDE_DIRS unicode/uchar.h
HINTS /usr/include /usr/local/include
)
find_library(ICU_UC_LIBRARY
NAMES icuuc
HINTS /usr/lib /usr/lib64 /usr/local/lib
)
find_library(ICU_IO_LIBRARY
NAMES icuio
HINTS /usr/lib /usr/lib64 /usr/local/lib
)
find_library(ICU_I18N_LIBRARY
NAMES icui18n
HINTS /usr/lib /usr/lib64 /usr/local/lib
)
endif()
if(ICU_UC_LIBRARY AND ICU_IO_LIBRARY AND ICU_I18N_LIBRARY)
set(ICU_LIBRARIES ${ICU_UC_LIBRARY} ${ICU_IO_LIBRARY} ${ICU_I18N_LIBRARY})
set(ICU_FOUND TRUE)
message(STATUS "Found ICU: ${ICU_LIBRARIES}")
endif()
endif()
if(ICU_FOUND)
add_definitions(-DUSE_ICU)
if(ICU_INCLUDE_DIRS)
include_directories(SYSTEM ${ICU_INCLUDE_DIRS})
endif()
else()
message(FATAL_ERROR
"ICU not found. MygramDB requires ICU for Unicode normalization in production builds. "
"Install ICU (macOS: brew install icu4c, Linux: sudo apt-get install libicu-dev) "
"or configure with -DUSE_ICU=OFF for an explicit ASCII-only development build.")
endif()
endif()
# MySQL Client detection
option(USE_MYSQL "Use MySQL client library" ON)
if(USE_MYSQL)
# Try pkg-config first
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(MYSQL mysqlclient)
if(MYSQL_FOUND)
set(MYSQL_LIBRARIES ${MYSQL_LINK_LIBRARIES})
message(STATUS "Found MySQL client via pkg-config")
message(STATUS " Include dirs: ${MYSQL_INCLUDE_DIRS}")
message(STATUS " Libraries: ${MYSQL_LIBRARIES}")
endif()
endif()
# If pkg-config didn't find it, try manual detection
if(NOT MYSQL_FOUND)
if(APPLE)
# Check Homebrew paths for MySQL on macOS. Prefer mysql-client@8.4
# because that is the documented development dependency.
execute_process(
COMMAND brew --prefix mysql-client@8.4
OUTPUT_VARIABLE BREW_MYSQL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE BREW_MYSQL_RESULT
)
if(NOT BREW_MYSQL_RESULT EQUAL 0 OR NOT BREW_MYSQL_PREFIX)
execute_process(
COMMAND brew --prefix mysql-client
OUTPUT_VARIABLE BREW_MYSQL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE BREW_MYSQL_RESULT
)
endif()
if(BREW_MYSQL_RESULT EQUAL 0 AND BREW_MYSQL_PREFIX)
message(STATUS "Found Homebrew MySQL client at: ${BREW_MYSQL_PREFIX}")
set(MYSQL_BREW_INCLUDE "${BREW_MYSQL_PREFIX}/include/mysql")
set(MYSQL_BREW_LIB "${BREW_MYSQL_PREFIX}/lib")
endif()
find_path(MYSQL_INCLUDE_DIRS mysql.h
HINTS
${MYSQL_BREW_INCLUDE}
/opt/homebrew/opt/mysql-client@8.4/include/mysql
/opt/homebrew/opt/mysql-client/include/mysql
/usr/local/opt/mysql-client@8.4/include/mysql
/usr/local/opt/mysql-client/include/mysql
/opt/homebrew/opt/mysql/include/mysql
/usr/local/opt/mysql/include/mysql
/opt/homebrew/include/mysql
/usr/local/include/mysql
)
find_library(MYSQL_LIBRARIES
NAMES mysqlclient
HINTS
${MYSQL_BREW_LIB}
/opt/homebrew/opt/mysql-client@8.4/lib
/opt/homebrew/opt/mysql-client/lib
/usr/local/opt/mysql-client@8.4/lib
/usr/local/opt/mysql-client/lib
/opt/homebrew/opt/mysql/lib
/usr/local/opt/mysql/lib
/opt/homebrew/lib
/usr/local/lib
)
else()
# Linux paths
find_path(MYSQL_INCLUDE_DIRS mysql.h
PATHS
/usr/include/mysql
/usr/local/include/mysql
/usr/mysql/include/mysql
)
find_library(MYSQL_LIBRARIES
NAMES mysqlclient
PATHS
/usr/lib
/usr/local/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/mysql
)
endif()
if(MYSQL_INCLUDE_DIRS AND MYSQL_LIBRARIES)
set(MYSQL_FOUND TRUE)
message(STATUS "Found MySQL: ${MYSQL_LIBRARIES}")
endif()
endif()
if(MYSQL_FOUND)
add_definitions(-DUSE_MYSQL)
if(MYSQL_INCLUDE_DIRS)
include_directories(SYSTEM ${MYSQL_INCLUDE_DIRS})
endif()
else()
message(FATAL_ERROR "MySQL client library not found. Set -DUSE_MYSQL=OFF to build without MySQL support, or install it:\n"
" macOS: brew install mysql-client@8.4\n"
" Linux: sudo apt-get install libmysqlclient-dev")
endif()
endif()
# Third-party dependencies
add_subdirectory(third_party)
# Suppress warnings from third-party libraries
# roaring/spdlog also need PIC because they are linked (via mygramdb_utils)
# into the shared client library (libmygramclient.so).
if(TARGET roaring)
target_compile_options(roaring PRIVATE -w)
set_target_properties(roaring PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if(TARGET spdlog)
target_compile_options(spdlog PRIVATE -w)
set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if(TARGET yaml-cpp)
target_compile_options(yaml-cpp PRIVATE -w)
endif()
if(TARGET nlohmann_json)
# Header-only, so its warnings have to be silenced through the include path
# rather than with -w: an INTERFACE -w propagates to every consumer and would
# turn off -Wall/-Wextra across this project's own sources as well.
get_target_property(nlohmann_json_includes nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
if(nlohmann_json_includes)
set_target_properties(nlohmann_json PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${nlohmann_json_includes}")
endif()
endif()
if(TARGET nlohmann_json_schema_validator)
target_compile_options(nlohmann_json_schema_validator PRIVATE -w)
endif()
# Suppress warnings from abseil (many targets)
function(suppress_warnings_recursively dir)
get_property(targets DIRECTORY "${dir}" PROPERTY BUILDSYSTEM_TARGETS)
foreach(target ${targets})
get_target_property(type ${target} TYPE)
if(type STREQUAL "STATIC_LIBRARY" OR type STREQUAL "SHARED_LIBRARY" OR type STREQUAL "OBJECT_LIBRARY")
target_compile_options(${target} PRIVATE -w)
endif()
endforeach()
get_property(subdirs DIRECTORY "${dir}" PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirs})
suppress_warnings_recursively("${subdir}")
endforeach()
endfunction()
if(abseil_SOURCE_DIR)
suppress_warnings_recursively(${abseil_SOURCE_DIR})
endif()
# Source
add_subdirectory(src)
# Fuzzers are opt-in local tools. They deliberately are not CTest targets and
# therefore do not alter the CI test gate.
if(BUILD_FUZZERS)
add_subdirectory(tests/fuzz)
endif()
# Tests
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Code Coverage Report Targets
if(ENABLE_COVERAGE)
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)
if(LCOV_PATH AND GENHTML_PATH)
# Get number of processors for parallel test execution
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
set(CTEST_PARALLEL_ARGS --parallel ${N})
endif()
# Add target to generate HTML coverage report (excludes SLOW and LOAD tests for faster CI).
# SLOW tests (10-25s each) and LOAD tests (large dataset) are excluded to keep CI feedback loop fast.
# To include them, use: make coverage-full
add_custom_target(coverage
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
COMMAND ${LCOV_PATH} --directory . --zerocounters
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure ${CTEST_PARALLEL_ARGS} --label-exclude "SLOW|LOAD"
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info --ignore-errors inconsistent,format,mismatch,negative --rc derive_function_end_line=0
COMMAND ${LCOV_PATH} --extract ${CMAKE_BINARY_DIR}/coverage/coverage.info
${CMAKE_SOURCE_DIR}/src/**
--output-file ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info --ignore-errors inconsistent,format,mismatch,negative,unused,source --rc derive_function_end_line=0
COMMAND ${GENHTML_PATH} ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info
--output-directory ${CMAKE_BINARY_DIR}/coverage/html --ignore-errors source,inconsistent,corrupt,category --rc derive_function_end_line=0
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report generated: ${CMAKE_BINARY_DIR}/coverage/html/index.html"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating code coverage report (excluding SLOW and LOAD tests)"
VERBATIM
)
# Add target to generate coverage report with ALL tests (including SLOW)
add_custom_target(coverage-full
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
COMMAND ${LCOV_PATH} --directory . --zerocounters
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure ${CTEST_PARALLEL_ARGS}
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info --ignore-errors inconsistent,format,mismatch,negative --rc derive_function_end_line=0
COMMAND ${LCOV_PATH} --extract ${CMAKE_BINARY_DIR}/coverage/coverage.info
${CMAKE_SOURCE_DIR}/src/**
--output-file ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info --ignore-errors inconsistent,format,mismatch,negative,unused,source --rc derive_function_end_line=0
COMMAND ${GENHTML_PATH} ${CMAKE_BINARY_DIR}/coverage/coverage_filtered.info
--output-directory ${CMAKE_BINARY_DIR}/coverage/html --ignore-errors source,inconsistent,corrupt,category --rc derive_function_end_line=0
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report generated: ${CMAKE_BINARY_DIR}/coverage/html/index.html"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating code coverage report (including ALL tests)"
VERBATIM
)
# Add target to clean coverage data
add_custom_target(coverage-clean
COMMAND ${LCOV_PATH} --directory . --zerocounters
COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Cleaning coverage data"
)
else()
message(WARNING "lcov and genhtml not found. Coverage report target will not be available.")
message(WARNING "Install with: brew install lcov (macOS) or sudo apt-get install lcov (Linux)")
endif()
endif()
# Install
install(TARGETS mygramdb DESTINATION bin)
# Install configuration examples
install(FILES examples/config.yaml DESTINATION etc/mygramdb RENAME config.yaml.example)
install(FILES examples/config-minimal.yaml DESTINATION etc/mygramdb)
install(FILES examples/config.json DESTINATION etc/mygramdb RENAME config.json.example)
install(FILES examples/config-minimal.json DESTINATION etc/mygramdb)
install(FILES
examples/client/CMakeLists.txt
examples/client/README.md
examples/client/c_search.c
examples/client/cpp_search.cpp
DESTINATION share/doc/mygramdb/examples/client
)
# Install JSON Schema (for reference - embedded in binary)
install(FILES src/config/config-schema.json DESTINATION share/mygramdb)
# Install documentation
install(FILES README.md LICENSE DESTINATION share/doc/mygramdb)