gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:36:31 37 4
gpt4 key购买 nike

我正在使用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)

最佳答案

将我的评论转化为答案

听起来您的外部模块确实有一个 project() 命令。这将重置此子模块及以下子模块的策略。

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

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_CMP0054OLD(或者甚至更好地NEW;没有人真正想要“OLD”行为),以消除您将在较新版本中收到的“Policy CMP0054 is not set”警告CMake 版本:

CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(PolicyOverwrite NONE)

set(CMAKE_POLICY_DEFAULT_CMP0054 NEW)
add_subdirectory(g3log)

现在您已设置策略的默认值 CMP0054如果您的项目或您正在使用的外部项目之一没有明确给出,则使用。

关于cmake - 使用 CMake 时忽略外部模块中的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695993/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com