Skip to content

CMakeDetermineCompilerABI: Avoid failing on warnings with -Werror

David Rohr requested to merge davidrohr/cmake:PR into master

Simply remove -Werror flags from CMAKE_<LANG>_FLAGS to avoid failing ABI detection if there happen to be warnings in the test project. For example, -Wunused-command-line-argument warnings are common since the ABI detection project may not exercise all the flags passed by users.

Original Description

Fix DetermineCompiler API failing with -Werror set

This is a follow-up to #19845 (closed). I am opening a new merge request, since the cause here is a different one (even though the symptoms are the same). For the original issue, there is an independent merge request !4315 (merged) , but this merge request fixes an independent problem that leads to the same symptom.

Here is a description of what goes wrong and the symptoms we are observing:

  1. 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.
  2. CMake would actually remove this path again, but to do so, it invokes the compiler, to find the compiler settings in Modules/CMakeDetermineCompilerABI.cmake
  3. 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 we need both fixes.

What this merge request does, is just add a -Wno-error to the DetermineCompilerABI call. I think it is actually not a clean solution. It would be better to filter any -Werror arguments from the command, but I could not figure out how to do so. So in case you have a cleaner solution, please update this PR (it's editable by maintainers), or let me know how to do it and I will update it.

Fixes: #20305 (closed)
Topic-rename: compiler-abi-no-Werror

Edited by Brad King

Merge request reports