summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2020-10-27 10:03:27 +0100
committerManuel Bentele2020-10-27 10:03:27 +0100
commit3f37a0911d0888013ad31a69fe63f324cc9db2ff (patch)
treed9eef6e7772cfbb2d3108a955aa386813b9ec007
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
-rw-r--r--CMakeLists.txt25
-rw-r--r--cmake/FindFuse.cmake2
-rw-r--r--cmake/FindKernelHeaders.cmake45
-rw-r--r--cmake/Version.cmake8
4 files changed, 56 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 122dedd..8a74307 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,9 +28,10 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)
# search for required packages
-find_package(Git)
-find_package(Threads)
-find_package(Fuse)
+find_package(Git REQUIRED)
+find_package(Threads REQUIRED)
+find_package(Fuse REQUIRED)
+find_package(Jansson REQUIRED)
# abort if a required package is not available
if(NOT GIT_FOUND)
@@ -49,18 +50,12 @@ include(Build)
# check for system and enable or disable built of Linux kernel module
if(DNBD3_KERNEL_MODULE AND UNIX AND CMAKE_SYSTEM_NAME MATCHES "Linux")
- # set Linux kernel directories
- set(KERNEL_BUILD_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build"
- CACHE PATH "Path to Linux kernel modules to compile against")
- set(KERNEL_INSTALL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra"
- CACHE PATH "Path to install Linux kernel modules")
+ # require Linux kernel headers
+ find_package(KernelHeaders REQUIRED)
# print configured settings
message(STATUS "Path to Linux kernel modules to compile against is " ${KERNEL_BUILD_DIR})
message(STATUS "Path to install Linux kernel modules is " ${KERNEL_INSTALL_DIR})
-
- # get the Linux kernel version
- get_kernel_version(LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR})
else(DNBD3_KERNEL_MODULE AND UNIX AND CMAKE_SYSTEM_NAME MATCHES "Linux")
# disable build of the dnbd3 Linux kernel module on a system other than Linux, eg. FreeBSD
message(STATUS "Detected non-Linux system: Disable build of the dnbd3 Linux kernel module")
@@ -120,11 +115,11 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
get_repository_version(REPOSITORY_VERSION ${INCLUDE_VERSION_HEADER} ${CMAKE_BUILD_TYPE})
# define project version
- if(LINUX_KERNEL_VERSION)
- set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION}-${LINUX_KERNEL_VERSION})
- else(LINUX_KERNEL_VERSION)
+ if(KernelHeaders_VERSION)
+ set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION}-${KernelHeaders_VERSION})
+ else(KernelHeaders_VERSION)
set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION})
- endif(LINUX_KERNEL_VERSION)
+ endif(KernelHeaders_VERSION)
set(CPACK_GENERATOR "DEB;RPM;TGZ")
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
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