c++ - 在 CMake 中抑制来自外部库的编译器警告
问题描述
我正在尝试按照下面复制的 CMake 说明将以下项目https://github.com/whoshuu/cpr#cmake构建到我的项目中:
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/whoshuu/cpr.git GIT_TAG c8d33915dbd88ad6c92b258869b03aba06587ff9) # the commit hash for 1.5.0
FetchContent_MakeAvailable(cpr)
我的项目已经有一些与主要目标链接的其他库,所以我包含了这个新库,如下所示:
target_link_libraries(my_target PRIVATE cpr::cpr PUBLIC other_libraries)
这样做的问题是构建cpr
库的警告阻止了项目的构建。我想压制这些警告。我已尝试SYSTEM
按照此处的建议添加关键字:How to suppress GCC warnings from library headers? 所以代码如下所示:
target_link_libraries(my_target PRIVATE SYSTEM cpr::cpr PUBLIC other_libraries)
但这没有帮助。是否有其他方法可以抑制 CMake 中外部库的警告?如果有帮助,我正在使用C++-17
g++-11
和忍者。
解决方案
我知道这在技术上并不能回答您的问题,但是,作为新手,我无法发表评论。
我能找到的唯一方法是在代码中使用编译器编译指示禁用警告:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weverything"
#include <cpr/cpr.h>
#pragma GCC diagnostic pop
这取决于编译器。如果您使用 clang,只需将“GCC”替换为“clang”即可。在 Visual Studio 上,使用 pragma 警告...这可以通过宏进行移植,看看这篇文章。
推荐阅读
- vb.net - 如何从只有选定列的 Access 数据库中填充我的 DataGridView?
- c++ - 错误:sigjmp_buf 没有命名类型。使用 Poco C++ 库编译我的项目时
- python - 优化模型
- keras - 如何在 KERAS API 模型中为多个输入制作数据生成器(用于非图像数据)?
- python - Tkinter 滚动条——Python 3
- c# - 将数据集转换为嵌套的 xml???帮帮我
- r - R中字符串到日期转换的“标准明确日期”错误
- javascript - 如何根据php中下拉框的选择来检索n个文本框上的数据
- java - 图像不局限于直接区域
- css - Material Angular - 按钮样式未呈现