[CMake] Building linux kernel module with Cmake

Suhas Jain suhasj at aftek.com
Mon Nov 5 02:58:48 EST 2007


Hi,

I have made changes to my CMakeLists.txt file

Here is my complete CMakeLists.txt file

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..

 

Set( KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" )

Set( kbuild_cmd ${CMAKE_MAKE_PROGRAM}

                -C ${KERNEL_DIR}

                M=${CMAKE_CURRENT_SOURCE_DIR} modules)

 

set ( kofile ${CMAKE_CURRENT_SOURCE_DIR}/hello.ko )

add_custom_command ( OUTPUT ${kofile}

                    COMMAND ${kbuild_cmd}

                    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

                    DEPENDS ${src} Kbuild VERBATIM 

                    COMMENT "Building kernel module...")

add_custom_target ( cool_driver ALL DEPENDS ${kofile} )

 

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<..

 

But on compilation I get this following error.

 

make[2]: *** No rule to make target `Kbuild', needed by `hello.ko'.  Stop.

make[1]: *** [CMakeFiles/cool_driver.dir/all] Error 2

make: *** [all] Error 2

 

 

If I exclude the Kbuild from DEPENDS.

 

I get this error:

Makefile:43 CMakeFiles/progress.make: No such file or directory

 

Is this line required?

 

I have already compiled my kernel . 

The driver gets compiled with normal kernel module Makefile

This is the Makefile that I have used . 

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<..

MODULE_NAME = hello

$(MODULE_NAME)-objs = main.o output.o

 

RM      = @rm -rf

JUNK   = *~ *.bak DEADJOE

 

 

# First pass, kernel Makefile reads module objects

ifneq ($(KERNELRELEASE),)

obj-m  := $(MODULE_NAME).o

 

EXTRA_CFLAGS += -I$(PWD)/../include

 

# Second pass, the actual build.

else

KVER    ?= $(shell uname -r)

KDIR    := /lib/modules/$(KVER)/build

PWD    := $(shell pwd)

 

all:

          $(MAKE) -C $(KDIR) M=$(PWD) modules

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..

Is this possible using the cmake ?

 

One more thing that is doubtful is:

How to specify the Obj-m and $(MODULE_NAME)-objs parameters?

Please give me some pointers to solve this issue or any working sample of
CMakeLists.txt for compiling kernel modules

 

I am stuck with this problem. Waiting for your replies

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071105/ba789242/attachment.htm


More information about the CMake mailing list