diff options
author | Simon Rettberg | 2023-06-07 18:02:39 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-06-07 18:12:34 +0200 |
commit | f9605e29c45464126e3a3aef1dc6a345aa954bd6 (patch) | |
tree | c907e2d9ad1d834b0f4d6658371a60d1b3d23714 | |
parent | [KERNEL] Add Rocky 9 support (diff) | |
download | dnbd3-f9605e29c45464126e3a3aef1dc6a345aa954bd6.tar.gz dnbd3-f9605e29c45464126e3a3aef1dc6a345aa954bd6.tar.xz dnbd3-f9605e29c45464126e3a3aef1dc6a345aa954bd6.zip |
Cleanup FindKernel cmake macros, add more error checks
-rw-r--r-- | cmake/FindCheckPatch.cmake | 2 | ||||
-rw-r--r-- | cmake/FindKernelHeaders.cmake | 23 |
2 files changed, 17 insertions, 8 deletions
diff --git a/cmake/FindCheckPatch.cmake b/cmake/FindCheckPatch.cmake index 3fa1ec8..8454e6b 100644 --- a/cmake/FindCheckPatch.cmake +++ b/cmake/FindCheckPatch.cmake @@ -5,7 +5,7 @@ # 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" + set(KERNEL_SCRIPTS_DIR "${KERNEL_BUILD_DIR}/scripts" CACHE PATH "Path to Linux kernel scripts directory") endif(NOT KERNEL_SCRIPTS_DIR) diff --git a/cmake/FindKernelHeaders.cmake b/cmake/FindKernelHeaders.cmake index 2fe2dcb..7c1f8ed 100644 --- a/cmake/FindKernelHeaders.cmake +++ b/cmake/FindKernelHeaders.cmake @@ -15,6 +15,10 @@ if(NOT KERNEL_INSTALL_DIR) CACHE PATH "Path to install Linux kernel modules") endif(NOT KERNEL_INSTALL_DIR) +if(NOT EXISTS "${KERNEL_BUILD_DIR}/Module.symvers") + message(FATAL_ERROR "Module.symvers not found in ${KERNEL_BUILD_DIR}") +endif() + # find the Linux kernel headers from given KERNEL_BUILD_DIR find_path(KernelHeaders_INCLUDE_DIR NAMES linux/kernel.h @@ -24,7 +28,18 @@ find_path(KernelHeaders_INCLUDE_DIR NO_DEFAULT_PATH) # get Linux kernel headers version -string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" KernelHeaders_VERSION ${KernelHeaders_INCLUDE_DIR}) +file(READ "${KERNEL_BUILD_DIR}/include/generated/utsrelease.h" tmpvar) +string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" KernelHeaders_VERSION ${tmpvar}) +if("${KernelHeaders_VERSION}" EQUAL "") + file(READ "${KERNEL_BUILD_DIR}/include/config/kernel.release" tmpvar) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" KernelHeaders_VERSION ${tmpvar}) +endif() +if("${KernelHeaders_VERSION}" EQUAL "") + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" KernelHeaders_VERSION ${KernelHeaders_INCLUDE_DIR}) +endif() +if("${KernelHeaders_VERSION}" EQUAL "") + message(FATAL_ERROR "Cannot determine kernel version") +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(KernelHeaders @@ -33,11 +48,6 @@ find_package_handle_standard_args(KernelHeaders 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 @@ -46,5 +56,4 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.15.0") 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}") endif(${CMAKE_VERSION} VERSION_GREATER "3.15.0") |