如何在 CMake 中设置警告级别? [英] How to set warning level in CMake?

查看:29
本文介绍了如何在 CMake 中设置警告级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 CMake项目(不是整个解决方案)设置警告级别?应该适用于 Visual StudioGCC.

How to set the warning level for a project (not the whole solution) using CMake? Should work on Visual Studio and GCC.

我找到了各种选项,但大多数似乎要么不起作用,要么与文档不一致.

I found various options but most seem either not to work or are not consistent with the documentation.

推荐答案

这是我目前找到的最佳解决方案(包括编译器检查):

Here is the best solution I found so far (including a compiler check):

if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
    add_definitions(/W2)
endif()

GCC 等效项是 -Wall(未经测试).

The GCC equivalent is -Wall (untested).

这篇关于如何在 CMake 中设置警告级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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