testing/install removes -Werror blindly, leaving any arguments hanging (test fails)
The configuration file for testing/install removes -Werror (and -Wall) blindly from CFLAGS (CXXFLAGS),
https://github.com/ornladios/ADIOS2/blob/06c8feccb7589aa7d61655e4aa8d01a52c3b2507/testing/install/CMakeLists.txt#L85
# Remove -Wall -Werror in this scope
if(CMAKE_C_FLAGS)
string(REPLACE "-Wall" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-Werror" " " CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif()
if(CMAKE_CXX_FLAGS)
string(REPLACE "-Wall" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-Werror" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
The problem is that these flags may have arguments (values). Since the replacement is simple, any such value is left hanging.
For instance debian packages are built with standard CFLAGS intended to improve security (build hardening), determined by dpkg-buildflags, for instance
CFLAGS=-g -O2 -ffile-prefix-map=/home/drew=. -fstack-protector-strong -Wformat -Werror=format-security
In cmake builds this is passed to CMAKE_C_FLAGS (and CMAKE_CXX_FLAGS etc). So adios2 gets built with -Werror=format-security. Then, once testing/install/CMakeLists.txt has had its way, the compilation line gets rendered with c++ -Wformat =format-security, which obviously fails. The error message is
cc: warning: =format-security: linker input file unused because linking not done
cc: error: =format-security: linker input file not found: No such file or directory
from trying to interpret =format-security on its own as a valid linker flag.
There are a handful of options for fixing it, depending on what the intention for removing -Werror was in the first place.
If it's just -Werror itself, add a tailing space "-Werror " (and likewise "-Wall "). If any -Werror is meant to be removed then use a wildcard "-Werror*" (or .*, whatever the wildcard syntax needs to be in this context)
A more robust solution might be to parse the flags individually, e.g. using add_definitions and remove_definitions.
Another option is to append -Wno-error rather than removing -Werror (likewise -Wno-all)
To Reproduce
- export CMAKE_CXX_FLAGS="-Werror=format-security"
- cmake configure, build
- ctest
- See error
Expected behavior tests should pass. The names of CFLAGS should not be removed leaving their values hanging in place.
Desktop (please complete the following information):
- OS/Platform: Debian unstable (linux)
- Build gcc 13.2.0, cmake 3.27.2, shared library build
@drew-parsons many thanks for reporting this. This indeed has been a nightmare which has probably caused issues with the generation of the adios2-config script needed for non-cmake applications to find adios2 includes and libraries.
Another option is to append -Wno-error rather than removing -Werror (likewise -Wno-all)
I think this is the best at this stage