blob: 76132a449e77f420ce66568f120e3aec6e2e18c6 [file] [log] [blame]
Michal Vaskob0e3ec42021-05-26 09:48:31 +02001# format source files with uncrustify
2
3# check that format checking is available - always use before SOURCE_FORMAT
4macro(SOURCE_FORMAT_ENABLE)
5 find_package(Uncrustify 0.71)
6 if(UNCRUSTIFY_FOUND)
7 set(SOURCE_FORMAT_ENABLED TRUE)
8 else()
9 set(SOURCE_FORMAT_ENABLED FALSE)
10 endif()
11endmacro()
12
13# files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR
14macro(SOURCE_FORMAT)
15 if(NOT ${ARGC})
16 message(FATAL_ERROR "source_format() needs a list of files to format!")
17 endif()
18
19 if(SOURCE_FORMAT_ENABLED)
20 add_custom_target(format
21 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --no-backup --replace ${ARGN}
22 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
23 COMMENT "Formating sources with ${UNCRUSTIFY} ...")
24
25 add_custom_target(format-check
26 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --check ${ARGN}
27 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
28 COMMENT "Checking format of the sources with ${UNCRUSTIFY} ...")
29
30 set(SOURCE_FORMAT_ENABLED TRUE)
31 endif()
32endmacro()