Add USE_CLANG_TIDY and CLANG_TIDY_TREAT_WARNINGS_AS_ERRORS options to cmake

This commit is contained in:
Sebastian Messmer 2018-09-29 18:01:38 -07:00
parent d91a7358c0
commit 1cb1efab6e
2 changed files with 24 additions and 14 deletions

View File

@ -18,6 +18,8 @@ require_clang_version(4.0)
option(BUILD_TESTING "build test cases" OFF)
option(CRYFS_UPDATE_CHECKS "let cryfs check for updates and security vulnerabilities" ON)
option(DISABLE_OPENMP "allow building without OpenMP libraries. This will cause performance degradations." OFF)
option(USE_CLANG_TIDY "build with clang-tidy checks enabled" OFF)
option(CLANG_TIDY_WARNINGS_AS_ERRORS "treat clang-tidy warnings as errors" OFF)
if (MSVC)
option(DOKAN_PATH "Location of the Dokan library, e.g. C:\\Program Files\\Dokan\\DokanLibrary-1.1.0" "")

View File

@ -32,16 +32,22 @@ function(target_activate_cpp14 TARGET)
endfunction(target_activate_cpp14)
# Find clang-tidy executable (for use in target_enable_style_warnings)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(WARNING "clang-tidy not found. Checks are disabled")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-system-headers=0")
if (USE_CLANG_TIDY)
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(FATAL_ERROR "clang-tidy not found. Please install clang-tidy or run without -DUSE_CLANG_TIDY=on.")
else()
set(CLANG_TIDY_OPTIONS "-system-headers=0")
if (CLANG_TIDY_WARNINGS_AS_ERRORS)
set(CLANG_TIDY_OPTIONS "${CLANG_TIDY_OPTIONS}" "-warnings-as-errors=*")
endif()
message(STATUS "Clang-tidy is enabled. Executable: ${CLANG_TIDY_EXE} Arguments: ${CLANG_TIDY_OPTIONS}")
set(CLANG_TIDY_CLI "${CLANG_TIDY_EXE}" "${CLANG_TIDY_OPTIONS}")
endif()
endif()
#################################################
@ -57,10 +63,12 @@ function(target_enable_style_warnings TARGET)
endif()
# Enable clang-tidy
#set_target_properties(
# ${TARGET} PROPERTIES
# CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
#)
if(USE_CLANG_TIDY)
set_target_properties(
${TARGET} PROPERTIES
CXX_CLANG_TIDY "${CLANG_TIDY_CLI}"
)
endif()
endfunction(target_enable_style_warnings)
##################################################