Merge topic 'clang-tidy-plugin-stub'
d6f5e67f7b
ci: add clang-tidy plugin to clang-tidy job6c6912123e
clang-tidy: Add option to load CMake's clang-tidy module0ad3941f73
clang-tidy module: Add stub module Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !7768
This commit is contained in:
commit
153f39f4a5
@ -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")
|
||||
|
3
.gitlab/ci/env_fedora36_tidy.sh
Normal file
3
.gitlab/ci/env_fedora36_tidy.sh
Normal file
@ -0,0 +1,3 @@
|
||||
cmake -S Utilities/ClangTidyModule -B Utilities/ClangTidyModule/build
|
||||
cmake --build Utilities/ClangTidyModule/build
|
||||
ctest --test-dir Utilities/ClangTidyModule/build
|
@ -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)
|
||||
|
15
Utilities/ClangTidyModule/CMakeLists.txt
Normal file
15
Utilities/ClangTidyModule/CMakeLists.txt
Normal file
@ -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)
|
22
Utilities/ClangTidyModule/Module.cxx
Normal file
22
Utilities/ClangTidyModule/Module.cxx
Normal file
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user