summaryrefslogtreecommitdiffstats
path: root/src/kernel/CMakeLists.txt
diff options
context:
space:
mode:
authorManuel Bentele2020-10-23 18:13:15 +0200
committerManuel Bentele2020-10-23 18:13:15 +0200
commit588368dd2a46ddec70741c6cc87a79a0b26ee383 (patch)
tree69265caba9b1fb0ee126c142538b75fd49bbe8ee /src/kernel/CMakeLists.txt
parentMove the source code of all xloop components to the common 'src' directory (diff)
downloadxloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.tar.gz
xloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.tar.xz
xloop-588368dd2a46ddec70741c6cc87a79a0b26ee383.zip
Add automatic generation of version and build type headers for compilation
This change replaces the static version and build type header file generation by CMake with dynamic CMake targets to generate the version file whenever a Make target is executed. Thus, there is no need anymore to reconfigure and rerun CMake after the repository version or build configuration has changed.
Diffstat (limited to 'src/kernel/CMakeLists.txt')
-rw-r--r--src/kernel/CMakeLists.txt32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt
index dd12c80..2f1446a 100644
--- a/src/kernel/CMakeLists.txt
+++ b/src/kernel/CMakeLists.txt
@@ -3,20 +3,26 @@ cmake_minimum_required(VERSION 3.10)
# set the project name
project(xloop-kernel)
-set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-include(kernel)
+# include macros to define Linux kernel build targets
+include(Kernel)
# set C flags for a Linux kernel module
-set(KERNEL_C_FLAGS "-DCONFIG_BLK_DEV_XLOOP_MIN_COUNT=${BLK_DEV_XLOOP_MIN_COUNT} -DXLOOP_MAJOR=${XLOOP_MAJOR} -DXLOOP_CTRL_MINOR=${XLOOP_CTRL_MINOR} -DVERSION=${VERSION}"
- CACHE STRING "C flags to be used for building the kernel module")
+set(KERNEL_C_FLAGS "-DCONFIG_BLK_DEV_XLOOP_MIN_COUNT=${BLK_DEV_XLOOP_MIN_COUNT} -DXLOOP_MAJOR=${XLOOP_MAJOR} -DXLOOP_CTRL_MINOR=${XLOOP_CTRL_MINOR} -I ${PROJECT_INCLUDE_GEN_DIR}"
+ CACHE STRING "C flags to be used for building the kernel module")
# set C flags for the debug mode of a Linux kernel module
set(KERNEL_C_FLAGS_DEBUG "-g -DDEBUG"
- CACHE STRING "Additional C flags to be used for building the kernel module in debug mode")
+ CACHE STRING "Additional C flags to be used for building the kernel module in debug mode")
+
+# append include directories to the C flags
+get_property(KERNEL_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
+foreach(KERNEL_INCLUDE_DIR ${KERNEL_INCLUDE_DIRS})
+ set(KERNEL_C_FLAGS "${KERNEL_C_FLAGS} -I ${KERNEL_INCLUDE_DIR}")
+endforeach(KERNEL_INCLUDE_DIR ${KERNEL_INCLUDE_DIRS})
# append debug C flags if debug mode is enabled
-if(CMAKE_BUILD_TYPE MATCHES Debug)
+if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(KERNEL_C_FLAGS "${KERNEL_C_FLAGS} ${KERNEL_C_FLAGS_DEBUG}")
-endif(CMAKE_BUILD_TYPE MATCHES Debug)
+endif(CMAKE_BUILD_TYPE MATCHES "Debug")
# xloop main Linux kernel module
set(KERNEL_MODULE_XLOOP_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt.c
@@ -30,6 +36,8 @@ add_kernel_module(xloop "${KERNEL_BUILD_DIR}"
"${KERNEL_MODULE_XLOOP_SOURCE_FILES}"
"${KERNEL_MODULE_XLOOP_HEADER_FILES}"
${CMAKE_CURRENT_SOURCE_DIR}/Kbuild)
+# add dependency to generate project version header before xloop.ko is built
+add_dependencies(xloop xloop-generate-version)
# xloop_file_fmt_raw Linux kernel module
set(KERNEL_MODULE_XLOOP_RAW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt_raw.c)
@@ -43,6 +51,8 @@ add_kernel_module(xloop_file_fmt_raw "${KERNEL_BUILD_DIR}"
"${KERNEL_MODULE_XLOOP_RAW_HEADER_FILES}"
${CMAKE_CURRENT_SOURCE_DIR}/Kbuild
xloop)
+# add dependency to generate project version header before xloop_file_fmt_raw.ko is built
+add_dependencies(xloop_file_fmt_raw xloop-generate-version)
# xloop_file_fmt_qcow Linux kernel module
set(KERNEL_MODULE_XLOOP_QCOW_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/xloop_file_fmt_qcow_cache.c
@@ -61,13 +71,15 @@ add_kernel_module(xloop_file_fmt_qcow "${KERNEL_BUILD_DIR}"
"${KERNEL_MODULE_XLOOP_QCOW_HEADER_FILES}"
${CMAKE_CURRENT_SOURCE_DIR}/Kbuild
xloop)
+# add dependency to generate project version header before xloop_file_fmt_qcow.ko is built
+add_dependencies(xloop_file_fmt_qcow xloop-generate-version)
-if(${CMAKE_BUILD_TYPE} MATCHES Debug)
+if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_subdirectory(tests)
-endif()
+endif(CMAKE_BUILD_TYPE MATCHES "Debug")
# install udev rules for xloop devices exposed by the xloop kernel module
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/udev/50-xloop.rules
DESTINATION /lib/udev/rules.d
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
- COMPONENT main)
+ COMPONENT kernel)