-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormat.cmake
28 lines (25 loc) · 1.22 KB
/
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
# Check executable exists
if(NOT EXISTS ${CLANG_FORMAT_EXECUTABLE})
find_program(CLANG_FORMAT_EXEC_TEMP ${CLANG_FORMAT_EXECUTABLE})
if(CLANG_FORMAT_EXEC_TEMP)
set(CLANG_FORMAT_EXECUTABLE ${CLANG_FORMAT_EXEC_TEMP})
unset(CLANG_FORMAT_EXEC_TEMP)
else()
message(FATAL_ERROR "Unable to find clang-format executable: \"${CLANG_FORMAT_EXECUTABLE}\"")
endif()
endif()
# Check executable version
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} --version OUTPUT_VARIABLE CLANG_FORMAT_VERSION)
string(REGEX MATCH "clang-format version ([0-9]+)" CLANG_FORMAT_VERSION ${CLANG_FORMAT_VERSION})
unset(CLANG_FORMAT_VERSION)
if(NOT CMAKE_MATCH_1 EQUAL 17)
message(FATAL_ERROR "clang-format version ${CMAKE_MATCH_1} not supported. Must use version 17")
endif()
# Run
set(SOURCES "")
foreach(FOLDER IN ITEMS examples include src test tools)
file(GLOB_RECURSE folder_files "${FOLDER}/*.h" "${FOLDER}/*.hpp" "${FOLDER}/*.inl" "${FOLDER}/*.cpp" "${FOLDER}/*.mm" "${FOLDER}/*.m")
list(FILTER folder_files EXCLUDE REGEX "gl.h|vulkan.h|stb_perlin.h") # 3rd party code to exclude from formatting
list(APPEND SOURCES ${folder_files})
endforeach()
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -i ${SOURCES})