File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -14,12 +14,24 @@ endfunction()
1414
1515function (add_clang_format_target)
1616 if (NOT ${PROJECT_NAME} _CLANG_FORMAT_BINARY)
17- find_program (${PROJECT_NAME} _CLANG_FORMAT_BINARY clang-format)
17+ find_program (${PROJECT_NAME} _CLANG_FORMAT_BINARY clang-format)
1818 endif ()
19+
1920 if (${PROJECT_NAME} _CLANG_FORMAT_BINARY)
20- add_custom_target (clang-format
21- COMMAND ${${PROJECT_NAME} _CLANG_FORMAT_BINARY}
22- -i ${CMAKE_CURRENT_LIST_DIR} /${sources} ${CMAKE_CURRENT_LIST_DIR} /${headers} )
23- message (STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n " )
21+ if (${PROJECT_NAME} _BUILD_EXECUTABLE)
22+ add_custom_target (clang-format
23+ COMMAND ${${PROJECT_NAME} _CLANG_FORMAT_BINARY}
24+ -i $${CMAKE_CURRENT_LIST_DIR} /${exe_sources} ${CMAKE_CURRENT_LIST_DIR} /${headers} )
25+ elseif (${PROJECT_NAME} _BUILD_HEADERS_ONLY)
26+ add_custom_target (clang-format
27+ COMMAND ${${PROJECT_NAME} _CLANG_FORMAT_BINARY}
28+ -i ${CMAKE_CURRENT_LIST_DIR} /${headers} )
29+ else ()
30+ add_custom_target (clang-format
31+ COMMAND ${${PROJECT_NAME} _CLANG_FORMAT_BINARY}
32+ -i ${CMAKE_CURRENT_LIST_DIR} /${sources} ${CMAKE_CURRENT_LIST_DIR} /${headers} )
33+ endif ()
34+
35+ message (STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n " )
2436 endif ()
2537endfunction ()
You can’t perform that action at this time.
0 commit comments