|
1 | 1 | if(WIN32)
|
2 |
| - # CMAKE_EXPORT_COMPILE_COMMANDS is not working on Windows |
3 |
| - message(STATUS "clang-tidy is not supported on Windows") |
| 2 | + if (NOT CMAKE_GENERATOR STREQUAL "Ninja") |
| 3 | + set(NOT_SUPPORTED_MESSAGE "clang-tidy is only supported with Ninja generator on Microsoft Windows.") |
| 4 | + message(STATUS "${NOT_SUPPORTED_MESSAGE}") |
| 5 | + |
| 6 | + # For the target not to fail: |
| 7 | + add_custom_target(tidy COMMAND echo "${NOT_SUPPORTED_MESSAGE}") |
| 8 | + return() |
| 9 | + else() |
| 10 | + find_package (Python COMPONENTS Interpreter) |
| 11 | + |
| 12 | + if(NOT Python_Interpreter_FOUND) |
| 13 | + set(PYTHON_MISSING_MESSAGE "Python interpreter not found, it is required for run-clang-tidy.py") |
| 14 | + message(STATUS "${PYTHON_MISSING_MESSAGE}") |
| 15 | + add_custom_target(tidy COMMAND echo "${PYTHON_MISSING_MESSAGE}") |
| 16 | + return() |
| 17 | + endif() |
| 18 | + endif() |
| 19 | +endif() |
| 20 | + |
| 21 | +find_program(CLANG_TIDY NAMES run-clang-tidy-7.py run-clang-tidy.py) |
4 | 22 |
|
5 |
| - # For the target not to fail: |
6 |
| - add_custom_target(tidy COMMAND echo "not supported on Windows") |
| 23 | +if(NOT CLANG_TIDY) |
| 24 | + message(STATUS "Did not find clang-tidy, target tidy is disabled.") |
| 25 | + message(STATUS "If clang-tidy is installed, make sure run-clang-tidy.py and clang-tidy is in PATH") |
7 | 26 |
|
| 27 | + # For the target not to fail: |
| 28 | + add_custom_target(tidy COMMAND echo "Clang-tidy is not installed") |
8 | 29 | else()
|
9 |
| - find_program(CLANG_TIDY NAMES run-clang-tidy.py run-clang-tidy-6.0.py) |
10 |
| - if(NOT CLANG_TIDY) |
11 |
| - |
12 |
| - message(STATUS "Did not find clang-tidy, target tidy is disabled.") |
13 |
| - message(STATUS "If clang-tidy is installed, make sure run-clang-tidy.py is in PATH") |
14 |
| - |
15 |
| - # For the target not to fail: |
16 |
| - add_custom_target(tidy COMMAND echo "Clang-tidy is not installed") |
17 |
| - |
18 |
| - else() |
19 |
| - message(STATUS "Found clang-tidy, use \"make tidy\" to run it.") |
20 |
| - |
21 |
| - # This will create build/compile_commands.json |
22 |
| - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
23 |
| - |
24 |
| - set(CLANG_TIDY_CHECKS "*") |
25 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-header-guard") |
26 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-include-order") |
27 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-namespace-comment") |
28 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-readability-else-after-return") |
29 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-misc-macro-parentheses") |
30 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-analyzer-alpha.core.CastToStruct") |
31 |
| - # Modernize |
32 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-modernize-raw-string-literal") |
33 |
| - # CPP Core Guidelines |
34 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-array-to-pointer-decay") |
35 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-constant-array-index") |
36 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-pointer-arithmetic") |
37 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-member-init") # as of https://llvm.org/bugs/show_bug.cgi?id=31039 |
38 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-reinterpret-cast") |
39 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-vararg") |
40 |
| - # Google |
41 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-namespace-comments") |
42 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-braces-around-statements,-readability-braces-around-statements") |
43 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-todo") |
44 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-int") |
45 |
| - set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-references") |
46 |
| - set(CLANG_TIDY_CHECKS "-checks='${CLANG_TIDY_CHECKS}'") |
47 |
| - |
48 |
| - add_custom_target(tidy |
49 |
| - COMMAND ${CLANG_TIDY} ${CLANG_TIDY_CHECKS} |
50 |
| - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build/ |
51 |
| - ) |
52 |
| - endif() |
| 30 | + message(STATUS "Found clang-tidy, use \"cmake --build . --target tidy\" to run it.") |
| 31 | + |
| 32 | + # This will create build/compile_commands.json |
| 33 | + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 34 | + |
| 35 | + # Configuration of rules are picked up from .clang-tidy |
| 36 | + message(STATUS "Picking up clang-tidy rules from ${CMAKE_SOURCE_DIR}/.clang-tidy") |
| 37 | + set(CLANG_TIDY_ARGS "-header-filter=.*") |
| 38 | + |
| 39 | + if (WIN32) |
| 40 | + add_custom_target(tidy |
| 41 | + COMMAND ${Python_EXECUTABLE} ${CLANG_TIDY} ${CLANG_TIDY_ARGS} . |
| 42 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 43 | + ) |
| 44 | + else() |
| 45 | + add_custom_target(tidy |
| 46 | + COMMAND ${CLANG_TIDY} ${CLANG_TIDY_ARGS} . |
| 47 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 48 | + ) |
| 49 | + endif() |
53 | 50 | endif()
|
54 |
| - |
0 commit comments