blob: fd1e63bea222ef2f31c1599f3b3f1bd0f4d2a967 [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)
Michal Vasko26bbb272022-08-02 14:54:33 +02005 if(NOT ${ARGC} EQUAL 1)
6 message(FATAL_ERROR "source_format_enable() needs the required Uncrustify version!")
7 endif()
8
9 find_package(Uncrustify ${ARGV0})
Radek Krejci5348e6c2021-04-13 21:18:51 +020010 if(UNCRUSTIFY_FOUND)
11 set(SOURCE_FORMAT_ENABLED TRUE)
12 else()
13 set(SOURCE_FORMAT_ENABLED FALSE)
14 endif()
15endmacro()
16
Radek Krejcia198c962020-08-16 10:32:10 +020017# files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR
18macro(SOURCE_FORMAT)
19 if(NOT ${ARGC})
20 message(FATAL_ERROR "source_format() needs a list of files to format!")
21 endif()
22
Radek Krejci5348e6c2021-04-13 21:18:51 +020023 if(SOURCE_FORMAT_ENABLED)
Radek Krejcia198c962020-08-16 10:32:10 +020024 add_custom_target(format
25 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --no-backup --replace ${ARGN}
26 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
27 COMMENT "Formating sources with ${UNCRUSTIFY} ...")
28
29 add_custom_target(format-check
30 COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --check ${ARGN}
31 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
32 COMMENT "Checking format of the sources with ${UNCRUSTIFY} ...")
Radek Krejci5348e6c2021-04-13 21:18:51 +020033
34 set(SOURCE_FORMAT_ENABLED TRUE)
Radek Krejcia198c962020-08-16 10:32:10 +020035 endif()
36endmacro()