Developing Linux drivers with CLion.

I'm having some trouble getting CMake to build Linux Kernel Modules. There are some headers I need that aren't in the path expected for the linux headers. I have the headers on my computer, but the headers are located per each installed kernel, rather than under  /usr/include/linux

What I currently have for CMake:

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
project(driver)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")

set(HEADERS
       razerchromacommon.h
       razercommon.h
       razerfirefly_driver.h
       razerkbd_driver.h
       razermouse_driver.h)

set(SOURCE
       razerchromacommon.c
       razercommon.c
       razerfirefly_driver.c
       razerkbd_driver.c
       razermouse_driver.c)


#execute_process(COMMAND uname -r
# RESULT_VARIABLE INSTALLED_KERNEL)
#message(${INSTALLED_KERNEL})
#set(INCLUDE_DIRS
# /usr/lib/modules/${INSTALLED_KERNEL}/build/include/linux/usb/)
#include_directories(${INCLUDE_DIRS})
     
add_executable(driver ${HEADERS} ${SOURCE})

Would just calling the Linux kernel kbuild work with CLion?

0
2 comments

So, I've had some success with finding headers. The only problem is the current CMakeLists I have going would need all of the current kernels headers and preprocessor variables. I'm going to see if I can get kbuild working through cmake.  Does anyone know if having CMake call KBuild would work with CLion?

Here's what I have so far:

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
project(driver)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")

set(HEADERS
razerchromacommon.h
razercommon.h
razerfirefly_driver.h
razerkbd_driver.h
razermouse_driver.h)
set(SOURCE
razerchromacommon.c
razercommon.c
razerfirefly_driver.c
razerkbd_driver.c
razermouse_driver.c)
set(PREFIX "/usr/lib/modules/")
set(SUFFIX "/build/include/")
execute_process(COMMAND uname -r
OUTPUT_VARIABLE INSTALLED_KERNEL
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LINUX_KERNEL_PATH ${PREFIX}${INSTALLED_KERNEL}${SUFFIX})
message(${LINUX_KERNEL_PATH})
find_path(CUSTOM_INCLUDES
NAMES linux/usb/input.h
PATHS ${LINUX_KERNEL_PATH}
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
include_directories(${CUSTOM_INCLUDES})

add_executable(driver ${HEADERS} ${SOURCE})
0

Did you manage to solve this issue eventually? I'm trying to do the same thing without any success.

0

Please sign in to leave a comment.