[CMake] Preprocessed linker script

Alexander Neundorf a.neundorf-work at gmx.net
Thu Oct 2 18:14:05 EDT 2008


On Monday 29 September 2008, Vladimir wrote:
> Hello,
>
> I want to link an executable with custom linker script, but my script have
> to be preprocessed with cpp. I've tried using add_custom_command and
> add_dependencies:
>
> set(MOD_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/kernel_mod.ld)
> add_custom_command(OUTPUT ${MOD_LINKER_SCRIPT}
>     cpp -nostdinc -P ${CMAKE_SOURCE_DIR}/${ARCH_LINKER_SCRIPT} -o
> ${MOD_LINKER_SCRIPT}
>     DEPENDS ${CMAKE_SOURCE_DIR}/${ARCH_LINKER_SCRIPT} VERBATIM)
>
> add_executable(kernel_mod ${MOD_SOURCES})
> add_dependencies(kernel_mod ${MOD_LINKER_SCRIPT})
> set_target_properties(kernel_mod PROPERTIES
> LINK_FLAGS "-T${MOD_LINKER_SCRIPT}")
>
> but the dependency is somhow ignored and my custom command is not invoked.

ADD_DEPENDENCIES() works only for target-level dependencies, but 
MOD_LINKER_SCRIPT is a file and no target, so this doesn't work.

Please have a look at the attached example, I think it does what you want.
It has an add_custom_command(), which creates a dummy c file, which does 
nothing but which is part of the sources of the target. So if this file 
changes the target is linked again. This add_custom_command() depends on the 
file "abc", which in your case would be the ${ARCH_LINKER_SCRIPT}. So if this 
file changes, the dummy file is recreated, so the target is linked again. 
Additionally the add_custom_command() also runs the actual command to create 
the linker script, so this is also recreated every time the dummy C file is 
recreated.

Alex
-------------- next part --------------
A non-text attachment was scrubbed...
Name: linkerscriptdummy.tar.gz
Type: application/x-tgz
Size: 427 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081003/2e444e4b/attachment-0001.bin>


More information about the CMake mailing list