|
1 |
| -# Licensed to the LF AI & Data foundation under one |
2 |
| -# or more contributor license agreements. See the NOTICE file |
3 |
| -# distributed with this work for additional information |
4 |
| -# regarding copyright ownership. The ASF licenses this file |
5 |
| -# to you under the Apache License, Version 2.0 (the |
6 |
| -# "License"); you may not use this file except in compliance |
7 |
| -# with the License. You may obtain a copy of the License at |
8 |
| -# |
9 |
| -# http://www.apache.org/licenses/LICENSE-2.0 |
10 |
| -# |
11 |
| -# Unless required by applicable law or agreed to in writing, software |
12 |
| -# distributed under the License is distributed on an "AS IS" BASIS, |
13 |
| -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
| -# See the License for the specific language governing permissions and |
15 |
| -# limitations under the License. |
16 |
| -# |
17 |
| -# Tries to find the clang-tidy and clang-format modules |
18 |
| -# |
19 |
| -# Usage of this module as follows: |
20 |
| -# |
21 |
| -# find_package(ClangTools) |
22 |
| -# |
23 |
| -# Variables used by this module, they can change the default behaviour and need |
24 |
| -# to be set before calling find_package: |
25 |
| -# |
26 |
| -# ClangToolsBin_HOME - |
27 |
| -# When set, this path is inspected instead of standard library binary locations |
28 |
| -# to find clang-tidy and clang-format |
29 |
| -# |
30 |
| -# This module defines |
31 |
| -# CLANG_TIDY_BIN, The path to the clang tidy binary |
32 |
| -# CLANG_TIDY_FOUND, Whether clang tidy was found |
33 |
| -# CLANG_FORMAT_BIN, The path to the clang format binary |
34 |
| -# CLANG_TIDY_FOUND, Whether clang format was found |
| 1 | +# use pip install clang-tidy & clang-format |
35 | 2 |
|
36 | 3 | if (CMAKE_HOST_APPLE)
|
37 |
| - execute_process( |
38 |
| - COMMAND brew --prefix llvm |
39 |
| - OUTPUT_VARIABLE USER_LLVM_PATH |
40 |
| - OUTPUT_STRIP_TRAILING_WHITESPACE |
41 |
| - COMMAND_ERROR_IS_FATAL ANY |
42 |
| - ) |
43 |
| - set(USER_CLANG_TOOLS_PATH ${USER_LLVM_PATH}/bin) |
44 |
| - message(STATUS ${USER_CLANG_TOOLS_PATH}) |
| 4 | + execute_process( |
| 5 | + COMMAND brew --prefix llvm |
| 6 | + OUTPUT_VARIABLE USER_LLVM_PATH |
| 7 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 8 | + COMMAND_ERROR_IS_FATAL ANY |
| 9 | + ) |
| 10 | + set(USER_CLANG_TOOLS_PATH ${USER_LLVM_PATH}/bin) |
| 11 | + message(STATUS ${USER_CLANG_TOOLS_PATH}) |
45 | 12 | endif ()
|
46 | 13 |
|
47 | 14 | find_program(CLANG_TIDY_BIN
|
48 |
| - NAMES |
49 |
| - clang-tidy-14 |
50 |
| - clang-tidy-13 |
51 |
| - clang-tidy-10 |
52 |
| - clang-tidy |
53 |
| - PATHS ${ClangTools_PATH} $ENV{CLANG_TOOLS_PATH} ${USER_CLANG_TOOLS_PATH} /usr/local/bin /usr/bin |
| 15 | + NAMES |
| 16 | + clang-tidy |
| 17 | + PATHS |
| 18 | + ${USER_CLANG_TOOLS_PATH} |
| 19 | + ${ClangTools_PATH} |
| 20 | + $ENV{CLANG_TOOLS_PATH} |
| 21 | + $ENV{HOME}/.local/bin |
| 22 | + /usr/local/bin |
| 23 | + /usr/bin |
54 | 24 | NO_DEFAULT_PATH
|
55 | 25 | )
|
56 | 26 |
|
57 |
| -if ( "${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND" ) |
58 |
| - set(CLANG_TIDY_FOUND 0) |
59 |
| - message("clang-tidy not found") |
60 |
| -else() |
61 |
| - set(CLANG_TIDY_FOUND 1) |
62 |
| - message("clang-tidy found at ${CLANG_TIDY_BIN}") |
63 |
| -endif() |
64 |
| - |
65 |
| -if (CLANG_FORMAT_VERSION) |
66 |
| - find_program(CLANG_FORMAT_BIN |
67 |
| - NAMES clang-format-${CLANG_FORMAT_VERSION} |
68 |
| - PATHS |
69 |
| - ${ClangTools_PATH} |
70 |
| - $ENV{CLANG_TOOLS_PATH} |
71 |
| - ${USER_CLANG_TOOLS_PATH} |
72 |
| - /usr/local/bin /usr/bin |
73 |
| - NO_DEFAULT_PATH |
74 |
| - ) |
| 27 | +if ("${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND") |
| 28 | + set(CLANG_TIDY_FOUND 0) |
| 29 | + message("clang-tidy not found") |
| 30 | +else () |
| 31 | + set(CLANG_TIDY_FOUND 1) |
| 32 | + message("clang-tidy found at ${CLANG_TIDY_BIN}") |
| 33 | +endif () |
75 | 34 |
|
76 |
| - # If not found yet, search alternative locations |
77 |
| - if (("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND") AND APPLE) |
78 |
| - # Homebrew ships older LLVM versions in /usr/local/opt/llvm@version/ |
79 |
| - STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" CLANG_FORMAT_MAJOR_VERSION "${CLANG_FORMAT_VERSION}") |
80 |
| - STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" CLANG_FORMAT_MINOR_VERSION "${CLANG_FORMAT_VERSION}") |
81 |
| - if ("${CLANG_FORMAT_MINOR_VERSION}" STREQUAL "0") |
82 |
| - find_program(CLANG_FORMAT_BIN |
83 |
| - NAMES clang-format |
84 |
| - PATHS /usr/local/opt/llvm@${CLANG_FORMAT_MAJOR_VERSION}/bin |
85 |
| - NO_DEFAULT_PATH |
86 |
| - ) |
87 |
| - else() |
88 |
| - find_program(CLANG_FORMAT_BIN |
89 |
| - NAMES clang-format |
90 |
| - PATHS /usr/local/opt/llvm@${CLANG_FORMAT_VERSION}/bin |
91 |
| - NO_DEFAULT_PATH |
92 |
| - ) |
93 |
| - endif() |
94 |
| - endif() |
95 |
| -else() |
96 |
| - find_program(CLANG_FORMAT_BIN |
97 |
| - NAMES |
98 |
| - clang-format-14 |
99 |
| - clang-format-13 |
100 |
| - clang-format-10 |
101 |
| - clang-format |
102 |
| - PATHS ${ClangTools_PATH} $ENV{CLANG_TOOLS_PATH} ${USER_CLANG_TOOLS_PATH} /usr/local/bin /usr/bin |
103 |
| - NO_DEFAULT_PATH |
104 |
| - ) |
105 |
| -endif() |
| 35 | +find_program(CLANG_FORMAT_BIN |
| 36 | + NAMES |
| 37 | + clang-format |
| 38 | + PATHS |
| 39 | + clang-tidy |
| 40 | + PATHS |
| 41 | + ${USER_CLANG_TOOLS_PATH} |
| 42 | + ${ClangTools_PATH} |
| 43 | + $ENV{CLANG_TOOLS_PATH} |
| 44 | + $ENV{HOME}/.local/bin |
| 45 | + /usr/local/bin |
| 46 | + /usr/bin |
| 47 | + NO_DEFAULT_PATH |
| 48 | +) |
106 | 49 |
|
107 |
| -if ( "${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND" ) |
108 |
| - set(CLANG_FORMAT_FOUND 0) |
109 |
| - message("clang-format not found") |
110 |
| -else() |
111 |
| - set(CLANG_FORMAT_FOUND 1) |
112 |
| - message("clang-format found at ${CLANG_FORMAT_BIN}") |
113 |
| -endif() |
| 50 | +if ("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND") |
| 51 | + set(CLANG_FORMAT_FOUND 0) |
| 52 | + message("clang-format not found") |
| 53 | +else () |
| 54 | + set(CLANG_FORMAT_FOUND 1) |
| 55 | + message("clang-format found at ${CLANG_FORMAT_BIN}") |
| 56 | +endif () |
114 | 57 |
|
0 commit comments