forked from RoEdAl/asterisk-chan-quectel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang-format.cmake
executable file
·42 lines (34 loc) · 1.43 KB
/
clang-format.cmake
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
42
#!/usr/bin/cmake -P
FILE(REAL_PATH "~" HOME_DIR EXPAND_TILDE)
CMAKE_PATH(APPEND HOME_DIR .vscode extensions OUTPUT_VARIABLE VSCODE_EXTENSIONS_DIR)
IF(EXISTS ${VSCODE_EXTENSIONS_DIR})
FILE(GLOB CPPTOOLS_DIR "${VSCODE_EXTENSIONS_DIR}/ms-vscode.cpptools*")
FOREACH(P ${CPPTOOLS_DIR})
CMAKE_PATH(APPEND P LLVM bin OUTPUT_VARIABLE VSE_BIN_DIR)
IF(NOT EXISTS ${VSE_BIN_DIR})
CONTINUE()
ENDIF()
FIND_PROGRAM(CLANG_FORMAT NAME clang-format HINTS ${VSE_BIN_DIR} NO_CACHE NO_DEFAULT_PATH)
IF(NOT ${CLANG_FORMAT} STREQUAL "CLANG_FORMAT-NOTFOUND")
BREAK()
ENDIF()
ENDFOREACH()
ENDIF()
IF(NOT DEFINED CLANG_FORMAT OR ${CLANG_FORMAT} STREQUAL "CLANG_FORMAT-NOTFOUND")
FIND_PROGRAM(CLANG_FORMAT NAME clang-format NO_CACHE)
ENDIF()
IF(${CLANG_FORMAT} STREQUAL "CLANG_FORMAT-NOTFOUND")
MESSAGE(FATAL_ERROR "Cannot find clang-format utility")
ENDIF()
CMAKE_PATH(GET CMAKE_SCRIPT_MODE_FILE PARENT_PATH SCRIPT_DIR)
CMAKE_PATH(APPEND SCRIPT_DIR src OUTPUT_VARIABLE SCRIPT_SRC_DIR)
MESSAGE(DEBUG "VSCode extensions directory: ${VSCODE_EXTENSIONS_DIR}")
MESSAGE(DEBUG "Source directory: ${SCRIPT_SRC_DIR}")
MESSAGE(VERBOSE "clang-format path: ${CLANG_FORMAT}")
INCLUDE(${SCRIPT_SRC_DIR}/source-files.cmake)
EXECUTE_PROCESS(
COMMAND ${CLANG_FORMAT} -i --style=file ${SOURCES} ${HEADERS}
WORKING_DIRECTORY ${SCRIPT_SRC_DIR}
COMMAND_ERROR_IS_FATAL ANY
COMMAND_ECHO NONE
)