CMake - 忽略/只显示来自某个目录的错误/警告 [英] CMake - ignore/only show errors/warnings from certain directory

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

问题描述

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



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



背景/动机
工作在一个更大的CMake项目,并希望专注于警告和错误只有从我的子项目。我正在使用QtCreator,它让我在一堆外来的错误/警告下寻找我的错误/警告。

解决方案

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

 #目标
set_target_properties(your_project_name PROPERTIES COMPILE_FLAGS...)

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

pre>

也可以通过将项目分为子项目来设置每个文件夹的选项,使用 add_subdirectory(your_project)并在您的项目CMakeLists.txt中使用 add_definitions(...)



来自CMake文件:


add_definitions 在当前目录及以下目录的源代码的编译器命令行中添加标志。



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

alternative solution: How can I toggle this in 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.

解决方案

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 "..."
)

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(...).

From CMake documentation:

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

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

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