Add C++ support to configure.
This is an optional dependency. It'll be used for the upcoming LLVM based just in time compilation support, which needs to wrap a few LLVM C++ APIs so they're accessible from C.. For now test for C++ compilers unconditionally, without failing if not present, to ensure wide buildfarm coverage. If we're bothered by the additional test times (which are quite short) or verbosity, we can later make the tests conditional on --with-llvm. Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
This commit is contained in:
parent
a364dfa4ac
commit
6869b4f258
6 changed files with 1012 additions and 10 deletions
|
@ -477,6 +477,46 @@ AC_DEFUN([PGAC_PROG_CC_VAR_OPT],
|
|||
|
||||
|
||||
|
||||
# PGAC_PROG_VARCXX_VARFLAGS_OPT
|
||||
# -----------------------
|
||||
# Given a compiler, variable name and a string, check if the compiler
|
||||
# supports the string as a command-line option. If it does, add the
|
||||
# string to the given variable.
|
||||
AC_DEFUN([PGAC_PROG_VARCXX_VARFLAGS_OPT],
|
||||
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_prog_$1_cxxflags_$3])])dnl
|
||||
AC_CACHE_CHECK([whether ${$1} supports $3, for $2], [Ac_cachevar],
|
||||
[pgac_save_CXXFLAGS=$CXXFLAGS
|
||||
pgac_save_CXX=$CXX
|
||||
CXX=${$1}
|
||||
CXXFLAGS="${$2} $3"
|
||||
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
|
||||
ac_cxx_werror_flag=yes
|
||||
AC_LANG_PUSH(C++)
|
||||
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
[Ac_cachevar=yes],
|
||||
[Ac_cachevar=no])
|
||||
AC_LANG_POP([])
|
||||
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
|
||||
CXXFLAGS="$pgac_save_CXXFLAGS"
|
||||
CXX="$pgac_save_CXX"])
|
||||
if test x"$Ac_cachevar" = x"yes"; then
|
||||
$2="${$2} $3"
|
||||
fi
|
||||
undefine([Ac_cachevar])dnl
|
||||
])# PGAC_PROG_VARCXX_VARFLAGS_OPT
|
||||
|
||||
|
||||
|
||||
# PGAC_PROG_CXX_CFLAGS_OPT
|
||||
# -----------------------
|
||||
# Given a string, check if the compiler supports the string as a
|
||||
# command-line option. If it does, add the string to CXXFLAGS.
|
||||
AC_DEFUN([PGAC_PROG_CXX_CFLAGS_OPT],
|
||||
[PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS, $1)
|
||||
])# PGAC_PROG_CXX_VAR_OPT
|
||||
|
||||
|
||||
|
||||
# PGAC_PROG_CC_LDFLAGS_OPT
|
||||
# ------------------------
|
||||
# Given a string, check if the compiler supports the string as a
|
||||
|
|
50
configure.in
50
configure.in
|
@ -353,11 +353,12 @@ AC_DEFINE_UNQUOTED([XLOG_BLCKSZ], ${XLOG_BLCKSZ}, [
|
|||
PGAC_ARG_REQ(with, CC, [CMD], [set compiler (deprecated)], [CC=$with_CC])
|
||||
|
||||
case $template in
|
||||
aix) pgac_cc_list="gcc xlc";;
|
||||
*) pgac_cc_list="gcc cc";;
|
||||
aix) pgac_cc_list="gcc xlc"; pgac_cxx_list="g++ xlC";;
|
||||
*) pgac_cc_list="gcc cc"; pgac_cxx_list="g++ c++";;
|
||||
esac
|
||||
|
||||
AC_PROG_CC([$pgac_cc_list])
|
||||
AC_PROG_CXX([$pgac_cxx_list])
|
||||
|
||||
# Check if it's Intel's compiler, which (usually) pretends to be gcc,
|
||||
# but has idiosyncrasies of its own. We assume icc will define
|
||||
|
@ -381,7 +382,7 @@ unset CFLAGS
|
|||
#
|
||||
. "$srcdir/src/template/$template" || exit
|
||||
|
||||
# CFLAGS are selected so:
|
||||
# C[XX]FLAGS are selected so:
|
||||
# If the user specifies something in the environment, that is used.
|
||||
# else: If the template file set something, that is used.
|
||||
# else: If coverage was enabled, don't set anything.
|
||||
|
@ -403,9 +404,26 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
# CFLAGS we determined above will be added back at the end
|
||||
if test "$ac_env_CXXFLAGS_set" = set; then
|
||||
CXXFLAGS=$ac_env_CXXFLAGS_value
|
||||
elif test "${CXXFLAGS+set}" = set; then
|
||||
: # (keep what template set)
|
||||
elif test "$enable_coverage" = yes; then
|
||||
: # no optimization by default
|
||||
elif test "$GCC" = yes; then
|
||||
CXXFLAGS="-O2"
|
||||
else
|
||||
# if the user selected debug mode, don't use -O
|
||||
if test "$enable_debug" != yes; then
|
||||
CXXFLAGS="-O"
|
||||
fi
|
||||
fi
|
||||
|
||||
# C[XX]FLAGS we determined above will be added back at the end
|
||||
user_CFLAGS=$CFLAGS
|
||||
CFLAGS=""
|
||||
user_CXXFLAGS=$CXXFLAGS
|
||||
CXXFLAGS=""
|
||||
|
||||
# set CFLAGS_VECTOR from the environment, if available
|
||||
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
|
||||
|
@ -419,18 +437,26 @@ fi
|
|||
|
||||
if test "$GCC" = yes -a "$ICC" = no; then
|
||||
CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith"
|
||||
CXXFLAGS="-Wall -Wpointer-arith"
|
||||
# These work in some but not all gcc versions
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-Wdeclaration-after-statement])
|
||||
# -Wdeclaration-after-statement isn't applicable for C++
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-Wendif-labels])
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-format-attribute])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-format-attribute])
|
||||
# This was included in -Wall/-Wformat in older GCC versions
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security])
|
||||
# Disable strict-aliasing rules; needed for gcc 3.3+
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])
|
||||
# Disable optimizations that assume no overflow; needed for gcc 4.3+
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-fwrapv])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-fwrapv])
|
||||
# Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-fexcess-precision=standard])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-fexcess-precision=standard])
|
||||
# Optimization flags for specific files that benefit from vectorization
|
||||
PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-funroll-loops])
|
||||
PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTOR, [-ftree-vectorize])
|
||||
|
@ -445,16 +471,21 @@ elif test "$ICC" = yes; then
|
|||
# Intel's compiler has a bug/misoptimization in checking for
|
||||
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-mp1])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-mp1])
|
||||
# Make sure strict aliasing is off (though this is said to be the default)
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])
|
||||
elif test "$PORTNAME" = "aix"; then
|
||||
# AIX's xlc has to have strict aliasing turned off too
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-qnoansialias])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-qnoansialias])
|
||||
PGAC_PROG_CC_CFLAGS_OPT([-qlonglong])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([-qlonglong])
|
||||
elif test "$PORTNAME" = "hpux"; then
|
||||
# On some versions of HP-UX, libm functions do not set errno by default.
|
||||
# Fix that by using +Olibmerrno if the compiler recognizes it.
|
||||
PGAC_PROG_CC_CFLAGS_OPT([+Olibmerrno])
|
||||
PGAC_PROG_CXX_CFLAGS_OPT([+Olibmerrno])
|
||||
fi
|
||||
|
||||
AC_SUBST(CFLAGS_VECTOR, $CFLAGS_VECTOR)
|
||||
|
@ -464,10 +495,15 @@ if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
|
|||
CFLAGS="$CFLAGS -g"
|
||||
fi
|
||||
|
||||
if test "$enable_debug" = yes && test "$ac_cv_prog_cxx_g" = yes; then
|
||||
CXXFLAGS="$CXXFLAGS -g"
|
||||
fi
|
||||
|
||||
# enable code coverage if --enable-coverage
|
||||
if test "$enable_coverage" = yes; then
|
||||
if test "$GCC" = yes; then
|
||||
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
|
||||
CXXFLAGS="$CXXFLAGS -fprofile-arcs -ftest-coverage"
|
||||
else
|
||||
AC_MSG_ERROR([--enable-coverage is supported only when using GCC])
|
||||
fi
|
||||
|
@ -479,6 +515,7 @@ if test "$enable_profiling" = yes && test "$ac_cv_prog_cc_g" = yes; then
|
|||
AC_DEFINE([PROFILE_PID_DIR], 1,
|
||||
[Define to 1 to allow profiling output to be saved separately for each process.])
|
||||
CFLAGS="$CFLAGS -pg $PLATFORM_PROFILE_FLAGS"
|
||||
CXXFLAGS="$CXXFLAGS -pg $PLATFORM_PROFILE_FLAGS"
|
||||
else
|
||||
AC_MSG_ERROR([--enable-profiling is supported only when using GCC])
|
||||
fi
|
||||
|
@ -489,12 +526,14 @@ if test "$PORTNAME" = "win32"; then
|
|||
CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
|
||||
fi
|
||||
|
||||
# Now that we're done automatically adding stuff to CFLAGS, put back the
|
||||
# Now that we're done automatically adding stuff to C[XX]FLAGS, put back the
|
||||
# user-specified flags (if any) at the end. This lets users override
|
||||
# the automatic additions.
|
||||
CFLAGS="$CFLAGS $user_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $user_CXXFLAGS"
|
||||
|
||||
# Check if the compiler still works with the final flag settings
|
||||
# (note, we're not checking that for CXX, which is optional)
|
||||
AC_MSG_CHECKING([whether the C compiler still works])
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
|
||||
[AC_MSG_RESULT(yes)],
|
||||
|
@ -2207,6 +2246,7 @@ AC_SUBST(PG_VERSION_NUM)
|
|||
|
||||
AC_MSG_NOTICE([using compiler=$cc_string])
|
||||
AC_MSG_NOTICE([using CFLAGS=$CFLAGS])
|
||||
AC_MSG_NOTICE([using CXXFLAGS=$CXXFLAGS])
|
||||
AC_MSG_NOTICE([using CPPFLAGS=$CPPFLAGS])
|
||||
AC_MSG_NOTICE([using LDFLAGS=$LDFLAGS])
|
||||
|
||||
|
|
|
@ -1360,6 +1360,24 @@ su - postgres
|
|||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><envar>CXX</envar></term>
|
||||
<listitem>
|
||||
<para>
|
||||
C++ compiler
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><envar>CXXFLAGS</envar></term>
|
||||
<listitem>
|
||||
<para>
|
||||
options to pass to the C++ compiler
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><envar>DTRACE</envar></term>
|
||||
<listitem>
|
||||
|
|
|
@ -249,9 +249,11 @@ endif # not PGXS
|
|||
CC = @CC@
|
||||
GCC = @GCC@
|
||||
SUN_STUDIO_CC = @SUN_STUDIO_CC@
|
||||
CXX = @CXX@
|
||||
CFLAGS = @CFLAGS@
|
||||
CFLAGS_VECTOR = @CFLAGS_VECTOR@
|
||||
CFLAGS_SSE42 = @CFLAGS_SSE42@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
|
||||
# Kind-of compilers
|
||||
|
||||
|
@ -813,6 +815,10 @@ ifndef COMPILE.c
|
|||
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
|
||||
endif
|
||||
|
||||
ifndef COMPILE.cc
|
||||
COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
|
||||
endif
|
||||
|
||||
DEPDIR = .deps
|
||||
|
||||
ifeq ($(GCC), yes)
|
||||
|
@ -822,6 +828,10 @@ ifeq ($(GCC), yes)
|
|||
@if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
|
||||
$(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
|
||||
|
||||
%.o : %.cpp
|
||||
@if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
|
||||
$(COMPILE.cc) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
|
||||
|
||||
endif # GCC
|
||||
|
||||
# Include all the dependency files generated for the current
|
||||
|
|
|
@ -100,6 +100,7 @@ endif
|
|||
# Try to keep the sections in some kind of order, folks...
|
||||
|
||||
override CFLAGS += $(CFLAGS_SL)
|
||||
override CXXFLAGS += $(CFLAGS_SL)
|
||||
ifdef SO_MAJOR_VERSION
|
||||
# libraries ought to use this to refer to versioned gettext domain names
|
||||
override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
|
||||
|
|
Loading…
Reference in a new issue