From 44f43bd62144b8c08fb52c6fac75e4fa82f3e457 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Wed, 31 May 2017 10:44:09 -0400 Subject: [PATCH] Adding clang tidy details --- .clang-tidy | 7 +++++++ CMakeLists.txt | 19 +++++++++++++++++++ examples/CMakeLists.txt | 19 +++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..f6ce8611 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,7 @@ +#Checks: '*,-clang-analyzer-alpha.*' +Checks: '-*,google-readability-casting,llvm-namespace-comment,performance-unnecessary-value-param,llvm-include-order,misc-throw-by-value-catch-by-reference,readability-container-size-empty,google-runtime-references,modernize*' +HeaderFilterRegex: '.*hpp' +CheckOptions: +- key: readability-braces-around-statements.ShortStatementLines + value: '1' + diff --git a/CMakeLists.txt b/CMakeLists.txt index e2bc16c2..2d8e980e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,24 @@ else() endif() +if(CMAKE_VERSION VERSION_GREATER 3.6) +# Add clang-tidy if available + option(CLANG_TIDY_FIX "Perform fixes for Clang-Tidy (resets to OFF)" OFF) + find_program( + CLANG_TIDY_EXE + NAMES "clang-tidy" + DOC "Path to clang-tidy executable" + ) + + if(CLANG_TIDY_EXE) + if(CLANG_TIDY_FIX) + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-fix") + else() + set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}") + endif() + endif() +endif() + if(CMAKE_BUILD_TYPE STREQUAL Coverage) include(CodeCoverage) @@ -64,3 +82,4 @@ if(CLI_EXAMPLES) add_subdirectory(examples) endif() +set(CLANG_TIDY_FIX OFF CACHE BOOL "Perform fixes for Clang-Tidy (resets to OFF)" FORCE) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 08ab9df5..6fae4456 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,8 +1,15 @@ -add_executable(try try.cpp ${CLI_headers}) -target_link_libraries(try PUBLIC CLI11) +function(add_cli_exe T) + add_executable(${T} ${ARGN} ${CLI_headers}) + target_link_libraries(${T} PUBLIC CLI11) -add_executable(try1 try1.cpp ${CLI_headers}) -target_link_libraries(try1 PUBLIC CLI11) + if(CLANG_TIDY_EXE) + set_target_properties( + ${T} PROPERTIES + CXX_CLANG_TIDY "${DO_CLANG_TIDY}" + ) + endif() +endfunction() -add_executable(try2 try2.cpp ${CLI_headers}) -target_link_libraries(try2 PUBLIC CLI11) +add_cli_exe(try try.cpp) +add_cli_exe(try1 try1.cpp) +add_cli_exe(try2 try2.cpp)