summaryrefslogtreecommitdiffstats
path: root/CMakeModules/SourceFormat.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:55:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:55:11 +0000
commitcd07912073c951b4bbb871ed2653af1be2cfc714 (patch)
tree1073c2308492e6aea4c66cb7436ee92db2abfd42 /CMakeModules/SourceFormat.cmake
parentInitial commit. (diff)
downloadlibyang2-cd07912073c951b4bbb871ed2653af1be2cfc714.tar.xz
libyang2-cd07912073c951b4bbb871ed2653af1be2cfc714.zip
Adding upstream version 2.1.30.upstream/2.1.30upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'CMakeModules/SourceFormat.cmake')
-rw-r--r--CMakeModules/SourceFormat.cmake36
1 files changed, 36 insertions, 0 deletions
diff --git a/CMakeModules/SourceFormat.cmake b/CMakeModules/SourceFormat.cmake
new file mode 100644
index 0000000..fd1e63b
--- /dev/null
+++ b/CMakeModules/SourceFormat.cmake
@@ -0,0 +1,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()