ClickHouse/cmake/clang_tidy.cmake

40 lines
1.7 KiB
CMake
Raw Permalink Normal View History

# https://clang.llvm.org/extra/clang-tidy/
option (ENABLE_CLANG_TIDY "Use clang-tidy static analyzer" OFF)
2020-03-08 20:17:49 +00:00
if (ENABLE_CLANG_TIDY)
find_program (CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
if (CLANG_TIDY_CACHE_PATH)
2024-03-13 08:39:03 +00:00
find_program (_CLANG_TIDY_PATH NAMES "clang-tidy-18" "clang-tidy-17" "clang-tidy-16" "clang-tidy")
# Why do we use ';' here?
# It's a cmake black magic: https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html#prop_tgt:%3CLANG%3E_CLANG_TIDY
# The CLANG_TIDY_PATH is passed to CMAKE_CXX_CLANG_TIDY, which follows CXX_CLANG_TIDY syntax.
set (CLANG_TIDY_PATH "${CLANG_TIDY_CACHE_PATH};${_CLANG_TIDY_PATH}" CACHE STRING "A combined command to run clang-tidy with caching wrapper")
else ()
2024-03-13 08:39:03 +00:00
find_program (CLANG_TIDY_PATH NAMES "clang-tidy-18" "clang-tidy-17" "clang-tidy-16" "clang-tidy")
endif ()
2020-03-08 20:17:49 +00:00
if (CLANG_TIDY_PATH)
2022-11-02 19:28:30 +00:00
message (STATUS
"Using clang-tidy: ${CLANG_TIDY_PATH}.
The checks will be run during the build process.
See the .clang-tidy file in the root directory to configure the checks.")
set (USE_CLANG_TIDY ON)
2021-03-19 14:23:04 +00:00
# clang-tidy requires assertions to guide the analysis
# Note that NDEBUG is set implicitly by CMake for non-debug builds
2022-11-02 19:28:30 +00:00
set (COMPILER_FLAGS "${COMPILER_FLAGS} -UNDEBUG")
2021-03-19 14:23:04 +00:00
2022-11-02 19:28:30 +00:00
# The variable CMAKE_CXX_CLANG_TIDY will be set inside the following directories with non third-party code.
# - base
# - programs
# - src
# - utils
2020-03-08 20:17:49 +00:00
# set (CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
else ()
2022-11-02 19:28:30 +00:00
message (${RECONFIGURE_MESSAGE_LEVEL} "clang-tidy is not found")
2020-03-08 20:17:49 +00:00
endif ()
endif ()