使用CMake时忽略外部模块中的警告 [英] Ignore warnings in external modules when using CMake

查看:1086
本文介绍了使用CMake时忽略外部模块中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CMake 3.6.1中使用 CMake GUI (无版本)。我正在使用带有 add_subdirectory 的外部模块,该模块向我显示一些我不喜欢的警告(由于令人讨厌的污染):

I am using CMake GUI (no version) with CMake 3.6.1. I am using an external module with add_subdirectory that shows me some warnings that I do not like (because of the annoying pollution):

CMake Warning (dev) at D:/Sources/.../external/g3log/latest/Build.cmake:11 (IF):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  D:/Sources/.../external/g3log/latest/CMakeLists.txt:72 (INCLUDE)
This warning is for project developers.  Use -Wno-dev to suppress it.

我想隐藏这些警告而不触摸外部文件。如果 -Wno-dev 只影响外部模块( g3log ),就可以了。

I want to hide these warnings without touching the external files. -Wno-dev would be ok if it will affect only the external module (g3log).

我尝试使用 cmake_policy 像下面这样没有效果:

I tried using cmake_policy like following with no effect:

cmake_policy(PUSH)
cmake_policy(SET CMP0054 OLD)
add_subdirectory(${g3log_DIR} ${CMAKE_BINARY_DIR}/../g3log)
cmake_policy(POP)


推荐答案

将我的评论变成答案

这听起来像您的外部模块确实具有 project()命令。

That sounds like your external module does have a project() command. This resets the policies for this sub-module and below.

为演示可能的解决方案,可以说您有一个外部项目,如下所示:

To demonstrate a possible solution, lets say you have a external project as the following:

g3log / CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(g3log NONE)

set(VAR1 "Hello World")
set(VAR2 "VAR1")
if ("${VAR2}" STREQUAL "${VAR1}")
    message("CMP0054 old behavior")
endif()

您现在可以设置 CMAKE_POLICY_DEFAULT_CMP0054 更改为 OLD (甚至更好的是 NEW ;没有人真正想要 OLD行为)以摆脱使用较新版本的CMake的未设置策略CMP0054警告:

You can now set CMAKE_POLICY_DEFAULT_CMP0054 to OLD (or even better to NEW; nobody really wanted the "OLD" behavior) to get rid of the "Policy CMP0054 is not set" warnings you will get with newer versions of CMake:

CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(PolicyOverwrite NONE)

set(CMAKE_POLICY_DEFAULT_CMP0054 NEW)
add_subdirectory(g3log)

现在,您已将策略 CMP0054 设置为默认值如果您的项目或正在使用的外部项目之一未明确给出任何内容,则使用此方法。

Now you have set a default for policy CMP0054 to be used if none is explicitly given in your project or one of the external projects you are using.

这篇关于使用CMake时忽略外部模块中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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