0

I have a large base of code and use CMake 3.19.3 to build the compile environment. I keep the code compiling in GCC (9.3), CLang (11), and ICC (19.1). However, for ICC to work I need to remove a lot of warnings from the mandatory checks. My CMake config file looks like this:

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()

(In case you wonder, this is the reason why I append things to CMAKE_CXX_FLAGS instead of using add_compile_options())

I need to do so, otherwise, my code fails because of warnings in the C++ library includes (I've also turned on "-pedantic-errors", "-Wall", "-Werror" and "-Wfatal-errors").

For example, in CentOS 7, using gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3) as the base compiler for ICC, this is the output if I enable the warnings disable in the sample above:

-- 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

I've already marked as SYSTEM all the explicit includes to external libraries to avoid this kind of warnings being thrown, for example:

include_directories(SYSTEM ${Python3_INCLUDE_DIRS})

But I have no idea/haven't found anything related on how to do that directly from CMake for the C++ system libraries themselves (like basic_string.h in my sample), without obviously modifying the generated Makefiles by hand. I found this article, but it's related to what I already do. I also found this possible solution, but also found that even CMake discourages such solution:

"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."

A MWE would be this:

test.cpp
#include <iostream>
#include <string>

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

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

        return 0;
}

Compile with:

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

returns:

icc: warning #10193: -vec is default; use -x and -ax to configure vectorization
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/basic_string.h(5052) (col. 50): error #2102: violation of ansi-alias rules

compilation aborted for main.cpp (code 4)

Any suggestions? Thanks a lot.

  • The code you show is definitely **incomplete** one, so it is difficult to understand what are you actually have and what you actually doing. Please, prepare [mcve]. Also, `SYSTEM` in CMake is not a "magic" tool: it passes adds include directory to the compiler with a special flag, like `-isystem`. So you may inspect your command line (with make `VERBOSE=1`) and check, whether `-isystem` option is actually used. – Tsyvarev Jan 19 '21 at 18:32
  • Note also, that using `-isystem` for standard compiler include directory could cause errors (see e.g [that question](https://stackoverflow.com/questions/37218953/isystem-on-a-system-include-directory-causes-errors)). As far as I aware, for that reason CMake ignores specification of the include directory which is actually the standard one for the compiler. If you are sure that such specification doesn't harm your compiler, you may append `-isystem <...>` option directly to `CMAKE_CXX_FLAGS`. – Tsyvarev Jan 19 '21 at 18:42
  • I've added the MWE to the original post (not sure if editing it is the proper way to do it, hope it is). – Alvaro Palma Aste Jan 20 '21 at 16:07
  • In your MWE you forgot the content of `CMakeLists.txt`. – Tsyvarev Jan 20 '21 at 16:33
  • I guess I missexpressed my issue. My doubt is if it's possible to add some flag in CMake that generates Makefiles (equivalents to the compilation command I created by hand in the MWE) which won't emit a warning on the C++ system library include files, as it happens in the MWE. Or equivalently (I can do the "reverse search"), which flag will make ICC to avoid emitting the warning being shown in the MWE. By reverse search I mean that, if such flag exists, I can look up for the CMake command that generates it. Hope it clarifies the question. – Alvaro Palma Aste Jan 20 '21 at 18:55
  • So, firstly you look for the parameter for **command line**, not for CMake? In most cases, for obtain some parameter for the command line, you need to specify the **same** parameter in `CMakeLists.txt`. Have you tried parameter `-isystem=/opt/rh/devtoolset-8/root/usr/include/c++/8`, as I suggested above? – Tsyvarev Jan 20 '21 at 19:05
  • Yes, same result. – Alvaro Palma Aste Jan 20 '21 at 19:10
  • As a direct parameter to command line doesn't help, then CMake is unlikely able to help too. – Tsyvarev Jan 20 '21 at 19:16
  • I guess I'll rephrase my question and repost it without the reference to CMake. Many thanks for your suggestions. – Alvaro Palma Aste Jan 20 '21 at 21:26

0 Answers0