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