使用 CMake 避免来自系统库/包含的警告

问题描述

我有大量代码库并使用 CMake 3.19.3 构建编译环境。我一直在 GCC (9.3)CLang (11)ICC (19.1) 中编译代码。但是,要使 ICC 工作,我需要从强制性检查中删除很多警告。我的 CMake 配置文件如下所示:

if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
    list(APPEND CMAKE_CXX_FLAGS "-no-ansi-alias")
    list(APPEND CMAKE_CXX_FLAGS "-Wno-error=missing-prototypes")
    list(APPEND CMAKE_CXX_FLAGS "-wd68")   # integer conversion resulted in a change of sign
    list(APPEND CMAKE_CXX_FLAGS "-wd111")  # statement is unreachable
    list(APPEND CMAKE_CXX_FLAGS "-wd186")  # pointless comparison of unsigned integer with zero
    list(APPEND CMAKE_CXX_FLAGS "-wd593")  # variable was set but never used
    list(APPEND CMAKE_CXX_FLAGS "-wd654")  # overloaded virtual function is only partially overridden in class
    list(APPEND CMAKE_CXX_FLAGS "-wd1476") # field uses tail padding of a base class
    list(APPEND CMAKE_CXX_FLAGS "-wd1505") # size of class is affected by tail padding
    list(APPEND CMAKE_CXX_FLAGS "-wd1572") # floating-point equality and inequality comparisons are unreliable
    list(APPEND CMAKE_CXX_FLAGS "-wd2196") # routine is both "inline" and "noinline"
    list(APPEND CMAKE_CXX_FLAGS "-wd2415") # variable "xxx" of static storage duration was declared but never referenced
    list(APPEND CMAKE_CXX_FLAGS "-wd2338") # this switch statement does not have a default clause
    list(APPEND CMAKE_CXX_FLAGS "-wd3884") # missing initializer for field
endif()

(如果您想知道,this 是我将内容附加到 CMAKE_CXX_FLAGS 而不是使用 add_compile_options() 的原因)

我需要这样做,否则,我的代码会因为 C++ 库中的警告而失败,包括(我还打开了 "-pedantic-errors""-Wall""-Werror" 和 {{1 }}).

例如,在 "-Wfatal-errors" 中,使用 CentOS 7 作为 ICC 的基本编译器,如果我在上面的示例中启用警告禁用,则这是输出:

gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)

我已经将外部库的所有显式包含标记为 -- Found ccache -- The C compiler identification is Intel 19.1.0.20200306 -- The CXX compiler identification is Intel 19.1.0.20200306 ... ... ... [ 40%] Building CXX object Utils/src/CMakeFiles/utils_objects.dir/boolean_utils.cpp.o icc: warning #10193: -vec is default; use -x and -ax to configure vectorization remark #11074: Inlining inhibited by limit max-size remark #11074: Inlining inhibited by limit max-total-size remark #11076: To get full report use -qopt-report=4 -qopt-report-phase ipo /opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h(5163) (col. 16): error #2102: violation of ansi-alias rules 以避免抛出此类警告,例如:

SYSTEM

但我不知道/没有找到任何有关如何直接从 CMake 为 C++ 系统库本身(如我的示例中的 include_directories(SYSTEM ${Python3_INCLUDE_DIRS}) )执行此操作的相关信息,而无需明显手动修改生成的 Makefile。我找到了 this article,但它与我已经在做的事情有关。我也找到了this possible solution,但也发现连CMake的discourages such solution

basic_string.h

MWE 应该是这样的:

"It is also probably a good idea to avoid passing -I/-isystem for directories that the compiler already assumes as default include directories. It keeps thinga cleaner and simple."
test.cpp

编译:

#include <iostream>
#include <string>

int main()
{
        std::string a("Text");

        std::cout << a.c_str() << std::endl;

        return 0;
}

返回:

icc -o OUT -pedantic-errors -fmax-errors=1 -march=native -Wall -Werror -Wfatal-errors -Wextra -ftree-vectorize -g -Wl,--exclude-libs,ALL -O3 -DNDEBUG -fPIC -fvisibility=hidden -Wstrict-aliasing -std=gnu++17 main.cpp

有什么建议吗?非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...