cmake globbing生成的文件
我正在使用asn1c
是为了从一个或多个.asn1
文件中产生一系列.h
和.c 。代码>文件到给定文件夹。
这些C文件与原始ASN1
文件没有任何对应关系。
这些文件必须与我的链接在一起,才能获得工作可执行文件。我希望能够:
- 自动生成构建目录中的文件,以避免污染项目的其余部分(可能使用
add_custom_target
) - 指定我的可执行文件对这些文件的依赖性,以便
ASN1C
如果文件丢失,或者如果更新了.asn1
文件之一,则会自动运行。 - 自动将所有生成的文件添加到我的可执行文件的汇编中。
由于未知生成的文件不知道,只要目录不是空的,我很高兴,只要asn1c
命令的输出目录的内容都可以。
I'm using asn1c
in order to produce from one or more .asn1
files a series of .h
and .c
files into a given folder.
These C files have no correspondence in names with the original asn1
files.
These files must be linked together with mine in order to obtain a working executable. I'd love to be able to:
- Automatically generate the files in the build directory to avoid polluting the rest of the project (probably done with
add_custom_target
) - Specify the dependency of my executable on those files, so that the
asn1c
executable is automatically run if the files are missing or if one of the.asn1
files is updated. - Automatically add ALL generated files to the compilation of my executable.
Since the generated files are not known in advance it's ok to just glob whatever the contents of the output directory of the asn1c
command - as long as the directory is not empty I'm happy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CMAKE期望完整的列表将传递给
add_executable()
。也就是说,您不能在 build stage 上生成的网络文件 - 为时已晚。您有几种方法可以处理生成源文件,而无需提前知道其名称:
使用配置阶段生成文件使用
execute_process
。之后,您可以使用file(glob)
用于收集源名称,然后将它们传递给add_executable()
:如果生成的输入文件(
.asn1
在您的情况下)将来不打算更改,这是最简单的方法。如果您打算更改输入文件,并期望CMAKE检测这些变化并重新生成源,则应采取更多措施。例如,您可以首先使用
configure_file(copy_only)
将输入文件复制到构建目录中。在这种情况下,将跟踪输入文件,如果更改CMAKE将重新运行:解析输入文件以确定,将从它们创建哪些文件。不确定它是否适用于
.asn1
,但对于某些格式,这起作用:在这种情况下,cmake将检测输入文件中的更改(但如果修改列表生成的源文件,您需要重新运行
cmake
手动 em>)。CMake expects complete list of sources to be passed to
add_executable()
. That is, you cannot glob files generated at build stage - it would be too late.You have several ways for handle generating source files without knowing their names in advance:
Generate files at configuration stage with
execute_process
. After that you may usefile(GLOB)
for collect source names and pass them toadd_executable()
:If input files for generation (
.asn1
in your case) are not intended to be changed in the future, this is the most simple approach which just works.If you intend to change input files and expect CMake to detect these changings and regenerate source, some more action should be taken. E.g., you may first copy input files into build directory with
configure_file(COPY_ONLY)
. In that case input files will be tracked, and CMake will rerun if they are changed:Parse input files for determine, which files would be created from them. Not sure whether it works with
.asn1
, but for some formats this works:In that case CMake will detect changes in input files (but in case of modification of list of generated source files you need to rerun
cmake
manually).