diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-09-06 21:34:44 (GMT) |
---|---|---|
committer | Igor-Mikhail-Valentin Glebov <iglebov@albany.edu> | 2022-10-12 17:39:30 (GMT) |
commit | 6c6912123e8cc11af616744683d134e4dee37873 (patch) | |
tree | 518d52de6893d5a57758e0284fbd2393b3afa74d /CMakeLists.txt | |
parent | 0ad3941f737957fdb731eeb092ec13a1f8ca57a9 (diff) | |
download | CMake-6c6912123e8cc11af616744683d134e4dee37873.zip CMake-6c6912123e8cc11af616744683d134e4dee37873.tar.gz CMake-6c6912123e8cc11af616744683d134e4dee37873.tar.bz2 |
clang-tidy: Add option to load CMake's clang-tidy module
Issue: #23912
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b9eb2d..8181284 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -277,6 +277,16 @@ if(CMake_RUN_CLANG_TIDY) endif() set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + option(CMake_USE_CLANG_TIDY_MODULE "Use CMake's clang-tidy module." OFF) + if(CMake_USE_CLANG_TIDY_MODULE) + find_library(CMake_CLANG_TIDY_MODULE NAMES cmake-clang-tidy-module DOC "Location of the clang-tidy module") + if(NOT CMake_CLANG_TIDY_MODULE) + message(FATAL_ERROR "CMake_USE_CLANG_TIDY_MODULE is ON but cmake-clang-tidy-module is not found!") + endif() + list(APPEND CMAKE_CXX_CLANG_TIDY "--load=${CMake_CLANG_TIDY_MODULE}") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMake_CLANG_TIDY_MODULE}") + endif() + # Create a preprocessor definition that depends on .clang-tidy content so # the compile command will change when .clang-tidy changes. This ensures # that a subsequent build re-runs clang-tidy on all sources even if they @@ -286,6 +296,11 @@ if(CMake_RUN_CLANG_TIDY) file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1) set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}") unset(clang_tidy_sha1) + if(CMake_USE_CLANG_TIDY_MODULE) + file(SHA1 "${CMake_CLANG_TIDY_MODULE}" clang_tidy_module_sha1) + list(APPEND CLANG_TIDY_DEFINITIONS "CLANG_TIDY_MODULE_SHA1=${clang_tidy_module_sha1}") + unset(clang_tidy_module_sha1) + endif() endif() configure_file(.clang-tidy .clang-tidy COPYONLY) |