-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
113 lines (91 loc) · 2.81 KB
/
Copy pathCMakeLists.txt
File metadata and controls
113 lines (91 loc) · 2.81 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
cmake_minimum_required(VERSION 3.22.0)
project(cppfig VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(CompileCommands)
include(Coverage)
include(Docs)
# Enable copying of compile_commands.json to project root
copy_compile_commands()
find_package(GTest CONFIG REQUIRED)
# Optional serializer back-ends
option(CPPFIG_ENABLE_JSON "Enable JSON serializer (requires nlohmann-json)" OFF)
# When building in-tree we always need JSON for the tests & benchmarks.
# Detect whether nlohmann-json is available and enable automatically.
find_package(nlohmann_json CONFIG QUIET)
if(nlohmann_json_FOUND)
set(CPPFIG_ENABLE_JSON ON CACHE BOOL "" FORCE)
message(STATUS "nlohmann-json found — CPPFIG_ENABLE_JSON=ON")
else()
message(STATUS "nlohmann-json not found — JSON serializer disabled")
endif()
# Future: option(CPPFIG_ENABLE_TOML "Enable TOML serializer" OFF)
option(STRICT_BUILD "Enable warnings as errors" ON)
if(STRICT_BUILD)
message(STATUS "Strict build enabled — adding comprehensive compiler warnings")
# Warnings common to GCC and Clang
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Werror
# Type-safety & conversions
-Wconversion
-Wsign-conversion
-Wdouble-promotion
-Wfloat-equal
-Wcast-align
-Wcast-qual
# C++ best practices
-Wold-style-cast
-Woverloaded-virtual
-Wnon-virtual-dtor
-Wshadow
-Wundef
# Control-flow & logic
-Wimplicit-fallthrough
-Wswitch-enum
-Wnull-dereference
# Formatting & style
-Wformat=2
-Wmisleading-indentation
-Wunused
-Wredundant-decls
)
# GCC-only warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
-Wsuggest-override
-Wstringop-overflow=4
-Warray-bounds=2
)
endif()
# Clang-only warnings
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
-Wextra-semi
-Wnewline-eof
-Wheader-hygiene
-Wdocumentation
)
endif()
endif()
configure_file(CMakeConfig.h.in "${CMAKE_BINARY_DIR}/CMakeConfig.h")
include_directories(${CMAKE_BINARY_DIR})
# Uncomment to enable clang-tidy during compilation
# set(CMAKE_CXX_CLANG_TIDY clang-tidy;-fix;-fix-errors)
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(test)
add_subdirectory(benchmark)
include(CTest)
# Add coverage targets if coverage is enabled
add_coverage_target()
include(CPackConfig.cmake)
include(CPack)