[PATCH 2/4] libstdc++: Adjust build of PCH files accounting configured host support.

Iain Sandoe iains.gcc@gmail.com
Thu Nov 4 20:02:16 GMT 2021


This takes account of the overall configuration for host PCH support
when deciding if we should build the libstdc++ PCH files.

We now require both the support is configured and that we are hosted.
A non-fatal configure warning is given if the user attempts to
--disable-host-pch-support --enable-libstdcxx-pch since the latter
conflicts with the former (but does not prevent a useable libstdc++
library build).

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libstdc++-v3/ChangeLog:

	* acinclude.m4: Account for configured host PCH support.
	* configure: Regenerate.
	* configure.ac: Act on --enable-host-pch-support.
---
 libstdc++-v3/acinclude.m4 | 49 ++++++++++++++++-----------
 libstdc++-v3/configure    | 71 ++++++++++++++++++++++++++-------------
 libstdc++-v3/configure.ac | 11 ++++--
 3 files changed, 86 insertions(+), 45 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 90ecc4a87a2..87652306691 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -3225,7 +3225,7 @@ AC_DEFUN([GLIBCXX_ENABLE_WCHAR_T], [
 ])
 
 
-dnl
+≈
 dnl Check to see if building and using a C++ precompiled header can be done.
 dnl
 dnl --enable-libstdcxx-pch=yes
@@ -3240,29 +3240,40 @@ dnl Substs:
 dnl  glibcxx_PCHFLAGS
 dnl
 AC_DEFUN([GLIBCXX_ENABLE_PCH], [
-  GLIBCXX_ENABLE(libstdcxx-pch,$1,,[build pre-compiled libstdc++ headers])
+  dnl This is only allowed if host support is enabled, and we are hosted.
+  if test "$1" = "yes" && test "$2" = "yes"; then
+    can_pch=yes
+  else
+    can_pch=no
+  fi
+  GLIBCXX_ENABLE(libstdcxx-pch,$can_pch,,[build pre-compiled libstdc++ headers])
   if test $enable_libstdcxx_pch = yes; then
-    AC_CACHE_CHECK([for compiler with PCH support],
-      [glibcxx_cv_prog_CXX_pch],
-      [ac_save_CXXFLAGS="$CXXFLAGS"
-       CXXFLAGS="$CXXFLAGS -Werror -Winvalid-pch -Wno-deprecated"
-       AC_LANG_SAVE
-       AC_LANG_CPLUSPLUS
-       echo '#include <math.h>' > conftest.h
-       if $CXX $CXXFLAGS $CPPFLAGS -x c++-header conftest.h \
+    if test "$2" != "yes"; then
+      glibcxx_cv_prog_CXX_pch=no
+      AC_MSG_WARN([PCH headers cannot be built since host PCH is disabled])
+    else
+      AC_CACHE_CHECK([for compiler with PCH support],
+        [glibcxx_cv_prog_CXX_pch],
+        [ac_save_CXXFLAGS="$CXXFLAGS"
+         CXXFLAGS="$CXXFLAGS -Werror -Winvalid-pch -Wno-deprecated"
+         AC_LANG_SAVE
+         AC_LANG_CPLUSPLUS
+         echo '#include <math.h>' > conftest.h
+         if $CXX $CXXFLAGS $CPPFLAGS -x c++-header conftest.h \
 			  -o conftest.h.gch 1>&5 2>&1 &&
 		echo '#error "pch failed"' > conftest.h &&
 	  echo '#include "conftest.h"' > conftest.cc &&
 	       $CXX -c $CXXFLAGS $CPPFLAGS conftest.cc 1>&5 2>&1 ;
-       then
-	 glibcxx_cv_prog_CXX_pch=yes
-       else
-	 glibcxx_cv_prog_CXX_pch=no
-       fi
-       rm -f conftest*
-       CXXFLAGS=$ac_save_CXXFLAGS
-       AC_LANG_RESTORE
-      ])
+         then
+	   glibcxx_cv_prog_CXX_pch=yes
+         else
+	   glibcxx_cv_prog_CXX_pch=no
+         fi
+         rm -f conftest*
+         CXXFLAGS=$ac_save_CXXFLAGS
+         AC_LANG_RESTORE
+        ])
+    fi
     enable_libstdcxx_pch=$glibcxx_cv_prog_CXX_pch
   fi
 

diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index 2d68b3672b9..ce82f16c859 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -103,7 +103,6 @@ if test "$enable_vtable_verify" = yes; then
   postdep_objects_CXX="${postdep_objects_CXX} ${glibcxx_builddir}/../libgcc/vtv_end.o"
 fi
 
-
 # libtool variables for C++ shared and position-independent compiles.
 #
 # Use glibcxx_lt_pic_flag to designate the automake variable
@@ -147,8 +146,16 @@ GLIBCXX_ENABLE_HOSTED
 # Enable descriptive messages to standard output on termination.
 GLIBCXX_ENABLE_VERBOSE
 
+# The current default is that PCH is supported by the host unless otherwise
+# stated.
+AC_ARG_ENABLE(host_pch_support,
+AS_HELP_STRING([--disable-host-pch-support],
+	       [Disable host support for precompiled headers]),
+host_pch_support=$enableval,
+host_pch_support=yes)
+
 # Enable compiler support that doesn't require linking.
-GLIBCXX_ENABLE_PCH($is_hosted)
+GLIBCXX_ENABLE_PCH($is_hosted, $host_pch_support)
 GLIBCXX_ENABLE_THREADS
 GLIBCXX_ENABLE_ATOMIC_BUILTINS
 GLIBCXX_ENABLE_LOCK_POLICY
-- 
2.24.3 (Apple Git-128)



More information about the Gcc-patches mailing list