blob: fd1e63bea222ef2f31c1599f3b3f1bd0f4d2a967 [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)
Michal Vasko6ce8e822022-08-02 15:09:17 +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})
Michal Vaskob0e3ec42021-05-26 09:48:31 +020010 if(UNCRUSTIFY_FOUND)
11 set(SOURCE_FORMAT_ENABLED TRUE)
12 else()
13 set(SOURCE_FORMAT_ENABLED FALSE)
14 endif()
15endmacro()
16
17# 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
23 if(SOURCE_FORMAT_ENABLED)
24 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} ...")
33
34 set(SOURCE_FORMAT_ENABLED TRUE)
35 endif()
36endmacro()