ClangTidy.cmake 898 B

123456789101112131415161718192021
  1. if(CMAKE_EXPORT_COMPILE_COMMANDS)
  2. find_program(CLANG_TIDY clang-tidy NAMES clang-tidy-3.9 clang-tidy-3.8 clang-tidy-3.7)
  3. find_program(CLANG_REPLACE clang-apply-replacements NAMES clang-apply-replacements-3.9 clang-apply-replacements-3.8 clang-apply-replacements-3.7)
  4. if(NOT CLANG_TIDY STREQUAL CLANG_TIDY-NOTFOUND)
  5. set(CLANG_TIDY_COMMAND ${PROJECT_SOURCE_DIR}/scripts/run-clang-tidy.py -clang-apply-replacements-binary ${CLANG_REPLACE} -clang-tidy-binary ${CLANG_TIDY} -header-filter=${PROJECT_SOURCE_DIR}/src/.*)
  6. add_custom_target(tidy
  7. COMMAND ${CLANG_TIDY_COMMAND} ${PROJECT_SOURCE_DIR}/src
  8. USES_TERMINAL
  9. )
  10. add_custom_target(tidy-fix
  11. COMMAND ${CLANG_TIDY_COMMAND} -fix ${PROJECT_SOURCE_DIR}/src
  12. USES_TERMINAL
  13. )
  14. endif()
  15. else()
  16. message(STATUS "clang-tidy not enabled, pass -DCMAKE_EXPORT_COMPILE_COMMANDS=on to cmake to enable it")
  17. endif()