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.amfor 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_CXXFLAGSisn't something you shouldAC_SUBST. It is reserved for use by automake. If you look at theMakefilegenerated for a C++ target, you will find definitions forCXXCOMPILEandLTCXXCOMPILE, which always include theAM_CXXFLAGSvariable.You want to add the (conditional) compiler flag to
AM_CXXFLAGSor 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_CXXFLAGSright inconfigure.ac.The
GXXtest is insufficient as autoconf just tests for the__GNUC__macro (AFAIK), so clang++ will set:GXX=yesThe problem is, there isn't a portable way of detecting command line options that are unknown. Intel's
icc -vwill even reproduce thegcc versionstring. 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: