5 # Find clang-tidy executable.
10 # This module defines the following variables:
12 # ``CLANG_TIDY_FOUND``, ``ClangTidy_FOUND``
14 # ``CLANG_TIDY_EXECUTABLE``
16 # ``CLANG_TIDY_VERSION``
21 # .. command:: add_clang_tidy
25 # add_clang_tidy([OPTIONS opt] [TARGETS tgt ...] [tgt ...])
27 include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
28 find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
29 mark_as_advanced(CLANG_TIDY_EXECUTABLE)
31 if(EXISTS "${CLANG_TIDY_EXECUTABLE}")
32 execute_process(COMMAND ${CLANG_TIDY_EXECUTABLE} --version OUTPUT_VARIABLE CLANG_TIDY_VERSION)
33 string(REGEX REPLACE ".*version ([^\n ]+).*" "\\1" CLANG_TIDY_VERSION "${CLANG_TIDY_VERSION}")
36 find_package_handle_standard_args(ClangTidy
46 set(CLANG_TIDY_FOUND 1)
47 function(add_clang_tidy)
48 if(CMAKE_VERSION VERSION_LESS 3.6)
51 cmake_parse_arguments(CLANG_TIDY "" "" "TARGETS;OPTIONS" ${ARGN})
52 list(APPEND CLANG_TIDY_TARGETS ${CLANG_TIDY_UNPARSED_ARGUMENTS})
53 get_cmake_property(ENABLED_LANGUAGES ENABLED_LANGUAGES)
54 foreach(LANG ${ENABLED_LANGUAGES})
55 set_target_properties(${CLANG_TIDY_TARGETS} PROPERTIES ${LANG}_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE};${CLANG_TIDY_OPTIONS}")