summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorManuel Bentele2020-10-27 10:03:27 +0100
committerManuel Bentele2020-10-27 10:03:27 +0100
commit3f37a0911d0888013ad31a69fe63f324cc9db2ff (patch)
treed9eef6e7772cfbb2d3108a955aa386813b9ec007 /cmake
parent[DOC] Fix URL to the Linux kernel documentation in README (diff)
downloaddnbd3-3f37a0911d0888013ad31a69fe63f324cc9db2ff.tar.gz
dnbd3-3f37a0911d0888013ad31a69fe63f324cc9db2ff.tar.xz
dnbd3-3f37a0911d0888013ad31a69fe63f324cc9db2ff.zip
Add CMake build requirements check to find libraries and Linux kernel headers
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindFuse.cmake2
-rw-r--r--cmake/FindKernelHeaders.cmake45
-rw-r--r--cmake/Version.cmake8
3 files changed, 46 insertions, 9 deletions
diff --git a/cmake/FindFuse.cmake b/cmake/FindFuse.cmake
index cea6b08..f3a6f29 100644
--- a/cmake/FindFuse.cmake
+++ b/cmake/FindFuse.cmake
@@ -53,7 +53,7 @@ set(FUSE_LIBRARIES )
set(FUSE_DEFINITIONS )
set(FUSE_INCLUDE_DIRS )
-find_package(PkgConfig)
+find_package(PkgConfig QUIET)
set(PC_FUSE_INCLUDE_DIRS )
set(PC_FUSE_LIBRARY_DIRS )
diff --git a/cmake/FindKernelHeaders.cmake b/cmake/FindKernelHeaders.cmake
new file mode 100644
index 0000000..60d2380
--- /dev/null
+++ b/cmake/FindKernelHeaders.cmake
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de>
+#
+
+# check if custom Linux kernel build directory was specified
+if(NOT KERNEL_BUILD_DIR)
+ set(KERNEL_BUILD_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build"
+ CACHE PATH "Path to Linux kernel modules to compile against")
+endif(NOT KERNEL_BUILD_DIR)
+
+# check if custom Linux kernel output directory was specified
+if(NOT KERNEL_INSTALL_DIR)
+ set(KERNEL_INSTALL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra"
+ CACHE PATH "Path to install Linux kernel modules")
+endif(NOT KERNEL_INSTALL_DIR)
+
+# find the Linux kernel headers from given KERNEL_BUILD_DIR
+find_path(KernelHeaders_INCLUDE_DIR
+ NAMES linux/user.h
+ PATHS ${KERNEL_BUILD_DIR}/include)
+
+# get Linux kernel headers version
+string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" KernelHeaders_VERSION ${KernelHeaders_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(KernelHeaders
+ FOUND_VAR KernelHeaders_FOUND
+ REQUIRED_VARS KernelHeaders_INCLUDE_DIR
+ VERSION_VAR KernelHeaders_VERSION
+ FAIL_MESSAGE "Linux kernel headers are not available! Please install them to build kernel modules!")
+
+if(KernelHeaders_FOUND)
+ set(KernelHeaders_INCLUDE_DIRS ${KernelHeaders_INCLUDE_DIR}/include
+ CACHE PATH "Path to Linux kernel header includes")
+endif(KernelHeaders_FOUND)
+
+mark_as_advanced(KernelHeaders_INCLUDE_DIR KernelHeaders_MODULE_INSTALL_DIR)
+
+# print found information
+message(VERBOSE "KERNEL_BUILD_DIR: ${KERNEL_BUILD_DIR}")
+message(VERBOSE "KERNEL_INSTALL_DIR: ${KERNEL_INSTALL_DIR}")
+message(VERBOSE "KernelHeaders_FOUND: ${KernelHeaders_FOUND}")
+message(VERBOSE "KernelHeaders_VERSION: ${KernelHeaders_VERSION}")
+message(VERBOSE "KernelHeaders_INCLUDE_DIRS: ${KernelHeaders_INCLUDE_DIRS}")
diff --git a/cmake/Version.cmake b/cmake/Version.cmake
index 939007e..097afd5 100644
--- a/cmake/Version.cmake
+++ b/cmake/Version.cmake
@@ -28,14 +28,6 @@ macro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION
add_dependencies(dnbd3-version dnbd3-generate-version)
endmacro(gen_project_version VERSION_INPUT_FILE VERSION_INPUT_FILE_TEMPLATE VERSION_OUTPUT_FILE)
-# macro to get Linux kernel version from KERNEL_BUILD_DIR string
-macro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
- string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR})
- if(LINUX_KERNEL_VERSION STREQUAL "")
- set(LINUX_KERNEL_VERSION "unknown")
- endif(LINUX_KERNEL_VERSION STREQUAL "")
-endmacro(get_kernel_version LINUX_KERNEL_VERSION KERNEL_BUILD_DIR)
-
# macro to get Git version information
macro(get_repository_version REPOSITORY_VERSION VERSION_HEADER_FILE VERSION_BUILD_TYPE)
# check if generated version header from source package is available