From 1cb1efab6e9f3d9399807c0130ef37dc3b12997f Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 29 Sep 2018 18:01:38 -0700 Subject: [PATCH] Add USE_CLANG_TIDY and CLANG_TIDY_TREAT_WARNINGS_AS_ERRORS options to cmake --- CMakeLists.txt | 2 ++ cmake-utils/utils.cmake | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cda3867..7566a23d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" "") diff --git a/cmake-utils/utils.cmake b/cmake-utils/utils.cmake index 9984419d..6c79440a 100644 --- a/cmake-utils/utils.cmake +++ b/cmake-utils/utils.cmake @@ -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) ##################################################