LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   CMake and very platform specific Makefiles (https://www.linuxquestions.org/questions/programming-9/cmake-and-very-platform-specific-makefiles-774795/)

random0 12-10-2009 03:58 PM

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?

a4z 12-11-2009 09:30 AM

there is a execute_process (in older versions it was exec_program) command for cmake
maybe this is what you are looking for

random0 12-11-2009 04:14 PM

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.


All times are GMT -5. The time now is 04:28 PM.