向 CMake 生成的构建系统本身添加依赖项 [英] Add dependency to the CMake-generated build-system itself
问题描述
简而言之:我知道如何在 CMake 生成的构建系统中向目标添加依赖项.但我想为生成的构建系统本身添加依赖项.
In short: I know how to add dependencies to targets, in a CMake-generated build system. But I would like to add dependencies to the generated build-system itself.
更长的问题:在cgal,我们希望 CMake 在修改某些文件时自动重新运行配置步骤.不需要的细节隐藏在下面:
Longer question: In the CMake-generated build process of cgal, we would like CMake to automatically re-run the configuration step, when certain files are modified. Unneeded details are hidden below:
事实上,我们使用 CMake 生成 CGAL 库/示例/演示的构建系统,同时也是 Doxygen 生成的文档的构建系统.
Doxyfile
由多个文件生成.
当CMake生成器为Makefile
"时,Makefile
中有一个特殊的target,名为rebuild_cache
,但是那个target(在 Makefile 级别)不是 CMake 目标.无论如何,我正在寻找一种跨平台的解决方案,即:可用于所有 CMake 生成器.我的印象是,我想要的东西还不能用 CMake 实现.能否请您确认一下,以便我可以填写记录在案的功能请求?
When the CMake generator is "Makefile
", there is a special target in the Makefile
, that is named rebuild_cache
, but that target (at the Makefile level) is not a CMake-target. And anyway, I look for a solution that is cross-platform, that is: usable with all CMake generators. I have the impression that what I want is not yet doable with CMake. Can you please confirm, so that I can fill a documented feature-request?
推荐答案
从 CMake 3.0 开始,您可以将这样的文件添加到目录属性 CMAKE_CONFIGURE_DEPENDS
.此属性包含文件列表;如果其中任何一个发生变化,CMake 将触发重新配置.
Since CMake 3.0, you can add such a file to the directory property CMAKE_CONFIGURE_DEPENDS
. This property holds a list of files; if any of them changes, CMake will trigger re-configuration.
这是一个小例子.假设您的 Doxyfile
是从当前源目录中的 Doxyfile.in.1
和 Doxyfile.in.2
生成的,则可以像这样使用该属性这个:
Here is a small example. Assuming your Doxyfile
is generated from Doxyfile.in.1
and Doxyfile.in.2
in the current source directory, the property could be used like this:
set_property(
DIRECTORY
APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS
Doxyfile.in.1
Doxyfile.in.2
)
<小时>
如果您使用的是 CMake 2.x,则属性 CMAKE_CONFIGURE_DEPENDS
不可用,但您可以使用以下技巧:
If you're using CMake 2.x, the property CMAKE_CONFIGURE_DEPENDS
is not available, but you can use the following trick:
通过configure_file()
传递文件,即使您只是COPYONLY
将它们放在某个地方并且不使用生成的副本.configure_file()
准确地引入了您正在寻找的构建系统依赖项.
Pass the files through configure_file()
, even if you just COPYONLY
them someplace and don't use the resulting copies. configure_file()
introduces precisely the buildsystem dependency you're looking for.
这有效,但它增加了复制文件的开销.
This works, but it adds the overhead of copying the file.
(注意:这个技巧也是这个答案的原始内容,因为我在回答时不知道CMAKE_CONFIGURE_DEPENDS
).
这篇关于向 CMake 生成的构建系统本身添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!