Radek Krejci | a198c96 | 2020-08-16 10:32:10 +0200 | [diff] [blame] | 1 | # format source files with uncrustify |
Radek Krejci | 5348e6c | 2021-04-13 21:18:51 +0200 | [diff] [blame] | 2 | |
| 3 | # check that format checking is available - always use before SOURCE_FORMAT |
| 4 | macro(SOURCE_FORMAT_ENABLE) |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +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}) |
Radek Krejci | 5348e6c | 2021-04-13 21:18:51 +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 | |
Radek Krejci | a198c96 | 2020-08-16 10:32:10 +0200 | [diff] [blame] | 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 | |
Radek Krejci | 5348e6c | 2021-04-13 21:18:51 +0200 | [diff] [blame] | 23 | if(SOURCE_FORMAT_ENABLED) |
Radek Krejci | a198c96 | 2020-08-16 10:32:10 +0200 | [diff] [blame] | 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} ...") |
Radek Krejci | 5348e6c | 2021-04-13 21:18:51 +0200 | [diff] [blame] | 33 | |
| 34 | set(SOURCE_FORMAT_ENABLED TRUE) |
Radek Krejci | a198c96 | 2020-08-16 10:32:10 +0200 | [diff] [blame] | 35 | endif() |
| 36 | endmacro() |