summaryrefslogtreecommitdiffstats
path: root/cmake/FindCheckPatch.cmake
diff options
context:
space:
mode:
authorManuel Bentele2021-03-11 16:47:05 +0100
committerManuel Bentele2021-03-11 18:18:27 +0100
commitba20fa121a0e97a7862aa163a11c7337a05188f7 (patch)
treedff557d5524b711a6f90209f071ed7d3a4b38148 /cmake/FindCheckPatch.cmake
parent[BUILD] Add Github workflow to validate (lint) source code (diff)
downloaddnbd3-ba20fa121a0e97a7862aa163a11c7337a05188f7.tar.gz
dnbd3-ba20fa121a0e97a7862aa163a11c7337a05188f7.tar.xz
dnbd3-ba20fa121a0e97a7862aa163a11c7337a05188f7.zip
[BUILD] Enable lint targets if lint programs are found
Diffstat (limited to 'cmake/FindCheckPatch.cmake')
-rw-r--r--cmake/FindCheckPatch.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/cmake/FindCheckPatch.cmake b/cmake/FindCheckPatch.cmake
new file mode 100644
index 0000000..2772676
--- /dev/null
+++ b/cmake/FindCheckPatch.cmake
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2021 Manuel Bentele <development@manuel-bentele.de>
+#
+
+# check if custom Linux kernel script directory was specified
+if(NOT KERNEL_SCRIPTS_DIR)
+ set(KERNEL_SCRIPTS_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build/scripts"
+ CACHE PATH "Path to Linux kernel scripts directory")
+endif(NOT KERNEL_SCRIPTS_DIR)
+
+# find the checkpatch.pl script in the given KERNEL_SCRIPTS_DIR
+find_program(CheckPatch_EXECUTABLE
+ NAMES checkpatch.pl
+ PATHS ${KERNEL_SCRIPTS_DIR})
+
+
+# get the checkpatch.pl version
+if(CheckPatch_EXECUTABLE)
+ execute_process(COMMAND ${CheckPatch_EXECUTABLE} --version
+ OUTPUT_VARIABLE CheckPatch_VERBOSE_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REGEX REPLACE ".*Version:.([0-9]+\\.[0-9]+).*" "\\1" CheckPatch_VERSION ${CheckPatch_VERBOSE_VERSION})
+endif(CheckPatch_EXECUTABLE)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(CheckPatch
+ FOUND_VAR CheckPatch_FOUND
+ REQUIRED_VARS CheckPatch_EXECUTABLE
+ VERSION_VAR CheckPatch_VERSION
+ FAIL_MESSAGE "checkpatch.pl is not available! Please install checkpatch.pl to lint and format the source code!")