Compile flag -Werror breaks compiler ABI detection since CMake 3.15
This is a follow-up to #19845 (closed) and !4316 (merged). I am opening a new issue, since the cause here is a different one (even though the symptoms are the same). (For #19845 (closed), there is an independent merge request !4315 (merged) , but this merge request fixes an independent problem that by chance leads to the same symptoms.) Here is a description of what goes wrong and the symptoms we are observing:
- A package like in find_package(zlib) finds the zlib.h header the system folder, and adds
.../MacOSX10.15.sdk/usr/include
as system include path on MacOS. - CMake would actually remove this path again, but to do so, it invokes the compiler, to find the compiler settings in
Modules/CMakeDetermineCompilerABI.cmake
- If the -Werror compiler flag is set, this is forwarded to the compiler test-invocation, and since this test invocation produces warnings, the compiler bails out. Consequently, the correct
.../MacOSX10.15.sdk/usr/include
path is not detected, hence the zlib include path is not removed, and the compilation fails because of the additional include path.
The symptom described above is actually also fixed by !4315 (merged), which removes the bogus include path, but the ROOT cause that the DetermineCompilerABI call fails, remains also with !4315 (merged). Therefore I think a second fix is needed.
See !4316 (merged) for a quick workaround, which works for GCC / clang compilers, but just enforcing an additional -Wno-error
flag, which overrides any previous -Werror
and thus makes the ABI detection succeed. Obviously this breaks for compilers that do not understand the -Wno-error
syntax.
A better fix is needed, which either disables warnings on the CMake level, or checks the compiler flags for -Werror
and removes it.
Just for reference, the offending commit which introduced this problem is c765ae49, which changes the forwarding of the compiler flags somehow. I have to admit that I don't fully understand how, and I am also no CMake expert, so I feel unable to provide a proper fix.
Therefore I am opening this issue for discussion how to proceed.