diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-10-14 15:01:38 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-10-14 15:01:58 (GMT) |
commit | 153f39f4a56fb89af5e08258853e3c013733df70 (patch) | |
tree | 7c57092dcdd50646337cad54e680f196abce11b0 | |
parent | 83663325f664af7ddcf3ecdff746d30d9fca3420 (diff) | |
parent | d6f5e67f7bce23d77ab98ef935f53d467b562bab (diff) | |
download | CMake-153f39f4a56fb89af5e08258853e3c013733df70.zip CMake-153f39f4a56fb89af5e08258853e3c013733df70.tar.gz CMake-153f39f4a56fb89af5e08258853e3c013733df70.tar.bz2 |
Merge topic 'clang-tidy-plugin-stub'
d6f5e67f7b ci: add clang-tidy plugin to clang-tidy job
6c6912123e clang-tidy: Add option to load CMake's clang-tidy module
0ad3941f73 clang-tidy module: Add stub module
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7768
-rw-r--r-- | .gitlab/ci/configure_fedora36_tidy.cmake | 2 | ||||
-rw-r--r-- | .gitlab/ci/env_fedora36_tidy.sh | 3 | ||||
-rw-r--r-- | CMakeLists.txt | 15 | ||||
-rw-r--r-- | Utilities/ClangTidyModule/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Utilities/ClangTidyModule/Module.cxx | 22 |
5 files changed, 57 insertions, 0 deletions
diff --git a/.gitlab/ci/configure_fedora36_tidy.cmake b/.gitlab/ci/configure_fedora36_tidy.cmake index 38414d3..2d0eeeb 100644 --- a/.gitlab/ci/configure_fedora36_tidy.cmake +++ b/.gitlab/ci/configure_fedora36_tidy.cmake @@ -1,3 +1,5 @@ set(CMake_RUN_CLANG_TIDY ON CACHE BOOL "") +set(CMake_USE_CLANG_TIDY_MODULE ON CACHE BOOL "") +set(CMake_CLANG_TIDY_MODULE "$ENV{CI_PROJECT_DIR}/Utilities/ClangTidyModule/build/libcmake-clang-tidy-module.so" CACHE FILEPATH "") include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora36_common.cmake") diff --git a/.gitlab/ci/env_fedora36_tidy.sh b/.gitlab/ci/env_fedora36_tidy.sh new file mode 100644 index 0000000..428b60e --- /dev/null +++ b/.gitlab/ci/env_fedora36_tidy.sh @@ -0,0 +1,3 @@ +cmake -S Utilities/ClangTidyModule -B Utilities/ClangTidyModule/build +cmake --build Utilities/ClangTidyModule/build +ctest --test-dir Utilities/ClangTidyModule/build diff --git a/CMakeLists.txt b/CMakeLists.txt index b2ca218..73c2c2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,6 +273,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 @@ -282,6 +292,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) diff --git a/Utilities/ClangTidyModule/CMakeLists.txt b/Utilities/ClangTidyModule/CMakeLists.txt new file mode 100644 index 0000000..bd87977 --- /dev/null +++ b/Utilities/ClangTidyModule/CMakeLists.txt @@ -0,0 +1,15 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. +cmake_minimum_required(VERSION 3.13) +project(CMakeClangTidyModule C CXX) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Clang REQUIRED) + +add_library(cmake-clang-tidy-module MODULE + Module.cxx + ) +target_include_directories(cmake-clang-tidy-module PRIVATE ${CLANG_INCLUDE_DIRS}) +target_link_libraries(cmake-clang-tidy-module PRIVATE clang-tidy) diff --git a/Utilities/ClangTidyModule/Module.cxx b/Utilities/ClangTidyModule/Module.cxx new file mode 100644 index 0000000..4bb6dc0 --- /dev/null +++ b/Utilities/ClangTidyModule/Module.cxx @@ -0,0 +1,22 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#include <clang-tidy/ClangTidyModule.h> +#include <clang-tidy/ClangTidyModuleRegistry.h> + +namespace clang { +namespace tidy { +namespace cmake { +class CMakeClangTidyModule : public ClangTidyModule +{ +public: + void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override + { + // TODO + } +}; + +static ClangTidyModuleRegistry::Add<CMakeClangTidyModule> X( + "cmake-clang-tidy", "Adds lint checks for the CMake code base."); +} +} +} |