如何收集与CMake的源文件,而无需通配符? [英] How to collect source files with CMake without globbing?
问题描述
借助 CMake的文档明确指出,文件(GLOB ...)
不是
建议收集源文件的生成,但它不
别说什么实际建议的方法是。
The CMake documentation explicitly states that file(GLOB ...)
is not
recommended to collect source files for a build, but it doesn't
mention what the recommended method actually is.
指定每个源文件太多手动手动听起来有点
对我来说。那么,什么是正确的方法来收集源文件,如果没有文件(GLOB ...)
?
Specifying every source file manually sounds a little bit too manually
to me. So, what is the right method to collect source files, if not
file(GLOB ...)
?
推荐答案
手册确实是推荐的方法。通过推荐反对使用GLOB,该文档只是警告不要依赖于文件present构建系统。例如,要添加一个测试可执行文件,所以您创建mytest.cpp。哎呀。现在,您的库编译休息。对于AUX_SOURCE_DIRECTORY(用途类似的文件名替换为源文件)的文档提供了以下警告:
Manual is indeed the recommended method. By recommending against using GLOB, the documentation is simply warning against a build system that depends on files present. For example, you want to add a test executable, so you create mytest.cpp. Oops. Now your library compilation breaks. The documentation for AUX_SOURCE_DIRECTORY (similar purpose as globbing for for source files) gives the following warning:
这是很有诱惑力的使用这个命令来避免编写源列表
文件库或可执行的目标。虽然这似乎工作,
有没有办法让CMake的生成,知道当一个构建系统
新的源文件已被添加。通常情况下,产生的构建系统
知道什么时候它需要重新运行CMake的,因为的CMakeLists.txt文件
修改,以添加新的源。当源是刚刚加入
无需修改此文件目录,一会手动必须
重新运行CMake的生成构建系统结合了新的文件。
It is tempting to use this command to avoid writing the list of source files for a library or executable target. While this seems to work, there is no way for CMake to generate a build system that knows when a new source file has been added. Normally the generated build system knows when it needs to rerun CMake because the CMakeLists.txt file is modified to add a new source. When the source is just added to the directory without modifying this file, one would have to manually rerun CMake to generate a build system incorporating the new file.
如果你确定你想要的目录中的所有内容,而不要添加新的,然后通过各种手段使用GLOB计划。
If you're certain that you want all the contents of a directory, and don't plan on adding new ones, then by all means use a GLOB.
另外,不要忘记列出文件手动没有涉及打字所有的文件名。你可以做,例如, LS *&的.cpp GT;>的CMakeLists.txt
,然后用你的编辑器文件列表移动到文件在正确的位置。
Also, don't forget listing files manually doesn't have to involve typing all the filenames. You could do, for example, ls *.cpp >> CMakeLists.txt
, then use your editor to move the list of files to the correct place in the file.
这篇关于如何收集与CMake的源文件,而无需通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!