如何使 CMake 重新配置依赖于自定义文件? [英] How to make CMake reconfiguration depend on custom file?

查看:25
本文介绍了如何使 CMake 重新配置依赖于自定义文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CMake 下有一个项目,其中一些文件是用 Python 生成器从 XML 文件生成的.我无法在 CMakeLists.txt 中指定此生成器生成的所有文件,因此我为此使用了文件通配符.

I have a project under CMake with some files generated with python generator from XML files. I cannot specify all files generated by this generator in CMakeLists.txt so I use file globbing for this.

问题是,当我更新我的 XML 文件或生成器源(位于同一个存储库中)时,我希望重新配置我的构建系统,以便在重建代码时考虑更改的文件(例如通过 make).

The problem is that when I update my XML files or generator sources (which are in the same repository) I would like to have my build system reconfigured so changed files are taken into account when rebuilding the code (via make for example).

是否可以让 CMake 像对待 CMakeLists.txt 文件一样对待某些文件,并在更改这些文件时使其重新生成构建系统?

Is it possible to make CMake treat some files like it treats CMakeLists.txt files and to make it regenerate build system when those file are changed?

推荐答案

是的,您应该能够通过(ab)使用 configure_file() 来做到这一点.配置文件会使源成为 CMake 运行的依赖项,因此其中的任何更改都会导致重新配置.就像这样:

Yes, you should be able to do that by (ab)using configure_file(). Configuring a file makes the source a dependency of the CMake run, so that any changes in it cause a reconfiguration. Simply like this:

configure_file(MyInputFile.xml DummyOutput.xml)

这篇关于如何使 CMake 重新配置依赖于自定义文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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