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) |
Michal Vasko | 6ce8e82 | 2022-08-02 15:09:17 +0200 | [diff] [blame^] | 5 | 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 Vasko | b0e3ec4 | 2021-05-26 09:48:31 +0200 | [diff] [blame] | 10 | if(UNCRUSTIFY_FOUND) |
| 11 | set(SOURCE_FORMAT_ENABLED TRUE) |
| 12 | else() |
| 13 | set(SOURCE_FORMAT_ENABLED FALSE) |
| 14 | endif() |
| 15 | endmacro() |
| 16 | |
| 17 | # files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR |
| 18 | macro(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() |
| 36 | endmacro() |