使用CMake忽略/仅显示某些目录中的错误/警告 [英] Ignore/only show errors/warnings from certain directory using CMake

查看:1144
本文介绍了使用CMake忽略/仅显示某些目录中的错误/警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主要问题:是否有cmake配置,仅显示或忽略来自特定目录的编译器警告/错误?

main question: Is there a configuration for cmake, to show or ignore compiler warnings/errors only from a certain directory?

替代解决方案:如何在QtCreator中切换?

alternative solution: How can I toggle this in QtCreator?

背景/动机
我是在一个更大的CMake项目上工作,并且只想关注我的子项目中的警告和错误。我正在与QtCreator一起工作,这使我很烦恼在大量外国错误下寻找我的错误/警告。

background / motivation: I'm working on a bigger CMake-project and want to focus on warnings and errors only from my subproject. I'm working with QtCreator and it annoys me to look for "my" errors/warnings under a pile of foreign ones.

推荐答案

您至少可以在CMake中为某些 target 或某些文件设置编译器警告选项。

You can set compiler warning options in CMake at least for certain target or certain files.

# For target
set_target_properties(your_project_name PROPERTIES COMPILE_FLAGS "...")

# For files
set_source_files_properties(
  ${list_of_your_files}
  PROPERTIES
  COMPILE_FLAGS "..."
)

也可以通过将项目分隔为子项目来设置每个文件夹的选项,并使用 add_subdirectory(your_project)添加它

,并在您的项目CMakeLists.txt中使用 add_definitions(...)

It is also possible to set the options per-folder basis by separating your project as subproject, add it using add_subdirectory(your_project) and in your project CMakeLists.txt use add_definitions(...).

来自CMake文档:


add_definitions 将标志添加到编译器命令行中,用于显示当前目录及以下目录中的源。

add_definitions Adds flags to the compiler command line for sources in the current directory and below.

这篇关于使用CMake忽略/仅显示某些目录中的错误/警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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