Skip to content

Commit eebbb5e

Browse files
leftibotclaude
andcommitted
Fix #139: rename dead preset cache vars so windows-clang disables analyzers
The conf-windows-common preset declared ENABLE_CPPCHECK_DEFAULT=FALSE and ENABLE_CLANG_TIDY_DEFAULT=FALSE in cacheVariables, intending to disable those analyzers for windows-clang and windows-msvc presets. Those names are not consumed anywhere; the actual options are myproject_ENABLE_CPPCHECK and myproject_ENABLE_CLANG_TIDY, so cppcheck ran on Windows with WARNINGS_AS_ERRORS=ON, errored on third-party headers in fmt/spdlog, and aborted the intro target build. Renaming the cache variables to the real option names makes the preset's intent take effect. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ec01c73 commit eebbb5e

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

CMakePresets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"strategy": "external"
3434
},
3535
"cacheVariables": {
36-
"ENABLE_CPPCHECK_DEFAULT": "FALSE",
37-
"ENABLE_CLANG_TIDY_DEFAULT": "FALSE"
36+
"myproject_ENABLE_CPPCHECK": "FALSE",
37+
"myproject_ENABLE_CLANG_TIDY": "FALSE"
3838
}
3939
},
4040
{

test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ endif()
2121

2222
include(${Catch2_SOURCE_DIR}/extras/Catch.cmake)
2323

24+
# Regression test for issue #139: ensure windows-clang preset actually disables
25+
# cppcheck/clang-tidy by setting the real project option names.
26+
add_test(
27+
NAME presets.windows_disables_static_analysis
28+
COMMAND
29+
${CMAKE_COMMAND}
30+
-DPRESETS_FILE=${CMAKE_SOURCE_DIR}/CMakePresets.json
31+
-P ${CMAKE_CURRENT_SOURCE_DIR}/test_cmake_presets.cmake)
32+
2433
# Provide a simple smoke test to make sure that the CLI works and can display a --help message
2534
add_test(NAME cli.has_help COMMAND intro --help)
2635

test/test_cmake_presets.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Regression test for issue #139.
2+
#
3+
# CMakePresets.json must disable cppcheck and clang-tidy on the windows-clang
4+
# preset using the project's actual option names, otherwise from-scratch builds
5+
# fail when WARNINGS_AS_ERRORS is on and cppcheck flags third-party headers.
6+
7+
if(NOT DEFINED PRESETS_FILE)
8+
message(FATAL_ERROR "PRESETS_FILE not defined")
9+
endif()
10+
11+
file(READ "${PRESETS_FILE}" PRESETS_JSON)
12+
13+
string(JSON CONFIGURE_PRESETS_LEN LENGTH "${PRESETS_JSON}" "configurePresets")
14+
math(EXPR LAST_PRESET_IDX "${CONFIGURE_PRESETS_LEN} - 1")
15+
16+
set(WINDOWS_PRESET_INDEX -1)
17+
foreach(I RANGE 0 ${LAST_PRESET_IDX})
18+
string(JSON NAME GET "${PRESETS_JSON}" "configurePresets" ${I} "name")
19+
if(NAME STREQUAL "conf-windows-common")
20+
set(WINDOWS_PRESET_INDEX ${I})
21+
break()
22+
endif()
23+
endforeach()
24+
25+
if(WINDOWS_PRESET_INDEX EQUAL -1)
26+
message(FATAL_ERROR "conf-windows-common preset not found in ${PRESETS_FILE}")
27+
endif()
28+
29+
string(JSON CACHE_VARS GET "${PRESETS_JSON}"
30+
"configurePresets" ${WINDOWS_PRESET_INDEX} "cacheVariables")
31+
32+
function(_assert_disabled var_name)
33+
string(JSON VAL ERROR_VARIABLE ERR GET "${CACHE_VARS}" "${var_name}")
34+
if(ERR)
35+
message(FATAL_ERROR
36+
"conf-windows-common cacheVariables is missing ${var_name}; "
37+
"expected it to disable the analyzer (issue #139). "
38+
"JSON error: ${ERR}")
39+
endif()
40+
if(NOT (VAL STREQUAL "OFF" OR VAL STREQUAL "FALSE" OR VAL STREQUAL "0" OR VAL STREQUAL "NO"))
41+
message(FATAL_ERROR
42+
"conf-windows-common cacheVariables sets ${var_name}=${VAL}, expected OFF/FALSE")
43+
endif()
44+
endfunction()
45+
46+
_assert_disabled("myproject_ENABLE_CPPCHECK")
47+
_assert_disabled("myproject_ENABLE_CLANG_TIDY")
48+
49+
message(STATUS "conf-windows-common correctly disables cppcheck and clang-tidy")

0 commit comments

Comments
 (0)