Compare commits

2 Commits

Author SHA1 Message Date
stubbfel
0a8f42f26e update Readme 2018-09-06 20:56:26 +02:00
stubbfel
c25f8c3dff add examples 2018-03-08 01:47:06 +01:00
4 changed files with 51 additions and 1 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "examples/LKMPG"]
path = examples/LKMPG
url = gitea@gitea.stubbe.rocks:3rd-party/LKMPG.git

View File

@@ -1,3 +1,13 @@
# CMake-Module-KernelModuleBuilder
With this cmake module the user can build/create/describe kernel modules in a CMakeLists.txt, in the way liwe a usespace executable or lib. E.g. see the CMakeLists.txt in example folder.
With this cmake module the user can build/create/describe kernel modules in a CMakeLists.txt, in the way like a usespace executable or lib. E.g. see the CMakeLists.txt in example folder.
* `include_directories` - "Add include directories to the build." -> https://cmake.org/cmake/help/latest/command/include_directories.html
* this cmake module will use the include entries from the `INCLUDE_DIRECTORIES` property (https://cmake.org/cmake/help/latest/prop_dir/INCLUDE_DIRECTORIES.html) of the `${CMAKE_CURRENT_SOURCE_DIR}` directory (https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_SOURCE_DIR.html)
* `add_definitions` - "Adds -D define flags to the compilation of source files." -> https://cmake.org/cmake/help/latest/command/add_definitions.html
* this cmake module will use the definition entries from the `COMPILE_DEFINITIONS` property (https://cmake.org/cmake/help/latest/prop_dir/COMPILE_DEFINITIONS.html) of the `${CMAKE_CURRENT_SOURCE_DIR}` directory (https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_SOURCE_DIR.html)
* `add_module` - "create a kernel module target"
* `function(add_module module_name module_files kernel_dir)`
* `module_name` - name of the module and target
* `module_files` - the source and object files of the moudles
* `kernel_dir` - path to kernelt build enviroment

36
examples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 2.6)
include("../BuildKernelModule.cmake")
project ("example_modules")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Weverything")
if(NOT KERNEL_DIR)
Set(KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" )
endif()
# create LKMPG examples
## find example folder
file(GLOB LKMPG_Folders
"${PROJECT_SOURCE_DIR}/LKMPG/[0-9][0-9][0-9].*"
"${PROJECT_SOURCE_DIR}/LKMPG/[0-9][0-9].*"
"${PROJECT_SOURCE_DIR}/LKMPG/[0-9].*")
list(GET LKMPG_Folders 0 LKMPG_Folder)
set(LKMPG_Example_Folder "${LKMPG_Folder}/examples/")
include_directories("${LKMPG_Example_Folder}")
## enable debug mode
add_definitions(-DDEBUG)
## create each c file as own module
file(GLOB LKMPG_files "${LKMPG_Example_Folder}/*.c")
foreach(module_file ${LKMPG_files})
string(REGEX MATCH "^.+\\.c$" match_file ${module_file})
if(NOT ${match_file})
file(RELATIVE_PATH rel_file "${LKMPG_Example_Folder}" ${module_file} )
string(REPLACE ".c" "" module_name ${rel_file})
add_module("${module_name}" "${module_file}" "${KERNEL_DIR}")
endif()
endforeach()

1
examples/LKMPG Submodule

Submodule examples/LKMPG added at 6e8a27232c