-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode_format.cmake
More file actions
20 lines (17 loc) · 828 Bytes
/
code_format.cmake
File metadata and controls
20 lines (17 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
include_guard(GLOBAL)
if(WIN32)
return()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/module)
find_package(ClangFormat QUIET)
if(ClangFormat_FOUND AND NOT TARGET do_clang_format)
get_all_sources_and_headers()
add_custom_target(
do_clang_format
COMMAND sh ${CMAKE_BINARY_DIR}/get_all_sources_and_headers.sh ${CMAKE_BINARY_DIR}/compile_commands.json | xargs -I source_file "$<TARGET_FILE:ClangFormat::clang-format>" -style=file -i source_file
COMMAND find ${CMAKE_CURRENT_SOURCE_DIR} -name '*.hpp' | xargs -I source_file "$<TARGET_FILE:ClangFormat::clang-format>" -style=file -i source_file
DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_BINARY_DIR}/get_all_sources_and_headers.sh
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()