We use autotools as our build infrastructure, and we use clang and gcc as compilers. Recently we hit a gcc warning that needed
--param max-vartrack-size=100000000
to silence (without completey disabling gcc's vartracking). Clang doesn't accept that option and produces
argument unused during compilation: '--param max-vartrack-size=100000000'
To silence that, clang needs
-Qunused-arguments
and that produces an error under gcc:
unrecognized command line option ‘-Qunused-arguments’
What is the best way to define compiler-specific flags in
configure.ac
, after a compiler has been selected with, e.g.AC_PROG_CXX
? WeAC_SUBST(AM_CXXFLAGS)
so I guess I'd be expanding a compiler specific variable withinAM_CXXFLAGS
.What is the right way to enable a per-target option in a
Makefile.am
for just one compiler? I'm thinking of:if HAVE_GCC SPECIFIC_CXXFLAGS = --param... endif if HAVE_CLANG SPECIFIC_CXXFLAGS = -Q... endif libfoo_la_CXXFLAGS = $(AM_CXXFLAGS) $(SPECIFIC_CXXFLAGS)
but I'd need the HAVE_*
vars subst'ed from configure.ac. Do AC_PROG_CXX/CC
perhaps already define something like this?
AM_CXXFLAGS
isn't something you shouldAC_SUBST
. It is reserved for use by automake. If you look at theMakefile
generated for a C++ target, you will find definitions forCXXCOMPILE
andLTCXXCOMPILE
, which always include theAM_CXXFLAGS
variable.You want to add the (conditional) compiler flag to
AM_CXXFLAGS
or tolibfoo_la_CXXFLAGS
. The former will affect all C++ compilations, and the latter just the per-library compilations. So it's just a matter of gettingSPECIFIC_CXXFLAGS
right inconfigure.ac
.The
GXX
test is insufficient as autoconf just tests for the__GNUC__
macro (AFAIK), so clang++ will set:GXX=yes
The problem is, there isn't a portable way of detecting command line options that are unknown. Intel's
icc -v
will even reproduce thegcc version
string. So you might have to add another filter, like:| grep -v 'icc'
You could optionally check that the flag works as advertised before
AC_SUBST
, but this doesn't really help if the compiler only generates a warning:Then in
Makefile.am
:or: