[CMake] linux kernel module, output directory and clean issues

Alexander Neundorf a.neundorf-work at gmx.net
Thu Aug 16 11:25:11 EDT 2007


On Thursday 16 August 2007 10:18, Tim Schooley wrote:
> Hi all!
>
> [My first post, please bear with me...]
>
> I've been porting a Makefile project to use CMake. Thankfully, it's gone
> very smoothly, and now I'm just trying to iron out some ripples. CMake
> truly rocks.
>
> I found some advice on this mailing list for building linux kernel
> modules, and I'm using the following for it:
>
> ---
>
> Set( DRIVER_FILE mydriver.ko )
> Set( KERNEL_DIR "/lib/modules/${CMAKE_SYSTEM_VERSION}/build" )
> Set( KBUILD_CMD ${CMAKE_MAKE_PROGRAM}
>                 -C ${KERNEL_DIR}
>                 M=${CMAKE_CURRENT_SOURCE_DIR} modules)
>
> Add_Custom_Command( OUTPUT ${DRIVER_FILE}
>                     COMMAND ${KBUILD_CMD}
>                     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
>                     DEPENDS ${src} Kbuild VERBATIM )
>
> Add_Custom_Target ( driver ALL DEPENDS ${DRIVER_FILE} )
>
> ---
>
> My issue is this: no matter how I specify the output, I cannot for the
> life of me get the mydriver.ko file to be outputted to the
> ${PROJECT_BINARY_DIR}/bin directory. I've searched around for similar
> issues/code, but come to a dead end.

You mean it's not created or is it created in the wrong directory ?
You should also use the full path for generated files, i.e. 
Set( DRIVER_FILE "${CMAKE_CURRENT_BINARY_DIR}/mydriver.ko")


> My second problem: I'm aware that you currently cant add custom commands
> to the "clean" target, but is there _any_ way of cleaning up the kernel
> module source directory when "clean" is called, even if it's a slightly
> nasty hack ?

"make clean" will remove also the files listed as OUTPUT in a custom command.
If you need more files to be removed, you can use SET_DIRECTORY_PROPERTIES( 
ADDITIONAL_MAKE_CLEAN_FILES) .

Alex


More information about the CMake mailing list