2020-09-17 15:37:23 +00:00
|
|
|
# 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)
|
|
|
|
|
2022-11-02 19:29:13 +00:00
|
|
|
find_program (CLANG_TIDY_CACHE_PATH NAMES "clang-tidy-cache")
|
|
|
|
if (CLANG_TIDY_CACHE_PATH)
|
|
|
|
find_program (_CLANG_TIDY_PATH NAMES "clang-tidy" "clang-tidy-15" "clang-tidy-14" "clang-tidy-13" "clang-tidy-12")
|
|
|
|
|
|
|
|
# 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 ()
|
|
|
|
find_program (CLANG_TIDY_PATH NAMES "clang-tidy" "clang-tidy-15" "clang-tidy-14" "clang-tidy-13" "clang-tidy-12")
|
|
|
|
endif ()
|
2020-09-17 15:37:23 +00:00
|
|
|
|
2020-03-08 20:17:49 +00:00
|
|
|
if (CLANG_TIDY_PATH)
|
2022-11-02 19:28:30 +00:00
|
|
|
message (STATUS
|
2020-09-17 15:37:23 +00:00
|
|
|
"Using clang-tidy: ${CLANG_TIDY_PATH}.
|
|
|
|
The checks will be run during build process.
|
|
|
|
See the .clang-tidy file at 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 ()
|