为什么是cmake文件GLOB? [英] Why is cmake file GLOB evil?

查看:2319
本文介绍了为什么是cmake文件GLOB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CMake文件说明命令文件GLOB

The CMake doc says about the command file GLOB:


我们不建议使用GLOB从源代码树中收集源文件列表。如果在添加或删除源时没有CMakeLists.txt文件更改,那么生成的构建系统无法知道何时请求CMake重新生成。

We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.

但是,为了让构建系统知道源代码已经被添加或删除,说

However, to make the build system know that a source has been added or removed, it's sufficient to say

touch CMakeLists.txt

对不对?

那么编辑 CMakeLists.txt 可以插入或删除源文件名。也不是很难记住。所以我没有看到任何好的理由,建议反对文件GLOB

Then that's less effort than editing CMakeLists.txt to insert or delete a source file name. Nor is it more difficult to remember. So I don't see any good reason to advise against file GLOB.

这个参数有什么问题? / p>

What's wrong with this argument?

推荐答案

问题是当你不是一个人在一个项目上工作。

The problem is when you're not alone working on a project.

让我们假设项目有开发人员A和B.

Let's say project has developer A and B.

A添加了一个新的源文件 xc 。他不会更改 CMakeLists.txt ,并在他完成实施 xc 后提交。

A adds a new source file x.c. He doesn't changes CMakeLists.txt and commits after he's finished implementing x.c.

现在B做了 git pull ,因为没有修改 CMakeLists.txt ,CMake不会再次运行,并且B在编译时有链接器错误,因为 xc 尚未添加到其源文件列表。

Now B does a git pull, and since there have been no modifications to the CMakeLists.txt, CMake isn't run again and B have linker errors when compiling, because x.c has not been added to its source files list.

这篇关于为什么是cmake文件GLOB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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