blob: 76132a449e77f420ce66568f120e3aec6e2e18c6 [file] [log] [blame]
Radek Krejcia198c962020-08-16 10:32:10 +02001# format source files with uncrustify
Radek Krejci5348e6c2021-04-13 21:18:51 +02002
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
Radek Krejcia198c962020-08-16 10:32:10 +020013# 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
Radek Krejci5348e6c2021-04-13 21:18:51 +020019 if(SOURCE_FORMAT_ENABLED)
Radek Krejcia198c962020-08-16 10:32:10 +020020 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} ...")
Radek Krejci5348e6c2021-04-13 21:18:51 +020029
30 set(SOURCE_FORMAT_ENABLED TRUE)
Radek Krejcia198c962020-08-16 10:32:10 +020031 endif()
32endmacro()