[CMake] Preprocessed linker script

Vladimir kv11111 at mail.ru
Fri Oct 3 11:04:09 EDT 2008


Hello Alexander,

Thanks a lot for your suggestion, it works well for me !

Alexander Neundorf wrote:

> 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

-- 
         Best Regards,
              Vladimir



More information about the CMake mailing list