Michal Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 1 | # format source files with uncrustify |
| 2 | |
| 3 | # check that format checking is available - always use before SOURCE_FORMAT |
| 4 | macro(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() |
| 11 | endmacro() |
| 12 | |
| 13 | # files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR |
| 14 | macro(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() |
| 32 | endmacro() |