We can check support for specific compiler flags in autoconf using:
AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
These checks are returning true but clang doesn't support them.
AX_CHECK_COMPILE_FLAG([-Woverride-init])
AX_CHECK_COMPILE_FLAG([-Wformat-truncation])
How to check support compile flag in autoconf for clang?
I change my compiler by
export CC=/usr/bin/clang-6.0
export CXX=/usr/bin/clang++-6.0
and if echo into script $CC and $CXX, all is ok.
link to configure.ac
If you use clang -Wsome-invalid-option -xc /dev/null, you'll see that clang emits a warning about an unknown option -Wsome-invalid-option. The docs for AX_CHECK_COMPILE_FLAG state that warnings are ignored.
You need to use argument 4 of the macro to include -Werror:
AX_CHECK_COMPILE_FLAG([-Woverride-init], , , [-Werror])
This check also generates a cache variable, in case you need to override it:
ax_cv_cflags__Werror__Woverride_init
If it's set to yes, then the compiler supports the flag, else it does not support the flag. You can use this for other flags as well:
AX_CHECK_COMPILE_FLAG([-Wformat-truncation], , , [-Werror])
AS_VAR_IF([ax_cv_cflags__Werror__Wformat_truncation], [yes],
,
[AC_FATAL([-Wformat-truncation not supported])])
The generic form is ax_cv_cflags_{EXTRA}_{FLAG} for C. Obviously if you're going to use AS_VAR_IF to check the cache variable, however, you may as well use the second and/or third macro arguments as well, and you can use AC_FATAL if the compilation flag is required:
AX_CHECK_COMPILE_FLAG([-Wformat-truncation],
,
[AC_FATAL([-Wformat-truncation is required])],
[-Werror])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With