Skip to content

Commit 7a18e1a

Browse files
committed
Add ccache support (close #1)
1 parent 4c4a847 commit 7a18e1a

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020
# === Options ===
2121
include(Options)
2222

23+
# === Cache ===
24+
include(Cache)
25+
2326
# === Compiler Flags ===
2427
include(CompilerFlags)
2528

CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"generator": "Ninja",
1313
"binaryDir": "${sourceDir}/build/${presetName}",
1414
"cacheVariables": {
15+
"ENABLE_CACHE": "OFF",
1516
"ENABLE_WARNINGS": "ON",
1617
"ENABLE_STRICT_WARNINGS": "ON",
1718
"ENABLE_TESTING": "ON",

cmake/Cache.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Cache.cmake — find and wire up ccache if ENABLE_CACHE is ON
2+
3+
if(ENABLE_CACHE)
4+
find_program(CCACHE_PROGRAM NAMES ccache)
5+
if(CCACHE_PROGRAM)
6+
message(STATUS "Found ccache: ${CCACHE_PROGRAM}")
7+
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
8+
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "" FORCE)
9+
else()
10+
message(WARNING "ccache requested but not found → continuing without caching")
11+
endif()
12+
endif()

cmake/Coverage.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if(ENABLE_COVERAGE)
2-
find_program(GCOVR_EXE gcovr REQUIRED)
2+
find_program(GCOVR_EXE NAMES gcovr REQUIRED)
33
set(COVERAGE_OUTPUT_DIR "${CMAKE_BINARY_DIR}")
44

55
add_custom_target(coverage

cmake/Options.cmake

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
#–– Options.cmake –– user‐facing toggles
22

33
# — Build Targets —
4-
option(ENABLE_TESTING "Build unit tests" ON)
5-
option(ENABLE_BENCHMARKS "Build benchmarks" OFF)
6-
option(BUILD_APP "Build the demo application" OFF)
4+
option(ENABLE_TESTING "Build unit tests" ON)
5+
option(ENABLE_BENCHMARKS "Build benchmarks" OFF)
6+
option(BUILD_APP "Build the demo application" OFF)
77

88
# — Quality Checks —
9-
option(ENABLE_WARNINGS "Enable compiler warnings" ON)
10-
option(ENABLE_STRICT_WARNINGS "Treat warnings as errors" ON)
11-
option(ENABLE_COVERAGE "Enable coverage instrumentation" OFF)
12-
option(ENABLE_SANITIZERS "Enable ASan / UBSan" OFF)
13-
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
14-
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
9+
option(ENABLE_WARNINGS "Enable compiler warnings" ON)
10+
option(ENABLE_STRICT_WARNINGS "Treat warnings as errors" ON)
11+
option(ENABLE_COVERAGE "Enable coverage instrumentation" OFF)
12+
option(ENABLE_SANITIZERS "Enable ASan / UBSan" OFF)
13+
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
14+
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
1515

1616
# — Static Analysis —
17-
option(ENABLE_CPPCHECK "Enable Cppcheck integration" ON)
18-
option(ENABLE_CLANG_TIDY "Enable clang-tidy integration" ON)
19-
option(ENABLE_CLANG_FORMAT "Enable clang-format integration" ON)
17+
option(ENABLE_CPPCHECK "Enable Cppcheck integration" ON)
18+
option(ENABLE_CLANG_TIDY "Enable clang-tidy integration" ON)
19+
option(ENABLE_CLANG_FORMAT "Enable clang-format integration" ON)
2020

21-
if(ENABLE_COVERAGE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
22-
message(WARNING "Coverage instrumentation is best used with Debug builds.")
23-
endif()
21+
option(ENABLE_CACHE "Enable ccache to speed up compilation" OFF)
2422

2523
# If someone turns on the “global” sanitizer switch, enable each one
2624
if(ENABLE_SANITIZERS)
2725
set(ENABLE_ASAN ON)
2826
set(ENABLE_UBSAN ON)
2927
endif()
28+
29+

cmake/Tooling.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ endif()
3434

3535
# clang-format
3636
if(ENABLE_CLANG_FORMAT)
37-
find_program(CLANG_FORMAT_EXE clang-format)
37+
find_program(CLANG_FORMAT_EXE NAMES clang-format)
3838

3939
if(CLANG_FORMAT_EXE)
4040
message(STATUS "Found clang-format: ${CLANG_TIDY_EXE}")
@@ -60,7 +60,7 @@ endif()
6060

6161
# cppcheck
6262
if(ENABLE_CPPCHECK)
63-
find_program(CPPCHECK_EXE cppcheck)
63+
find_program(CPPCHECK_EXE NAMES cppcheck)
6464

6565
if(CPPCHECK_EXE)
6666
message(STATUS "Found cppcheck: ${CLANG_TIDY_EXE}")
@@ -83,7 +83,7 @@ endif()
8383

8484
# clang-tidy
8585
if(ENABLE_CLANG_TIDY)
86-
find_program(CLANG_TIDY_EXE clang-tidy)
86+
find_program(CLANG_TIDY_EXE NAMES clang-tidy)
8787

8888
if (CLANG_TIDY_EXE)
8989
message(STATUS "Found clang-tidy: ${CLANG_TIDY_EXE}")

0 commit comments

Comments
 (0)