是否可以创建一个 cmake 脚本来生成一个构建来处理构建时生成的未知文件?
我有一个系统,可以从规范文档生成生成的代码,该文档可以随时更改。因此,生成的文件列表不能是静态的,并且必须能够在构建时动态处理。
据我所知,典型的 CMakeLists.txt 设置为在 cmake 生成时为每个文件定义规则。
有没有办法让 CMake 编写通用规则,以便可以在构建时设置目标?
如果没有,可能的解决方法是什么?
I have a system that produces generated code from a spec document which can change at any time. As such, the list of files being generated cannot be static, and must be able to be handled dynamically at build time.
From what I can tell the typical CMakeLists.txt is set up to define a rule for each file at cmake generation time.
Is there a way to get CMake to write generic rules so that the targets can be set at build time?
If not, what are the possible work-arounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你可以将你的代码生成过程以目标(add_custom_command)的形式放入CMakeLists.txt中,然后让你的目标依赖于这个命令。这是代码生成步骤,每次您发出
make
时都会运行。或者,这里有一个 hack:
还有一个不太 hackish 的变体,它应该保留已经构建的目标:
将此类代码添加到 CMakeLists.txt 中会强制 CMake 在每次运行时重新生成 makefile,而无需运行完整的配置过程。
First, you can put your code generation process into CMakeLists.txt in a form of a target (add_custom_command), and then make your target depends on this command. This was code generation steps will be run every time you issue
make
.Alternatively, here is a hack:
And a less hackish variant, which should preserve already built targets:
Adding such code into CMakeLists.txt forces CMake to regenerate makefiles on each run without running full configuration process.