Enable clang-tidy

Adding a custom target `clang-tidy` that will run `run-clang-tidy` if
it is available and the compiler database is enabled. If the compiler
database is not enabled but `run-clang-tidy` is found, a warning will
be printed and the custom command will not be added.
This commit is contained in:
Mats Kindahl 2020-04-16 14:17:42 +02:00 committed by Mats Kindahl
parent 5a6fd603e6
commit 685f8bf9f0
2 changed files with 20 additions and 0 deletions

6
.clang-tidy Normal file
View File

@ -0,0 +1,6 @@
---
Checks: '-*,clang-analyzer-core.*,clang-diagnostic-*'
WarningsAsErrors: 'clang-analyzer-unix.*,clang-analyzer-core.NullDereference'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
...

View File

@ -284,6 +284,20 @@ else()
)
endif ()
find_program(RUN_CLANG_TIDY run-clang-tidy DOC "The path to run-clang-tidy")
if(RUN_CLANG_TIDY)
message(STATUS "Found clang-tidy at ${RUN_CLANG_TIDY}")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
add_custom_target(clang-tidy COMMAND ${RUN_CLANG_TIDY} -quiet)
else()
message(WARNING "You need to add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to use clang-tidy")
add_custom_target(clang-tidy
COMMAND ${CMAKE_COMMAND} -E echo "clang-tidy found but -DCMAKE_EXPORT_COMPILE_COMMAND was not set")
endif()
else()
message(WARNING "Did not find clang-tidy, not defining clang-tidy target.")
endif()
option(USE_OPENSSL "Enable use of OpenSSL if available" ON)
option(SEND_TELEMETRY_DEFAULT "The default value for whether to send telemetry" ON)