fix(cmake): use the real variables for static analysis tools

- CMAKE_CXX_IWYU is not a CMake variable. Use
  CMAKE_CXX_INCLUDE_WHAT_YOU_USE and the include-what-you-use program
- Store find_program results in their own variables instead of misusing
  the *_FOUND names as cache entries

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 22:13:04 +00:00
committed by Dennis Klein
parent 7d268912ae
commit b6407c53a4

View File

@@ -139,26 +139,38 @@ endif()
unset(PROJECT_STATIC_ANALYSERS)
if(RUN_STATIC_ANALYSIS)
set(analyser "clang-tidy")
find_program(${analyser}_FOUND "${analyser}")
if(${analyser}_FOUND)
set(CMAKE_CXX_CLANG_TIDY ${analyser} "--extra-arg=-std=c++17")
endif()
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
set(analyser "iwyu")
find_program(${analyser}_FOUND "${analyser}")
if(${analyser}_FOUND)
set(CMAKE_CXX_IWYU "${${analyser}_FOUND}")
endif()
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
set(analyser "cpplint")
find_program(${analyser}_FOUND "${analyser}")
if(${analyser}_FOUND)
set(CMAKE_CXX_CPPLINT "${${analyser}_FOUND}")
endif()
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
# <summary name> <program> <CMake variable that activates it>
set(_analysers
"clang-tidy|clang-tidy|CMAKE_CXX_CLANG_TIDY"
"iwyu|include-what-you-use|CMAKE_CXX_INCLUDE_WHAT_YOU_USE"
"cpplint|cpplint|CMAKE_CXX_CPPLINT"
)
foreach(_entry IN LISTS _analysers)
string(REPLACE "|" ";" _entry "${_entry}")
list(GET _entry 0 analyser)
list(GET _entry 1 _program)
list(GET _entry 2 _variable)
string(MAKE_C_IDENTIFIER "${analyser}" _id)
find_program(FAIRMQ_${_id}_EXECUTABLE NAMES ${_program})
mark_as_advanced(FAIRMQ_${_id}_EXECUTABLE)
if(FAIRMQ_${_id}_EXECUTABLE)
set(${analyser}_FOUND TRUE)
if(analyser STREQUAL "clang-tidy")
set(${_variable} ${FAIRMQ_${_id}_EXECUTABLE} "--extra-arg=-std=c++17")
else()
set(${_variable} ${FAIRMQ_${_id}_EXECUTABLE})
endif()
else()
set(${analyser}_FOUND FALSE)
endif()
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
endforeach()
unset(_analysers)
unset(_entry)
unset(_program)
unset(_variable)
unset(_id)
unset(analyser)
endif()
if(CMAKE_GENERATOR STREQUAL Ninja AND ENABLE_CCACHE)