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

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

问题描述

如何使用 CMake 项目(而不是整个解决方案)设置警告级别?应该在 Visual Studio GCC 上工作。

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

我发现了很多选项,

推荐答案

这里是我发现的最好的解决方案(包括编译器检查):

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

这将在Visual Studio中设置警告级别2。我想用 -W2 它将在GCC工作(未测试)。

This will set warning level 2 in Visual Studio. I suppose with a -W2 it would work in GCC too (untested).

从@Williams更新应为 -Wall 用于GCC。

Update from @Williams: It should be -Wall for GCC.

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

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