CMake:如何添加对可执行文件的链接描述文件的依赖性 [英] CMake: How to add dependency on linker script for executable

查看:97
本文介绍了CMake:如何添加对可执行文件的链接描述文件的依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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 <的第一个参数/ code>是目标名称,即您传递给 add_executable 的第一个参数。

这篇关于CMake:如何添加对可执行文件的链接描述文件的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆