使用CMake时忽略外部模块中的警告

时间:2017-01-17 11:30:11

标签: cmake suppress-warnings cmake-gui

我正在使用CMake GUI(无版本)CMake 3.6.1。我正在使用一个带有add_subdirectory的外部模块,它向我展示了一些我不喜欢的警告(因为烦人的污染):

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),那么cmake_policy就可以了。

我尝试使用cmake_policy(PUSH) cmake_policy(SET CMP0054 OLD) add_subdirectory(${g3log_DIR} ${CMAKE_BINARY_DIR}/../g3log) cmake_policy(POP) ,但没有效果:

import some_module

class Number:

    a = 2

Number.a = some_module.Var.b
print("some_module.Var.b =", some_module.Var.b)
print("Number.a =", Number.a)

1 个答案:

答案 0 :(得分:2)

将我的评论转化为答案

听起来你的外部模块确实有<tr ng-repeat="name in names | myFilter: datas"> <td>{{ name.name }}</td> <td>{{ name.down }}</td> </tr> 命令。这将重置此子模块及以下的策略。

为了演示可能的解决方案,假设您有一个外部项目如下:

<强> g3log /的CMakeLists.txt

project()

您现在可以将CMAKE_POLICY_DEFAULT_CMP0054设置为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() (甚至更好地设置为OLD;没有人真的希望&#34; OLD&#34;行为)摆脱&# 34;政策CMP0054未设置&#34;你会得到更新版本的CMake警告:

<强>的CMakeLists.txt

NEW

现在,如果您的项目或正在使用的某个外部项目中没有明确指定,则您已设置了策略CMP0054的默认值。