LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-10-2009, 03:58 PM   #1
random0
LQ Newbie
 
Registered: Jun 2006
Location: Gainesville, Fl, USA
Distribution: Debian GNU/Linux
Posts: 18

Rep: Reputation: 0
CMake and very platform specific Makefiles


Not sure if this goes in General Programming as it has implications across platforms or in Linux as my problem is currently about that.

I'm working on a project that uses CMake for building. There's a directory of the source tree that includes drivers for the various target platforms. I've figured out how to make a CMakeLists.txt that can generate a Makefile to use the Kbuild system for the Linux drivers, but that's not what I would rather do.

The source directory containing the Linux kernel modules has a Makefile that uses Kbuild. The build process only gets to this directory if the platform is Linux. So, if the build process reaches that point, I know that the Makefile is compatible enough with the system. Is there a way that, once I get down to this directory, I can use the module's own Makefile instead of having CMake generate one for me?
 
Old 12-11-2009, 09:30 AM   #2
a4z
Member
 
Registered: Feb 2009
Posts: 444

Rep: Reputation: 152Reputation: 152
there is a execute_process (in older versions it was exec_program) command for cmake
maybe this is what you are looking for
 
Old 12-11-2009, 04:14 PM   #3
random0
LQ Newbie
 
Registered: Jun 2006
Location: Gainesville, Fl, USA
Distribution: Debian GNU/Linux
Posts: 18

Original Poster
Rep: Reputation: 0
I finally did decide to have cmake generate the Makefile instead of using the existing one. If anyone is curious, this is how I solved it:

CMakeLists.txt in the module source directory.
Code:
SET( MODULE_NAME
	my_module
)

SET( MODULE_SOURCE_FILES
	my_module_driver.c
	my_module_ops.c
	my_module_ops.h
)

SET( MODULE_FILE
	${MODULE_NAME}.ko
)

SET( MODULE_OUTPUT_DIR
	${CMAKE_BINARY_DIR}/modules/${MODULE_NAME}
)

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

SET( KBUILD_COMMAND
	${CMAKE_MAKE_PROGRAM} -C ${KERNEL_DIR} M=${MODULE_OUTPUT_DIR} modules
)

CONFIGURE_FILE(
	Kbuild.in
	${MODULE_OUTPUT_DIR}/Kbuild
)

FOREACH( MODULE_SOURCE_FILE ${MODULE_SOURCE_FILES} )
	CONFIGURE_FILE(
		${MODULE_SOURCE_FILE}
		${MODULE_OUTPUT_DIR}/${MODULE_SOURCE_FILE}
		COPYONLY
	)
ENDFOREACH( MODULE_SOURCE_FILE )

ADD_CUSTOM_COMMAND(
	OUTPUT ${MODULE_OUTPUT_DIR}/${MODULE_FILE}
	COMMAND ${KBUILD_COMMAND}
	WORKING_DIRECTORY ${MODULE_OUTPUT_DIR}
	DEPENDS ${MODULE_SOURCE_FILES} Kbuild.in
	VERBATIM
)

ADD_CUSTOM_TARGET(
	${MODULE_NAME}
	ALL
	DEPENDS ${MODULE_OUTPUT_DIR}/${MODULE_FILE}
)
And I also made a file called Kbuild.in.
Code:
obj-m := ${MODULE_NAME}.o
${MODULE_NAME}-objs += my_module_driver.o
${MODULE_NAME}-objs += my_module_ops.o

EXTRA_CFLAGS := -I${PROJECT_SOURCE_DIR}/include
EXTRA_CFLAGS += -DDEBUG
But this doesn't solve the problem of installation. To me, it seems that the only way cmake handles installation is by copying files with the INSTALL command. If there was a command like RUN_ON_INSTALL, I could call the Kbuild install_modules thing and have that handle the system specific stuff about where it should go.
 
  


Reply

Tags
cmake, driver, kernel, make


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using gdbserver from x86 platform to mips based platform. Neuzen Programming 4 05-13-2008 07:06 AM
How do I get platform specific info in Java devn Programming 5 10-15-2007 12:51 AM
LXer: Platform Expands Platform Open Cluster Stack With First AMD-Based ... LXer Syndicated Linux News 0 11-13-2006 06:54 PM
how to run programmes made for windows platform in linux platform... compugeek2006 Linux - Software 1 06-26-2006 09:34 PM
How can i send message from Linux platform to Windows platform linuxeagle Linux - Networking 1 02-17-2004 12:35 AM


All times are GMT -5. The time now is 02:53 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration