问题描述
主要问题:是否有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)添加它
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文档:
这篇关于使用CMake忽略/仅显示某些目录中的错误/警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!