include_guard(GLOBAL) set(CLANG_TIDY_NAMES clang-tidy) foreach(V RANGE 9 15) list(INSERT CLANG_TIDY_NAMES 0 "clang-tidy-${V}") endforeach() unset(V) find_program(CLANG_TIDY_EXE NAMES ${CLANG_TIDY_NAMES}) if(CLANG_TIDY_EXE) option(MYX_CMAKE_CLANG_TIDY_FIX "MyxCMake: perform fixes for Clang Tidy" OFF) endif() unset(CLANG_TIDY_NAMES) function(myx_cmake_analyze_clang_tidy target) if(CLANG_TIDY_EXE) set(_args -extra-arg="-Wno-unknown-warning-option") get_target_property(__sources ${target} SOURCES) list(FILTER __sources EXCLUDE REGEX "qrc_.*\\.cpp$") list(FILTER __sources EXCLUDE REGEX "moc_.*\\.cpp$") list(FILTER __sources EXCLUDE REGEX "ui_.*\\.h$") if(MYX_CMAKE_CLANG_TIDY_FIX) list(APPEND _args "-fix-errors") endif() if(NOT TARGET myx-cmake-analyze-clang-tidy) add_custom_target(myx-cmake-analyze-clang-tidy) endif() add_custom_target(${target}-analyze-clang-tidy WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${CLANG_TIDY_EXE} ${_args} -p ${CMAKE_BINARY_DIR} ${__sources}) add_dependencies(${target}-analyze-clang-tidy ${target}) add_dependencies(myx-cmake-analyze-clang-tidy ${target}-analyze-clang-tidy) else() message(STATUS "MyxCMake: Clang Tidy analyzer is not found") endif() endfunction()