zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.53k stars 2.34k forks source link

build (cmake): `LIBZMQ_WERROR` is broken #4700

Open fanquake opened 3 weeks ago

fanquake commented 3 weeks ago

Issue description

Usage of LIBZMQ_WERROR is mostly broken, because the build system is throwing other warnings when usage of the flag is being tested. i.e when building using GCC 14.1.1:

/usr/lib64/ccache/c++   -std=c++11 -Wno-tautological-constant-compare    -DHAVE_FLAG_-Werror -Werror -o CMakeFiles/cmTC_bc312.dir/src.cxx.o -c /root/libzmq/build/CMakeFiles/CMakeScratch/TryCompile-QS6bbk/src.cxx
<command-line>: error: ISO C++11 requires whitespace after the macro name [-Werror]
cc1plus: note: unrecognized command-line option '-Wno-tautological-constant-compare' may have been intended to silence earlier diagnostics
cc1plus: all warnings being treated as errors

The same happens under Clang 18.1.7:

/usr/lib64/ccache/clang++   -std=c++11 -Wno-tautological-constant-compare -Wall -Wextra -Wno-long-long -Wno-uninitialized -pedantic    -DHAVE_FLAG_-Werror -Werror -MD -MT CMakeFiles/cmTC_90abf.dir/src.cxx.o -MF CMakeFiles/cmTC_90abf.dir/src.cxx.o.d -o CMakeFiles/cmTC_90abf.dir/src.cxx.o -c /root/libzmq/build/CMakeFiles/CMakeScratch/TryCompile-N1gFrx/src.cxx
        In file included from <built-in>:430:
<command line>:1:19: error: ISO C99 requires whitespace after the macro name [-Werror,-Wc99-extensions]
            1 | #define HAVE_FLAG_-Werror 1
              |                   ^
1 error generated.

The -Werror test converts this warning (ISO C++11 requires whitespace after the macro name) into an error, and -Werror is never added as a build flag. Note that this likely effects a number of other options/checks as well.

Environment

Minimal test code / Steps to reproduce the issue

  1. cmake -B build

What's the actual result? (include assertion message & call stack if applicable)

-- Performing Test HAVE_FLAG_-Werror
-- Performing Test HAVE_FLAG_-Werror - Failed

What's the expected result?

-- Performing Test HAVE_FLAG_-Werror
-- Performing Test HAVE_FLAG_-Werror - Success