File: SourceFormat.cmake

package info (click to toggle)
libnetconf2 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,612 kB
  • sloc: ansic: 37,068; xml: 437; sh: 49; makefile: 20
file content (36 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# format source files with uncrustify

# check that format checking is available - always use before SOURCE_FORMAT
macro(SOURCE_FORMAT_ENABLE)
    if(NOT ${ARGC} EQUAL 1)
        message(FATAL_ERROR "source_format_enable() needs the required Uncrustify version!")
    endif()

    find_package(Uncrustify ${ARGV0})
    if(UNCRUSTIFY_FOUND)
        set(SOURCE_FORMAT_ENABLED TRUE)
    else()
        set(SOURCE_FORMAT_ENABLED FALSE)
    endif()
endmacro()

# files are expected to be a list and relative paths are resolved wtih respect to CMAKE_SOURCE DIR
macro(SOURCE_FORMAT)
    if(NOT ${ARGC})
        message(FATAL_ERROR "source_format() needs a list of files to format!")
    endif()

    if(SOURCE_FORMAT_ENABLED)
        add_custom_target(format
                COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --no-backup --replace ${ARGN}
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                COMMENT "Formating sources with ${UNCRUSTIFY} ...")

        add_custom_target(format-check
                COMMAND ${UNCRUSTIFY} -c ${CMAKE_SOURCE_DIR}/uncrustify.cfg --check ${ARGN}
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                COMMENT "Checking format of the sources with ${UNCRUSTIFY} ...")

        set(SOURCE_FORMAT_ENABLED TRUE)
    endif()
endmacro()