From 13ce3cb1eedb337eee3f45ffdf2e32332a22d50d Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 29 Jul 2021 17:42:34 -0700 Subject: Enable precompiled headers when using clang --- Makefile.in | 6 ++-- ax_check_compile_flag.m4 | 53 +++++++++++++++++++++++++++++++++ configure | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 3 ++ 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 ax_check_compile_flag.m4 diff --git a/Makefile.in b/Makefile.in index deebc5b..6ef2319 100644 --- a/Makefile.in +++ b/Makefile.in @@ -38,6 +38,7 @@ scripts_dir := $(src_dir)/scripts HAVE_INT128 := @HAVE_INT128@ HAVE_DLOPEN := @HAVE_DLOPEN@ +HAVE_CLANG_PCH := @HAVE_CLANG_PCH@ # If the version information is not in the configure script, then we # assume that we are in a working directory. We use the vcs-version.sh @@ -219,9 +220,8 @@ $(2)_deps += $$(patsubst %.o, %.d, $$($(2)_c_objs)) $(2)_deps += $$(patsubst %.h, %.h.d, $$($(2)_precompiled_hdrs)) $$($(2)_pch) : %.h.gch : %.h $(COMPILE) -x c++-header $$< -o $$@ -# If using clang, don't depend (and thus don't build) precompiled headers -$$($(2)_objs) : %.o : %.cc $$($(2)_gen_hdrs) $(if $(filter-out clang,$(CC)),$$($(2)_pch)) - $(COMPILE) $$($(2)_CFLAGS) -c $$< +$$($(2)_objs) : %.o : %.cc $$($(2)_gen_hdrs) $$($(2)_pch) + $(COMPILE) $(if $(HAVE_CLANG_PCH), $$(if $$($(2)_pch), -include-pch $$($(2)_pch))) $$($(2)_CFLAGS) -c $$< $$($(2)_c_objs) : %.o : %.c $$($(2)_gen_hdrs) $(COMPILE_C) $$($(2)_CFLAGS) -c $$< diff --git a/ax_check_compile_flag.m4 b/ax_check_compile_flag.m4 new file mode 100644 index 0000000..bd753b3 --- /dev/null +++ b/ax_check_compile_flag.m4 @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/configure b/configure index 79661e7..1b033da 100755 --- a/configure +++ b/configure @@ -627,6 +627,7 @@ LIBOBJS subprojects_enabled subprojects HAVE_DLOPEN +HAVE_CLANG_PCH HAVE_INT128 INSTALL_DATA INSTALL_SCRIPT @@ -2334,6 +2335,45 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac # =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + + +# =========================================================================== # https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html # =========================================================================== # @@ -4647,6 +4687,43 @@ fi done +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts -relocatable-pch" >&5 +$as_echo_n "checking whether C++ compiler accepts -relocatable-pch... " >&6; } +if ${ax_cv_check_cxxflags___relocatable_pch+:} false; then : + $as_echo_n "(cached) " >&6 +else + + ax_check_save_flags=$CXXFLAGS + CXXFLAGS="$CXXFLAGS -relocatable-pch" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ax_cv_check_cxxflags___relocatable_pch=yes +else + ax_cv_check_cxxflags___relocatable_pch=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CXXFLAGS=$ax_check_save_flags +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cxxflags___relocatable_pch" >&5 +$as_echo "$ax_cv_check_cxxflags___relocatable_pch" >&6; } +if test "x$ax_cv_check_cxxflags___relocatable_pch" = xyes; then : + HAVE_CLANG_PCH=yes + +else + : +fi + + #------------------------------------------------------------------------- # MCPPBS subproject list #------------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index b7788b4..d9d991d 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,7 @@ AC_CANONICAL_HOST m4_include(ax_require_defined.m4) m4_include(ax_append_flag.m4) +m4_include(ax_check_compile_flag.m4) m4_include(ax_check_link_flag.m4) m4_include(ax_append_link_flags.m4) @@ -89,6 +90,8 @@ AC_CHECK_TYPE([__int128_t], AC_SUBST([HAVE_INT128],[yes])) AX_APPEND_LINK_FLAGS([-Wl,--export-dynamic]) +AX_CHECK_COMPILE_FLAG([-relocatable-pch], AC_SUBST([HAVE_CLANG_PCH],[yes])) + #------------------------------------------------------------------------- # MCPPBS subproject list #------------------------------------------------------------------------- -- cgit v1.1