CMake:如何为可执行文件添加对链接器脚本的依赖 [英] CMake: How to add dependency on linker script for executable
问题描述
我有一个 CMake 脚本,其中最终的可执行文件与我自己的链接器脚本链接:
I have a CMake script where the final executable is linked with my own linker script:
cmake_minimum_required(VERSION 3.1)
project(test_app)
set(LINKER_SCRIPT "linker.ld")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf
main.cpp
startup.cpp
)
如何使可执行文件也依赖于链接器脚本文件(如果 linker.ld
被更改,则触发链接)?
How do I make an executable dependent also on the linker script file (trigger linking if linker.ld
was changed)?
推荐答案
您可以添加 LINK_DEPENDS 属性到您的可执行目标,使用 set_target_properties.在 add_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})
set_target_properties
的第一个参数是目标名称,即您传递给 add_executable
的第一个参数.
The first argument to set_target_properties
is the target name, i.e. the first argument you passed to add_executable
.
这篇关于CMake:如何为可执行文件添加对链接器脚本的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!