CMake-始终构建特定文件 [英] CMake - always build specific file

查看:93
本文介绍了CMake-始终构建特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的文件,无论是否已对其进行修改,都应在每次编译时对其进行重建。原因是它取决于值更改的系统宏。我该如何强制使用CMake进行重建?我不想将其绑定到特定目标:在CMakeLists.txt中指定的任何目标开始实际构建过程之前,应触摸文件。

I have a specific file that should be rebuilt on each compilation regardless if it has been modified or not. The reason is that it is depending on system macros whose values change. How could I force rebuild with CMake? I'd like to not bind it to specific target: the file should be "touched" before any of the targets specified in CMakeLists.txt begins the actual build process.

推荐答案

CMake具有 add_custom_target 命令:

CMake has a add_custom_target command:


添加具有给定名称的目标,该目标执行给定命令。目标没有输出文件,并且即使命令尝试使用目标名称创建文件,该目标也会被视为已过期。 [...]默认情况下,任何内容都不取决于自定义目标。 使用 add_dependencies()命令向其他目标添加依赖关系。

Adds a target with the given name that executes the given commands. The target has no output file and is always considered out of date even if the commands try to create a file with the name of the target. [...] By default nothing depends on the custom target. Use the add_dependencies() command to add dependencies to or from other targets.

这篇关于CMake-始终构建特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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