summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bentele2020-10-13 16:19:21 +0200
committerManuel Bentele2020-10-13 16:19:21 +0200
commit111a2350ac1967b62ffa3024371819c812c46844 (patch)
treee31808a39291fe3bfa53e921a51dc74be36468ae
parentAdded separate Linux kernel install directory and added version to kernel mod... (diff)
downloadxloop-111a2350ac1967b62ffa3024371819c812c46844.tar.gz
xloop-111a2350ac1967b62ffa3024371819c812c46844.tar.xz
xloop-111a2350ac1967b62ffa3024371819c812c46844.zip
Added support to keep track of kernel file changes in CMake
With this patch, CMake keeps track of changes to original xloop Linux kernel source files. CMake will copy each file if a change is detected without rebuiling the CMake build and cache files. Futhrmore, changed default paths of udev rules and xloop kernel modules to be installed.
-rw-r--r--CMakeLists.txt18
-rw-r--r--README.md16
-rw-r--r--kernel/CMakeLists.txt8
-rw-r--r--kernel/cmake/kernel.cmake29
-rw-r--r--kernel/tests/CMakeLists.txt2
-rw-r--r--kernel/tests/include/lapi/xloop.h2
-rw-r--r--kernel/tests/lib/CMakeLists.txt1
-rw-r--r--kernel/tests/lib/tst_device.c2
-rw-r--r--kernel/uapi_xloop.h (renamed from kernel/uapi/linux/xloop.h)0
-rw-r--r--kernel/xloop_main.h2
10 files changed, 48 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e1f8eac..54a949a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,8 +9,6 @@ project(xloop
DESCRIPTION "xloop Linux kernel modules and utility"
LANGUAGES C)
-include(GNUInstallDirs)
-
# define project specific settings
set(BLK_DEV_XLOOP_MIN_COUNT 8
CACHE STRING "Number of xloop devices to pre-create at init time")
@@ -20,9 +18,9 @@ set(XLOOP_CTRL_MINOR 15
CACHE STRING "Minor number for the xloop-control device")
# set Linux kernel directories
-set(KERNEL_BUILD_DIR "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/build"
+set(KERNEL_BUILD_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build"
CACHE PATH "Path to Linux kernel modules to compile against")
-set(KERNEL_INSTALL_DIR "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/extra"
+set(KERNEL_INSTALL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra"
CACHE PATH "Path to install Linux kernel modules")
# print configured settings
@@ -74,12 +72,12 @@ if(${CMAKE_BUILD_TYPE} MATCHES Release)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/package/deb/postinst
${CMAKE_CURRENT_BINARY_DIR}/package/deb/postrm)
# set RPM generator specific packaging options
- set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/${CMAKE_INSTALL_LIBDIR}"
- "/${CMAKE_INSTALL_LIBDIR}/modules"
- "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}"
- "/${CMAKE_INSTALL_LIBDIR}/modules/${CMAKE_SYSTEM_VERSION}/extra"
- "/${CMAKE_INSTALL_LIBDIR}/udev"
- "/${CMAKE_INSTALL_LIBDIR}/udev/rules.d"
+ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/lib"
+ "/lib/modules"
+ "/lib/modules/${CMAKE_SYSTEM_VERSION}"
+ "/lib/modules/${CMAKE_SYSTEM_VERSION}/extra"
+ "/lib/udev"
+ "/lib/udev/rules.d"
"${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion"
"${CPACK_PACKAGING_INSTALL_PREFIX}/share/bash-completion/completions"
"${CPACK_PACKAGING_INSTALL_PREFIX}/share/man"
diff --git a/README.md b/README.md
index 47f40f1..d1229c9 100644
--- a/README.md
+++ b/README.md
@@ -73,14 +73,14 @@ cd build
### Configuration
A build of the xloop Linux kernel modules and the xlosetup utility can be configured and customized by the following configuration variables (CMake cache entries):
-| Variable | Type | Values | Default value | Description |
-|:--------------------------|:-------|:----------------------------------------|:--------------------------------------------------|-----------------------------------------------------|
-| `CMAKE_BUILD_TYPE` | STRING | {`Debug`, `Release`} | `Debug` | Build configuration of the xloop project. |
-| `KERNEL_BUILD_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /${CMAKE_INSTALL_LIBDIR}/modules/`uname -r`/build | Path to Linux kernel modules to compile against. |
-| `KERNEL_INSTALL_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /${CMAKE_INSTALL_LIBDIR}/modules/`uname -r`/extra | Path to install Linux kernel modules. |
-| `XLOOP_MAJOR` | NUMBER | {`0` .. `255`} | `120` | Major number for xloop devices. |
-| `XLOOP_CTRL_MINOR` | NUMBER | {`0` .. `255`} | `15` | Minor number for the xloop-control device. |
-| `BLK_DEV_XLOOP_MIN_COUNT` | NUMBER | {`0` .. `255`} | `8` | Number of xloop devices to pre-create at init time. |
+| Variable | Type | Values | Default value | Description |
+|:--------------------------|:-------|:----------------------------------------|:------------------------------|-----------------------------------------------------|
+| `CMAKE_BUILD_TYPE` | STRING | {`Debug`, `Release`} | `Debug` | Build configuration of the xloop project. |
+| `KERNEL_BUILD_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /lib/modules/`uname -r`/build | Path to Linux kernel modules to compile against. |
+| `KERNEL_INSTALL_DIR` | PATH | {`a` .. `z`, `A` .. `Z`, `/`, `_`, `-`} | /lib/modules/`uname -r`/extra | Path to install Linux kernel modules. |
+| `XLOOP_MAJOR` | NUMBER | {`0` .. `255`} | `120` | Major number for xloop devices. |
+| `XLOOP_CTRL_MINOR` | NUMBER | {`0` .. `255`} | `15` | Minor number for the xloop-control device. |
+| `BLK_DEV_XLOOP_MIN_COUNT` | NUMBER | {`0` .. `255`} | `8` | Number of xloop devices to pre-create at init time. |
A value from the range of appropriate values can be assigend to each configuration variable by executing CMake once with the following command pattern:
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 1f266f6..dd12c80 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -23,7 +23,7 @@ set(KERNEL_MODULE_XLOOP_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.
${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.c)
set(KERNEL_MODULE_XLOOP_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h
${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h
- ${CMAKE_CURRENT_SOURCE_DIR}/uapi)
+ ${CMAKE_CURRENT_SOURCE_DIR}/uapi_xloop.h)
add_kernel_module(xloop "${KERNEL_BUILD_DIR}"
"${KERNEL_INSTALL_DIR}"
"CONFIG_BLK_DEV_XLOOP=m"
@@ -35,7 +35,7 @@ add_kernel_module(xloop "${KERNEL_BUILD_DIR}"
set(KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt_raw.c)
set(KERNEL_MODULE_XLOOP_RAW_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h
${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h
- ${CMAKE_CURRENT_SOURCE_DIR}/uapi)
+ ${CMAKE_CURRENT_SOURCE_DIR}/uapi_xloop.h)
add_kernel_module(xloop_file_fmt_raw "${KERNEL_BUILD_DIR}"
"${KERNEL_INSTALL_DIR}"
"CONFIG_BLK_DEV_XLOOP_FILE_FMT_RAW=m"
@@ -53,7 +53,7 @@ set(KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file
${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt_qcow_main.h
${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.h
${CMAKE_CURRENT_SOURCE_DIR}/xloop_main.h
- ${CMAKE_CURRENT_SOURCE_DIR}/uapi)
+ ${CMAKE_CURRENT_SOURCE_DIR}/uapi_xloop.h)
add_kernel_module(xloop_file_fmt_qcow "${KERNEL_BUILD_DIR}"
"${KERNEL_INSTALL_DIR}"
"CONFIG_BLK_DEV_XLOOP_FILE_FMT_QCOW=m"
@@ -68,6 +68,6 @@ endif()
# install udev rules for xloop devices exposed by the xloop kernel module
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/udev/50-xloop.rules
- DESTINATION /${CMAKE_INSTALL_LIBDIR}/udev/rules.d
+ DESTINATION /lib/udev/rules.d
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
COMPONENT main)
diff --git a/kernel/cmake/kernel.cmake b/kernel/cmake/kernel.cmake
index 0d843e6..811ce86 100644
--- a/kernel/cmake/kernel.cmake
+++ b/kernel/cmake/kernel.cmake
@@ -6,15 +6,31 @@
# macro to define kernel module targets
macro(add_kernel_module MODULE_NAME KERNEL_BUILD_DIR KERNEL_INSTALL_DIR MODULE_MACRO MODULE_SOURCE_FILES MODULE_HEADER_FILES BUILD_SOURCE_FILE)
+ # create directory for kernel module
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME})
# copy build source file
- file(COPY ${BUILD_SOURCE_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME})
+ get_filename_component(BUILD_SOURCE_FILENAME ${BUILD_SOURCE_FILE} NAME)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${BUILD_SOURCE_FILENAME}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${BUILD_SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
+ DEPENDS ${BUILD_SOURCE_FILE})
+ set(BUILD_SOURCE_FILE_PREPARED ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${BUILD_SOURCE_FILENAME})
# copy source files
foreach(MODULE_SOURCE_FILE ${MODULE_SOURCE_FILES})
- file(COPY ${MODULE_SOURCE_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME})
+ get_filename_component(MODULE_SOURCE_FILENAME ${MODULE_SOURCE_FILE} NAME)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_SOURCE_FILENAME}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MODULE_SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
+ DEPENDS ${MODULE_SOURCE_FILE})
+ set(MODULE_SOURCE_FILES_PREPARED ${MODULE_SOURCE_FILES_PREPARED}
+ ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_SOURCE_FILENAME})
endforeach()
# copy header files
foreach(MODULE_HEADER_FILE ${MODULE_HEADER_FILES})
- file(COPY ${MODULE_HEADER_FILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME})
+ get_filename_component(MODULE_HEADER_FILENAME ${MODULE_HEADER_FILE} NAME)
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_HEADER_FILENAME}
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MODULE_HEADER_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
+ DEPENDS ${MODULE_HEADER_FILE})
+ set(MODULE_HEADER_FILES_PREPARED ${MODULE_HEADER_FILES_PREPARED}
+ ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_HEADER_FILENAME})
endforeach()
# check if module depends on another module
if(NOT ${ARGV7} STREQUAL "")
@@ -28,9 +44,10 @@ macro(add_kernel_module MODULE_NAME KERNEL_BUILD_DIR KERNEL_INSTALL_DIR MODULE_M
KBUILD_EXTRA_SYMBOLS=${MODULE_EXTRA_SYMBOLS})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko
COMMAND ${MODULE_BUILD_COMMAND}
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
- DEPENDS ${MODULE_SOURCE_FILES} ${MODULE_HEADER_FILES} ${BUILD_SOURCE_FILE}
- VERBATIM)
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}
+ COMMENT "Build kernel module ${MODULE_NAME}"
+ DEPENDS ${BUILD_SOURCE_FILE_PREPARED} ${MODULE_HEADER_FILES_PREPARED} ${MODULE_SOURCE_FILES_PREPARED}
+ VERBATIM)
add_custom_target(${MODULE_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko ${ARGV7})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko
DESTINATION ${KERNEL_INSTALL_DIR}
diff --git a/kernel/tests/CMakeLists.txt b/kernel/tests/CMakeLists.txt
index f086864..e93ff9d 100644
--- a/kernel/tests/CMakeLists.txt
+++ b/kernel/tests/CMakeLists.txt
@@ -4,7 +4,7 @@ project(xloop-kernel-test)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/old)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../uapi)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
# configure configuration config.h and add it to the include directories
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
diff --git a/kernel/tests/include/lapi/xloop.h b/kernel/tests/include/lapi/xloop.h
index 8e57b31..769d1f0 100644
--- a/kernel/tests/include/lapi/xloop.h
+++ b/kernel/tests/include/lapi/xloop.h
@@ -8,7 +8,7 @@
#include "config.h"
#include <linux/types.h>
-#include <linux/xloop.h>
+#include <uapi_xloop.h>
#ifndef LO_FLAGS_PARTSCAN
# define LO_FLAGS_PARTSCAN 8
diff --git a/kernel/tests/lib/CMakeLists.txt b/kernel/tests/lib/CMakeLists.txt
index 9cea565..0ce8982 100644
--- a/kernel/tests/lib/CMakeLists.txt
+++ b/kernel/tests/lib/CMakeLists.txt
@@ -67,3 +67,4 @@ add_library(libltp STATIC ${CMAKE_CURRENT_SOURCE_DIR}/cloner.c
${CMAKE_CURRENT_SOURCE_DIR}/tst_virt.c
${CMAKE_CURRENT_SOURCE_DIR}/tst_wallclock.c)
target_include_directories(libltp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+target_compile_options(libltp PUBLIC "-Wno-deprecated-declarations")
diff --git a/kernel/tests/lib/tst_device.c b/kernel/tests/lib/tst_device.c
index 24f34a3..0df8efe 100644
--- a/kernel/tests/lib/tst_device.c
+++ b/kernel/tests/lib/tst_device.c
@@ -28,7 +28,7 @@
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
-#include <linux/xloop.h>
+#include <uapi_xloop.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/sysmacros.h>
diff --git a/kernel/uapi/linux/xloop.h b/kernel/uapi_xloop.h
index 1bf13c6..1bf13c6 100644
--- a/kernel/uapi/linux/xloop.h
+++ b/kernel/uapi_xloop.h
diff --git a/kernel/xloop_main.h b/kernel/xloop_main.h
index e45a891..e1b4cb6 100644
--- a/kernel/xloop_main.h
+++ b/kernel/xloop_main.h
@@ -15,7 +15,7 @@
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/kthread.h>
-#include "uapi/linux/xloop.h"
+#include "uapi_xloop.h"
#ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h>
#endif