Skip to content

Commit

Permalink
Added the Clang-tidy support (ENABLE_CLANG_TIDY option for CMake). (v…
Browse files Browse the repository at this point in the history
…esoft-inc#214)

* Added the Clang-tidy support (ENABLE_CLANG_TIDY option for CMake).

* address laura's comment.
  • Loading branch information
monadbobo authored Sep 3, 2020
1 parent 4dc93bb commit 88ae9d6
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
141 changes: 141 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,-misc-unused-parameters,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
bugprone-branch-clone,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-infinite-loop,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-not-null-terminated-result,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-reserved-identifier,
bugprone-signed-char-misuse,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
google-build-explicit-make-pair,
google-build-namespaces,
google-build-using-namespace,
google-default-arguments,
google-explicit-constructor,
google-global-names-in-headers,
google-objc-avoid-nsobject-new,
google-objc-function-naming,
google-objc-global-variable-declaration,
google-readability-avoid-underscore-in-googletest-name,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
google-upgrade-googletest-case,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-bool-literals,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-nullptr,
modernize-use-override,
modernize-use-trailing-return-type,
modernize-use-transparent-functors,
modernize-use-using,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-constructor-init,
performance-no-automatic-move,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
'

HeaderFilterRegex: '/(?!third-party)|(?!interface)/'
AnalyzeTemporaryDtors: false
FormatStyle: 'file'
WarningsAsErrors: '*'
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- 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'
- key: readability-identifier-naming.EnumConstantCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantPrefix
value: k

13 changes: 13 additions & 0 deletions cmake/ClangTidy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if (ENABLE_CLANG_TIDY)
if (${CMAKE_VERSION} VERSION_LESS "3.6.0")
message(FATAL_ERROR "clang-tidy requires CMake version at least 3.6.")
endif()

find_program (CLANG_TIDY_PATH NAMES "clang-tidy")
if (CLANG_TIDY_PATH)
message(STATUS "Using clang-tidy: ${CLANG_TIDY_PATH}.")
set (CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_PATH} --config=)
else ()
message(STATUS "clang-tidy is not found.")
endif ()
endif ()
6 changes: 6 additions & 0 deletions cmake/ThriftGenerate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ add_library(
OBJECT
${${file_name}-cpp2-SOURCES}
)

set_target_properties(
"${file_name}_thrift_obj"
PROPERTIES CXX_CLANG_TIDY ""
)

target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-pedantic")
target_compile_options(${file_name}_thrift_obj PRIVATE "-Wno-extra")
export(
Expand Down
1 change: 1 addition & 0 deletions cmake/nebula/GeneralCMakeOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ option(ENABLE_STRICT_ALIASING "Build with -fstrict-aliasing" OFF)
option(ENABLE_COVERAGE "Build with coverage report" OFF)
option(ENABLE_PIC "Build with -fPIC" OFF)
option(ENABLE_COMPRESSED_DEBUG_INFO "Compress debug info to reduce binary size" ON)
option(ENABLE_CLANG_TIDY "Enable clang-tidy if present" OFF)

get_cmake_property(variable_list VARIABLES)
foreach(_varname ${variable_list})
Expand Down

0 comments on commit 88ae9d6

Please sign in to comment.