File: ITKClangTidySetup.cmake

package info (click to toggle)
insighttoolkit5 5.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 704,404 kB
  • sloc: cpp: 783,697; ansic: 628,724; xml: 44,704; fortran: 34,250; python: 22,874; sh: 4,078; pascal: 2,636; lisp: 2,158; makefile: 461; yacc: 328; asm: 205; perl: 203; lex: 146; tcl: 132; javascript: 98; csh: 81
file content (41 lines) | stat: -rw-r--r-- 1,450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Provides itk_clangtidy_setup to assist with maintaining consistent
# c++ best practices across the ITK toolkit
#
# Clang-tidy version 8.0 or greater is required
#
# The ITK C++ best practices guidelines are represented by clang-tidy
# rules defined in ${ITK_SOURCE_DIR}/.clang-tidy
#
option(ITK_USE_CLANGTIDY "Enable the use of clang-tidy to enforce coding best practices." OFF)
mark_as_advanced(ITK_USE_CLANGTIDY)

if(ITK_USE_CLANGTIDY)
  if(ITK_USE_CLANGTIDY AND NOT EXISTS "${CLANGTIDY_EXECUTABLE}")
    find_program(
      CLANGTIDY_EXECUTABLE
      NAMES clang-tidy-13
            clang-tidy-12
            clang-tidy-11
            clang-tidy-10
            clang-tidy-9
            clang-tidy-9
            clang-tidy-8
            clang-tidy)
  endif()

  if(CLANGTIDY_EXECUTABLE AND EXISTS "${CLANGTIDY_EXECUTABLE}")
    mark_as_advanced(CLANGTIDY_EXECUTABLE)
    set(CLANG_TIDY_CHECKS "-*,modernize-use-*")
    set(CMAKE_CXX_CLANG_TIDY
        "${CLANGTIDY_EXECUTABLE};-checks=${CLANG_TIDY_CHECKS};-header-filter='${CMAKE_SOURCE_DIR}/Modules/*/*/include'")

    # Compile commands are required by clang-tidy
    set(CMAKE_EXPORT_COMPILE_COMMANDS
        ON
        CACHE BOOL "compile_commands.json file is needed by clang-tidy")
  else()
    unset(CLANGTIDY_EXECUTABLE)
    unset(CMAKE_CXX_CLANG_TIDY)
    message(FATAL_ERROR "Missing suitable clang-tidy executable, set CLANGTIDY_EXECUTABLE variable to desired path")
  endif()
endif()