cmake add_custom_command
我正在努力解决 add_custom_command 问题。让我详细解释一下这个问题。
我有这些 cxx 文件和 hxx 文件集。我在每个文件上运行一个 perl 脚本来生成某种类型的翻译文件。 对于 header.hxx 文件,该命令看起来
perl trans.pl source.cxx -o source_cxx_tro
也类似。
因此,我最终会得到一些多个命令(每个命令对应一个文件),
然后我对这些命令生成的输出运行另一个 perl scripn(source_cxx_tro、header_hxx_tro),
perl combine.pl source_cxx_tro header_hxx_tro -o dir.trx
dir.trx 是输出文件。
我有这样的东西。
Loop_Over_All_Files()
Add_Custom_Command (OUTPUT ${trofile} COMMAND perl trans.pl ${file} -o ${file_tro})
List (APPEND trofiles ${file_tro})
End_Loop()
Add_Custom_Command (TARGET LibraryTarget POST_BUILD COMMAND perl combine.pl ${trofiles} -o LibraryTarget.trx)
我期望的是在构建后构建目标时,将首先构建trofiles。但事实并非如此。 ${trofiles} 未构建,因此构建后命令以失败告终。 有什么方法可以告诉 POST_BUILD 命令依赖于之前的自定义命令吗?
有什么建议吗?
提前致谢, 苏里亚
I'm struggling with add_custom_command. Let me explain the problem in detail.
I've these set of cxx files and hxx files. I run a perl script on each of them to generate a certain kind of translation file. The command looks like
perl trans.pl source.cxx -o source_cxx_tro
and similarly for header.hxx files as well.
So I'll end up with some multiple commands (each for a file)
Then I run another perl scripn on the output generated from these commands (source_cxx_tro, header_hxx_tro)
perl combine.pl source_cxx_tro header_hxx_tro -o dir.trx
dir.trx is the output file.
I've something like this.
Loop_Over_All_Files()
Add_Custom_Command (OUTPUT ${trofile} COMMAND perl trans.pl ${file} -o ${file_tro})
List (APPEND trofiles ${file_tro})
End_Loop()
Add_Custom_Command (TARGET LibraryTarget POST_BUILD COMMAND perl combine.pl ${trofiles} -o LibraryTarget.trx)
What I expect is when building the post build target, the trofiles will be built first. but it is not the case. The ${trofiles} are not getting built and hence the post build command ends in a failure.
Is there any way I can tell the POST_BUILD command depend on the previous custom command ?
Any suggestions ?
Thanks in advance,
Surya
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用add_custom_command创建文件转换链
并使用 add_custom_target 将最后一个转换设为 cmake 中的一流实体。默认情况下,不会构建此目标,除非您将其标记为 ALL 或让构建的另一个目标依赖于它。
Use add_custom_command's to create a file transformation chain
and make the last transformation an first class entity in cmake by using add_custom_target. By default this target won't be build, unless you mark it with ALL or let another target that is built depend on it.
您想要创建一个使用自定义命令的输出的自定义目标。然后使用 ADD_DEPENDENCIES 确保命令以正确的顺序运行。
这可能有点接近你想要的:
https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-do-i-use-cmake-to-build-latex-documents
基本上每个生成的文件都有一个 add_custom_command ,收集这些文件(trofile)的列表,然后使用 add_custom_target 和 DEPENDS 列表trofile。然后使用 add_dependency 使 LibraryTarget 依赖于自定义目标。然后应该在构建库目标之前构建自定义目标。
You want to create a custom target that consumes the output of the custom commands. Then use ADD_DEPENDENCIES to make sure the commands are run in the right order.
This might be sort of close to what you want:
https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-do-i-use-cmake-to-build-latex-documents
Basically one add_custom_command for each file generated, collect a list of those files (trofiles), then use add_custom_target with a DEPENDS on the list trofiles. Then use add_dependencies to make the LibraryTarget depend on the custom target. Then the custom target should be built before the library target is built.