From 0ad3941f737957fdb731eeb092ec13a1f8ca57a9 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 31 Aug 2022 14:15:37 -0400 Subject: clang-tidy module: Add stub module Issue: #23912 --- Utilities/ClangTidyModule/CMakeLists.txt | 15 +++++++++++++++ Utilities/ClangTidyModule/Module.cxx | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Utilities/ClangTidyModule/CMakeLists.txt create mode 100644 Utilities/ClangTidyModule/Module.cxx 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 +#include + +namespace clang { +namespace tidy { +namespace cmake { +class CMakeClangTidyModule : public ClangTidyModule +{ +public: + void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override + { + // TODO + } +}; + +static ClangTidyModuleRegistry::Add X( + "cmake-clang-tidy", "Adds lint checks for the CMake code base."); +} +} +} -- cgit v0.12 From 6c6912123e8cc11af616744683d134e4dee37873 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 6 Sep 2022 17:34:44 -0400 Subject: clang-tidy: Add option to load CMake's clang-tidy module Issue: #23912 --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) -- cgit v0.12 From d6f5e67f7bce23d77ab98ef935f53d467b562bab Mon Sep 17 00:00:00 2001 From: Igor-Mikhail-Valentin Glebov Date: Sat, 8 Oct 2022 15:14:40 -0400 Subject: ci: add clang-tidy plugin to clang-tidy job --- .gitlab/ci/configure_fedora36_tidy.cmake | 2 ++ .gitlab/ci/env_fedora36_tidy.sh | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 .gitlab/ci/env_fedora36_tidy.sh 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 -- cgit v0.12