diff options
-rw-r--r-- | CMakeLists.txt | 25 | ||||
-rw-r--r-- | cmake/FindKernelHeaders.cmake | 45 | ||||
-rw-r--r-- | cmake/FindLibcap.cmake | 49 | ||||
-rw-r--r-- | cmake/FindLibncurses.cmake | 54 | ||||
-rw-r--r-- | cmake/Version.cmake | 8 |
5 files changed, 157 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a14e369..7fe82ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,18 +30,10 @@ include(Version) include(Build) # search for required packages -find_package(Git) - -# abort if a required package is not available -if(NOT GIT_FOUND) - message(FATAL_ERROR "No Git found, can't determine xloop project version number!") -endif(NOT GIT_FOUND) - -# 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") +find_package(Git REQUIRED) +find_package(Libcap REQUIRED) +find_package(Libncurses REQUIRED) +find_package(KernelHeaders REQUIRED) # set linux kernel modules specific default settings set(BLK_DEV_XLOOP_MIN_COUNT 8 @@ -58,9 +50,6 @@ message(STATUS "Number of xloop devices to pre-create at init time is " ${BLK_DE message(STATUS "Major number for xloop devices is " ${XLOOP_MAJOR}) message(STATUS "Minor number for the xloop-control device is " ${XLOOP_CTRL_MINOR}) -# get the Linux kernel version -get_kernel_version(LINUX_KERNEL_VERSION ${KERNEL_BUILD_DIR}) - # set include directories set(PROJECT_GEN_DIR ${CMAKE_BINARY_DIR}/generated) set(PROJECT_INCLUDE_DIR_PREFIX inc) @@ -96,7 +85,11 @@ if(CMAKE_BUILD_TYPE MATCHES "Release") get_repository_version(REPOSITORY_VERSION ${INCLUDE_VERSION_HEADER} ${CMAKE_BUILD_TYPE}) # define project version - set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION}-${LINUX_KERNEL_VERSION}) + if(KernelHeaders_VERSION) + set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION}-${KernelHeaders_VERSION}) + else(KernelHeaders_VERSION) + set(REPOSITORY_VERSION_FULL ${REPOSITORY_VERSION}) + endif(KernelHeaders_VERSION) set(CPACK_GENERATOR "DEB;RPM;TGZ") set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME}) 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/FindLibcap.cmake b/cmake/FindLibcap.cmake new file mode 100644 index 0000000..8529426 --- /dev/null +++ b/cmake/FindLibcap.cmake @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de> +# + +# Use pkg-config to get the directories and then use these values +# in the FIND_PATH() and FIND_LIBRARY() calls +find_package(PkgConfig QUIET) +pkg_check_modules(PKG_Libcap QUIET libcap) + +set(Libcap_COMPILE_OPTIONS ${PKG_Libcap_CFLAGS_OTHER}) +set(Libcap_VERSION ${PKG_Libcap_VERSION}) + +find_path(Libcap_INCLUDE_DIR + NAMES sys/capability.h + HINTS ${PKG_Libcap_INCLUDE_DIRS}) +find_library(Libcap_LIBRARY + NAMES cap + HINTS ${PKG_Libcap_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libcap + FOUND_VAR Libcap_FOUND + REQUIRED_VARS Libcap_LIBRARY + Libcap_INCLUDE_DIR + VERSION_VAR Libcap_VERSION + FAIL_MESSAGE "Library 'cap' is not available! Please install this required library!") + +if(Libcap_FOUND AND NOT TARGET Libcap::Libcap) + add_library(Libcap::Libcap UNKNOWN IMPORTED) + set_target_properties(Libcap::Libcap PROPERTIES + IMPORTED_LOCATION "${Libcap_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${Libcap_COMPILE_OPTIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${Libcap_INCLUDE_DIR}") +endif(Libcap_FOUND AND NOT TARGET Libcap::Libcap) + +mark_as_advanced(Libcap_LIBRARY Libcap_INCLUDE_DIR) + +if(Libcap_FOUND) + set(Libcap_LIBRARIES ${Libcap_LIBRARY}) + set(Libcap_INCLUDE_DIRS ${Libcap_INCLUDE_DIR}) +endif(Libcap_FOUND) + +# print found information +message(VERBOSE "Libcap_FOUND: ${Libcap_FOUND}") +message(VERBOSE "Libcap_VERSION: ${Libcap_VERSION}") +message(VERBOSE "Libcap_INCLUDE_DIRS: ${Libcap_INCLUDE_DIRS}") +message(VERBOSE "Libcap_COMPILE_OPTIONS: ${Libcap_COMPILE_OPTIONS}") +message(VERBOSE "Libcap_LIBRARIES: ${Libcap_LIBRARIES}") diff --git a/cmake/FindLibncurses.cmake b/cmake/FindLibncurses.cmake new file mode 100644 index 0000000..2589ff0 --- /dev/null +++ b/cmake/FindLibncurses.cmake @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2020 Manuel Bentele <development@manuel-bentele.de> +# + +# Use pkg-config to get the directories and then use these values +# in the FIND_PATH() and FIND_LIBRARY() calls +find_package(PkgConfig QUIET) +pkg_check_modules(PKG_Libncurses QUIET libncurses) + +set(Libncurses_COMPILE_OPTIONS ${PKG_Libncurses_CFLAGS_OTHER}) +set(Libncurses_VERSION ${PKG_Libncurses_VERSION}) + +find_path(Libncurses_INCLUDE_DIR + NAMES ncursesw/ncurses.h + ncurses/ncurses.h + ncurses.h + ncursesw/term.h + ncurses/term.h + term.h + HINTS ${PKG_Libncurses_INCLUDE_DIRS}) +find_library(Libncurses_LIBRARY + NAMES ncurses + HINTS ${PKG_Libncurses_LIBRARY_DIRS}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libncurses + FOUND_VAR Libncurses_FOUND + REQUIRED_VARS Libncurses_LIBRARY + Libncurses_INCLUDE_DIR + VERSION_VAR Libncurses_VERSION + FAIL_MESSAGE "Library 'ncurses' is not available! Please install this required library!") + +if(Libncurses_FOUND AND NOT TARGET Libncurses::Libncurses) + add_library(Libncurses::Libncurses UNKNOWN IMPORTED) + set_target_properties(Libncurses::Libncurses PROPERTIES + IMPORTED_LOCATION "${Libncurses_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${Libncurses_COMPILE_OPTIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${Libncurses_INCLUDE_DIR}") +endif(Libncurses_FOUND AND NOT TARGET Libncurses::Libncurses) + +mark_as_advanced(Libncurses_LIBRARY Libncurses_INCLUDE_DIR) + +if(Libncurses_FOUND) + set(Libncurses_LIBRARIES ${Libncurses_LIBRARY}) + set(Libncurses_INCLUDE_DIRS ${Libncurses_INCLUDE_DIR}) +endif(Libncurses_FOUND) + +# print found information +message(VERBOSE "Libncurses_FOUND: ${Libncurses_FOUND}") +message(VERBOSE "Libncurses_VERSION: ${Libncurses_VERSION}") +message(VERBOSE "Libncurses_INCLUDE_DIRS: ${Libncurses_INCLUDE_DIRS}") +message(VERBOSE "Libncurses_COMPILE_OPTIONS: ${Libncurses_COMPILE_OPTIONS}") +message(VERBOSE "Libncurses_LIBRARIES: ${Libncurses_LIBRARIES}") diff --git a/cmake/Version.cmake b/cmake/Version.cmake index a061e48..5c72c35 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(xloop-version xloop-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 |