diff options
author | Manuel Bentele | 2020-10-23 18:13:15 +0200 |
---|---|---|
committer | Manuel Bentele | 2020-10-23 18:13:15 +0200 |
commit | 588368dd2a46ddec70741c6cc87a79a0b26ee383 (patch) | |
tree | 69265caba9b1fb0ee126c142538b75fd49bbe8ee /src | |
parent | Move the source code of all xloop components to the common 'src' directory (diff) | |
download | xloop-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')
-rw-r--r-- | src/kernel/CMakeLists.txt | 32 | ||||
-rw-r--r-- | src/kernel/cmake/kernel.cmake | 56 | ||||
-rw-r--r-- | src/kernel/xloop_file_fmt_qcow_main.c | 4 | ||||
-rw-r--r-- | src/kernel/xloop_file_fmt_raw.c | 4 | ||||
-rw-r--r-- | src/kernel/xloop_main.c | 6 | ||||
-rw-r--r-- | src/utils/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/utils/config.h (renamed from src/utils/config.h.in) | 19 | ||||
-rw-r--r-- | src/utils/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/utils/libsmartcols/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/utils/sys-utils/CMakeLists.txt | 3 |
10 files changed, 47 insertions, 90 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) diff --git a/src/kernel/cmake/kernel.cmake b/src/kernel/cmake/kernel.cmake deleted file mode 100644 index 811ce86..0000000 --- a/src/kernel/cmake/kernel.cmake +++ /dev/null @@ -1,56 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# CMake macros to build and install Linux kernel modules -# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de> -# - -# 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 - 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}) - 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}) - 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 "") - set(MODULE_EXTRA_SYMBOLS ${CMAKE_CURRENT_BINARY_DIR}/${ARGV7}/Module.symvers) - endif() - # define build command - set(MODULE_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} ${MODULE_MACRO} - -C ${KERNEL_BUILD_DIR} - M=${CMAKE_CURRENT_BINARY_DIR}/${MODULE_NAME} modules - EXTRA_CFLAGS=${KERNEL_C_FLAGS} - 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} - 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} - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - COMPONENT main) -endmacro(add_kernel_module) diff --git a/src/kernel/xloop_file_fmt_qcow_main.c b/src/kernel/xloop_file_fmt_qcow_main.c index 38fe1af..dfde76d 100644 --- a/src/kernel/xloop_file_fmt_qcow_main.c +++ b/src/kernel/xloop_file_fmt_qcow_main.c @@ -27,6 +27,8 @@ #include <linux/zstd.h> #endif +#include <xloop/version.h> + #include "xloop_file_fmt.h" #include "xloop_file_fmt_qcow_main.h" #include "xloop_file_fmt_qcow_cache.h" @@ -1280,4 +1282,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); MODULE_DESCRIPTION("xloop device QCOW file format driver"); MODULE_SOFTDEP("pre: xloop"); -MODULE_VERSION(__stringify(VERSION)); +MODULE_VERSION(XLOOP_VERSION); diff --git a/src/kernel/xloop_file_fmt_raw.c b/src/kernel/xloop_file_fmt_raw.c index 76ab39e..12914e8 100644 --- a/src/kernel/xloop_file_fmt_raw.c +++ b/src/kernel/xloop_file_fmt_raw.c @@ -23,6 +23,8 @@ #include <linux/uio.h> #include <linux/version.h> +#include <xloop/version.h> + #include "xloop_file_fmt.h" static inline loff_t __raw_file_fmt_rq_get_pos(struct xloop_file_fmt *xlo_fmt, @@ -473,4 +475,4 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); MODULE_DESCRIPTION("xloop device RAW file format driver"); MODULE_SOFTDEP("pre: xloop"); -MODULE_VERSION(__stringify(VERSION)); +MODULE_VERSION(XLOOP_VERSION); diff --git a/src/kernel/xloop_main.c b/src/kernel/xloop_main.c index a3e20a6..300554f 100644 --- a/src/kernel/xloop_main.c +++ b/src/kernel/xloop_main.c @@ -88,6 +88,8 @@ #include <linux/debugfs.h> #endif +#include <xloop/version.h> + #include "xloop_file_fmt.h" #include "xloop_main.h" @@ -1719,7 +1721,7 @@ module_param(max_part, int, 0444); MODULE_PARM_DESC(max_part, "Maximum number of partitions per xloop device"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Manuel Bentele <development@manuel-bentele.de>"); -MODULE_VERSION(__stringify(VERSION)); +MODULE_VERSION(XLOOP_VERSION); MODULE_ALIAS_BLOCKDEV_MAJOR(XLOOP_MAJOR); int xloop_register_transfer(struct xloop_func_table *funcs) @@ -2189,7 +2191,7 @@ static int __init xloop_init(void) xloop_add(&xlo, i); mutex_unlock(&xloop_ctl_mutex); - pr_info("module in version %s loaded\n", __stringify(VERSION)); + pr_info("module in version %s loaded\n", XLOOP_VERSION); return 0; misc_out: diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index cfc5548..f3ea912 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -4,15 +4,11 @@ cmake_minimum_required(VERSION 3.10) project(xloop-utils) # include global headers -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -# prepare date for configuring config.h -string(TIMESTAMP DATE "%d-%b-%Y") +include_directories(${PROJECT_INCLUDE_GEN_DIR}) # configure configuration config.h and add it to each source file -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) -add_compile_options(-include ${CMAKE_CURRENT_BINARY_DIR}/config.h) +add_compile_options(-include ${CMAKE_CURRENT_SOURCE_DIR}/config.h) # add xloop specific compile options add_definitions(-DCONFIG_BLK_DEV_XLOOP_MIN_COUNT=${BLK_DEV_XLOOP_MIN_COUNT} -DXLOOP_MAJOR=${XLOOP_MAJOR}) diff --git a/src/utils/config.h.in b/src/utils/config.h index 40b8d34..781ddc7 100644 --- a/src/utils/config.h.in +++ b/src/utils/config.h @@ -1,6 +1,8 @@ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ +#include <xloop/version.h> + /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -693,20 +695,17 @@ /* Define to 1 if you have the `__secure_getenv' function. */ /* #undef HAVE___SECURE_GETENV */ -/* libblkid date string */ -#define LIBBLKID_DATE "@DATE@" - /* libblkid version string */ -#define LIBBLKID_VERSION "@VERSION@" +#define LIBBLKID_VERSION XLOOP_VERSION /* libfdisk version string */ -#define LIBFDISK_VERSION "@VERSION@" +#define LIBFDISK_VERSION XLOOP_VERSION /* libmount version string */ -#define LIBMOUNT_VERSION "@VERSION@" +#define LIBMOUNT_VERSION XLOOP_VERSION /* libsmartcols version string */ -#define LIBSMARTCOLS_VERSION "@VERSION@" +#define LIBSMARTCOLS_VERSION XLOOP_VERSION /* Should login chown /dev/vcsN? */ /* #undef LOGIN_CHOWN_VCS */ @@ -736,7 +735,7 @@ #define PACKAGE_NAME "util-linux" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "util-linux @VERSION@" +#define PACKAGE_STRING ("util-linux " XLOOP_VERSION) /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "util-linux" @@ -745,7 +744,7 @@ #define PACKAGE_URL "http://www.kernel.org/pub/linux/utils/util-linux/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "@VERSION@" +#define PACKAGE_VERSION XLOOP_VERSION /* Should pg ring the bell on invalid keys? */ #define PG_BELL 1 @@ -848,7 +847,7 @@ /* #undef USE_VENDORDIR */ /* Version number of package */ -#define VERSION "@VERSION@" +#define VERSION XLOOP_VERSION /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ diff --git a/src/utils/lib/CMakeLists.txt b/src/utils/lib/CMakeLists.txt index e5fa459..22eafb3 100644 --- a/src/utils/lib/CMakeLists.txt +++ b/src/utils/lib/CMakeLists.txt @@ -42,3 +42,4 @@ add_library(libcommon STATIC ${CMAKE_CURRENT_SOURCE_DIR}/blkdev.c ${CMAKE_CURRENT_SOURCE_DIR}/timer.c ${CMAKE_CURRENT_SOURCE_DIR}/timeutils.c ${CMAKE_CURRENT_SOURCE_DIR}/ttyutils.c) +target_link_libraries(libcommon xloop-version) diff --git a/src/utils/libsmartcols/CMakeLists.txt b/src/utils/libsmartcols/CMakeLists.txt index c8deb72..dccb5e2 100644 --- a/src/utils/libsmartcols/CMakeLists.txt +++ b/src/utils/libsmartcols/CMakeLists.txt @@ -18,5 +18,5 @@ add_library(libsmartcols STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/buffer.c ${CMAKE_CURRENT_SOURCE_DIR}/src/table.c ${CMAKE_CURRENT_SOURCE_DIR}/src/version.c ${CMAKE_CURRENT_SOURCE_DIR}/src/walk.c) -target_include_directories(libsmartcols PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/../lib) -target_link_libraries(libsmartcols LINK_PUBLIC libcommon) +target_include_directories(libsmartcols PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) +target_link_libraries(libsmartcols LINK_PUBLIC libcommon xloop-version) diff --git a/src/utils/sys-utils/CMakeLists.txt b/src/utils/sys-utils/CMakeLists.txt index 01295d9..e05b5cf 100644 --- a/src/utils/sys-utils/CMakeLists.txt +++ b/src/utils/sys-utils/CMakeLists.txt @@ -5,8 +5,7 @@ project(xloop-utils-sys-utils) # add xlosetup executable add_executable(xlosetup ${CMAKE_CURRENT_SOURCE_DIR}/xlosetup.c) -target_link_libraries(xlosetup LINK_PUBLIC libcommon libsmartcols) -target_include_directories(xlosetup PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../lib ${CMAKE_CURRENT_SOURCE_DIR}/../libsmartcols) +target_link_libraries(xlosetup libcommon libsmartcols xloop-version) install(TARGETS xlosetup DESTINATION bin COMPONENT main) |