相关疑难解决方法(0)

添加以文件名作为目标的自定义命令

我想做一些事情add_custom_command,输出文件名作为生成的makefile中的目标.这样做有一种优雅的方式吗?

我见过的所有示例(例如CMake FAQ re:latex)用于add_custom_command说明如何生成所需的输出文件,然后add_custom_target创建目标.例如.:

add_executable (hello hello.c)
add_custom_command(OUTPUT hello.bin
                   COMMAND objcopy --output-format=binary hello hello.bin
                   DEPENDS hello
                   COMMENT "objcopying hello to hello.bin")
add_custom_target(bin ALL DEPENDS hello.bin)
Run Code Online (Sandbox Code Playgroud)

但是,生成的makefile中的目标名称bin不是hello.bin.有没有办法让hello.bin自己成为生成的makefile中的目标?

我试过的一些解决方案不起作用:

  • 更改为:会add_custom_target(hello.bin ALL DEPENDS hello.bin)导致makefile中出现循环依赖关系.

cmake

7
推荐指数
1
解决办法
7069
查看次数

标签 统计

cmake ×1