blob: d3655adefd5afbd52c610121266f8db38d2dba05 [file] [log] [blame]
Radek Krejcia198c962020-08-16 10:32:10 +02001# format source files with uncrustify
2# files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR
3macro(SOURCE_FORMAT)
4 if(NOT ${ARGC})
5 message(FATAL_ERROR "source_format() needs a list of files to format!")
6 endif()
7
8 find_package(Uncrustify 0.71)
9 if(UNCRUSTIFY_FOUND)
10 add_custom_target(format
11 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --no-backup --replace ${ARGN}
12 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13 COMMENT "Formating sources with ${UNCRUSTIFY} ...")
14
15 add_custom_target(format-check
16 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --check ${ARGN}
17 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
18 COMMENT "Checking format of the sources with ${UNCRUSTIFY} ...")
19 endif()
20endmacro()