From 92fc2b3ccb03250dc9acb58abbb6990382c03346 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 18 Apr 2020 16:23:08 +0200 Subject: [PATCH] cmake: Add support for running clang-tidy Adds supports for running clang-tidy from within CMake, if the Clang toolset was found. This feature is experimental, but should work on many compilers, as it relies on generated compile_commands.json which are fully generated by the clang subproject. Using clang-tidy we can find hidden bugs that other static analyzers do not detect, or compilers don't even bother throwing an error for. --- .clang-tidy | 35 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 10 +++++++++- cmake/clang | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..152e03a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,35 @@ +Checks: '-*,clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,portability-*,readability-*,performance-*' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: Xaymar +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '1' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fa41aa..19caca7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -909,6 +909,7 @@ set_target_properties( ${PROJECT_NAME} PROPERTIES CXX_STANDARD ${_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS ${_CXX_EXTENSIONS} ) @@ -947,8 +948,15 @@ if(HAVE_OBS_FRONTEND) ) endif() -# Clang-Format +# Clang Tools if(HAVE_CLANG) + generate_compile_commands_json( + TARGETS ${PROJECT_NAME} + ) + clang_tidy( + TARGETS ${PROJECT_NAME} + VERSION 9.0.0 + ) clang_format( TARGETS ${PROJECT_NAME} DEPENDENCY diff --git a/cmake/clang b/cmake/clang index 9166c8a..58da85a 160000 --- a/cmake/clang +++ b/cmake/clang @@ -1 +1 @@ -Subproject commit 9166c8a575a2a6bf4c029cfefc84d4bbe62befc5 +Subproject commit 58da85a255b468ad170603e9528d63cf0d73bd27