CMake: How to add dependency on linker script for executable

You can add a LINK_DEPENDS property to your executable target, using set_target_properties. Add the following line after your add_executable command:

set_target_properties(${TARGET_NAME} PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})

The first argument to set_target_properties is the target name, i.e. the first argument you passed to add_executable.

Leave a Comment