将汇编标志限制为某些文件
我正在尝试向相当大的遗产项目介绍-Werror Flag。不出所料,它会完全打破汇编。因此,我决定逐步介绍它,并首先为新代码介绍。我最初的方法是将新功能汇编为单独的静态目标,并将其链接到项目,该项目在项目结构和可读性方面都有点好。持续存在预先存在的问题包括。基本上,即使在用新代码中修复了所有警告后,我还列出了链条,包括引入新警告。是否有任何方法将警告标志的使用量限制为严格的源文件? 我确实了解其中包括手段基本上将标头复制到CPP中,因此仅使用CMAKE设置似乎不可能。然后是布拉格马斯?
I'm trying to introduce -Werror flag to rather big legacy project. As expected, it breaks the compilation completely. Therefore I've decided to introduce it gradually, and for the new code first of all. My original approach was to compile new features as separate static targets and link them to the project, which works kind of good both in terms of project structure and readability. The problem which persist are pre-existing tangled includes. Basically, even after fixing all warnings in new code I'm left with chain of includes introducing new warnings. Is there any way to limit warning flags usage to given source files strictly?
I do understand that include means basically copy/pasting headers into cpps, so it does not seem possible with just cmake settings. Then pragmas, perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用设置
这样的事情:
You can use the
set_source_files_properties
command to set theCOMPILE_OPTIONS
property on the files you need.Something like this:
我不知道任何允许您仅在其中包含的文件上应用标志的编译器标志,因此CMAKE不能为您做得更好。因此,布拉格马是必经之路。
基本上,您在CPP文件中有效的内容是这样的:
请注意,如果您随着时间的推移逐渐更新标头,则需要在多个翻译单元中重复此逻辑。
作为替代方案,您可以复制标头文件子目录,并通过一条路径和通过另一个路径更新标头提供未更新的版本,例如header
foo/bar/bar/baz.hpp
使标题要么使标题可通过路径获得旧/foo/bar/baz.hpp
或new/foo/bar/bar/baz.hpp
并创建一个可通过foo/bar/提供的新标头baz.hpp
看起来像这样:请注意,您可能需要为您编写这些标题。您甚至可以在项目的一代过程中通过CMAKE生成实际包含,该项目将把标题缩短到3个PRAGMAS加一个包括:这将具有与不支持
__ has_include
的编译器版本合作的其他好处。I don't know about any compiler flags that allow you to apply flags to only some of the files included, so cmake cannot do better for you. Therefore pragmas are the way to go.
Basically what you effectively want in your cpp files is something like this:
Note that this would require this logic to be repeated in multiple translation units which you may want to avoid, if you're updating the headers gradually over time.
As an alternative you could duplicate the header file subdirectories, and make the non-updated versions available via one path and updated headers via another, e.g. for a header
foo/bar/baz.hpp
either make the header available via pathold/foo/bar/baz.hpp
ornew/foo/bar/baz.hpp
and create a new header available viafoo/bar/baz.hpp
that looks like this:Note that you'll probably need to write these kind of headers for you. You could even generate the actual includes via cmake during the generation of the project which which would shorten the headers to 3 pragmas plus one include; this would have the additional benefit of working with compiler versions not supporting
__has_include
.