add a "run-clang-tidy" CMake target when the executable exists (#2567)

* CMakeLists.txt: there is no REQUIRED option for include()

* added a "run-clang-tidy" target when the executable exists / always create compilation database / added .clang-tidy with all existing warnings have been disabled for now
This commit is contained in:
Oliver Stöneberg 2020-04-02 13:55:49 +02:00 committed by GitHub
parent 71deaaeb18
commit 85b050acdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 8 deletions

5
.clang-tidy Normal file
View File

@ -0,0 +1,5 @@
---
Checks: '*,-abseil-*,-android-*,-cert-*,-cppcoreguidelines-*,-fuchsia-*,-google-*,-hicpp-*,-llvm-*,-linuxkernel-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-named-parameter,-readability-redundant-member-init,-performance-faster-string-find,-modernize-avoid-c-arrays,-modernize-use-equals-default,-modernize-use-using,-readability-container-size-empty,-readability-simplify-boolean-expr,-modernize-use-override,-modernize-pass-by-value,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-misc-unused-using-decls,-modernize-use-emplace,-readability-const-return-type,-performance-unnecessary-value-param,-readability-static-accessed-through-instance,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-performance-for-range-copy,-misc-throw-by-value-catch-by-reference,-modernize-use-bool-literals,-readability-avoid-const-params-in-decls,-readability-redundant-control-flow,-bugprone-argument-comment,-readability-redundant-string-cstr,-readability-non-const-parameter,-misc-non-private-member-variables-in-classes,-performance-unnecessary-copy-initialization,-readability-redundant-string-init,-bugprone-suspicious-string-compare,-bugprone-use-after-move,-readability-misleading-indentation,-misc-unused-parameters-,clang-analyzer-*'
CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'

View File

@ -1,15 +1,17 @@
project(Cppcheck) project(Cppcheck)
cmake_minimum_required(VERSION 2.8.11) cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs) include(GNUInstallDirs)
include(cmake/versions.cmake REQUIRED) include(cmake/versions.cmake)
include(cmake/options.cmake REQUIRED) include(cmake/options.cmake)
include(cmake/findDependencies.cmake REQUIRED) include(cmake/findDependencies.cmake)
include(cmake/compileroptions.cmake REQUIRED) include(cmake/compileroptions.cmake)
include(cmake/compilerDefinitions.cmake REQUIRED) include(cmake/compilerDefinitions.cmake)
include(cmake/buildFiles.cmake REQUIRED) include(cmake/buildFiles.cmake)
include(cmake/cxx11.cmake REQUIRED) include(cmake/cxx11.cmake)
use_cxx11() use_cxx11()
@ -30,4 +32,5 @@ ADD_SUBDIRECTORY(gui) # Graphical application
ADD_SUBDIRECTORY(tools/triage) # Triage tool ADD_SUBDIRECTORY(tools/triage) # Triage tool
add_subdirectory(oss-fuzz) # OSS-Fuzz clients add_subdirectory(oss-fuzz) # OSS-Fuzz clients
include(cmake/printInfo.cmake REQUIRED) include(cmake/printInfo.cmake)
include(cmake/clang_tidy.cmake)

13
cmake/clang_tidy.cmake Normal file
View File

@ -0,0 +1,13 @@
find_program(CLANG_TIDY NAMES clang-tidy clang-tidy-9 clang-tidy-8)
message(STATUS "CLANG_TIDY=${CLANG_TIDY}")
if (CLANG_TIDY)
set(CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/cli/*.cpp ${CMAKE_SOURCE_DIR}/lib/*.cpp)
if (BUILD_GUI)
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/gui/*.cpp)
endif()
if (BUILD_TESTS)
list(APPEND CLANG_TIDY_SRCS ${CMAKE_SOURCE_DIR}/test/*.cpp)
endif()
add_custom_target(run-clang-tidy ${CLANG_TIDY} -p=${CMAKE_BINARY_DIR} ${CLANG_TIDY_SRCS})
endif()