lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] precompiled headers


From: Vaclav Slavik
Subject: Re: [lmi] precompiled headers
Date: Thu, 06 Aug 2009 19:23:04 +0200

On Sun, 2009-06-28 at 22:16 +0000, Greg Chicares wrote:
> I don't see anything that I'd object to putting in HEAD.

Here are updated makefiles parts:

=== modified file 'Makefile.am'
--- Makefile.am revid:address@hidden
+++ Makefile.am revid:address@hidden
@@ -38,6 +38,33 @@
 endif
 
 ##############################################################################
+# Precompiled headers support
+##############################################################################
+
+if LMI_USE_PCH
+
+AM_CXXFLAGS = -fPIC -DLMI_COMPILER_USES_PCH
+
+PCH_FILES = pchfile.hpp.gch pchfile_wx.hpp.gch
+
+CLEANFILES = $(PCH_FILES) .deps/
+
+# Adding a file to BUILT_SOURCES ensures that it is built before any source
+# files are compiled. That's exactly what is needed for PCH files.
+BUILT_SOURCES = $(PCH_FILES)
+
+pchfile.hpp.gch: $(srcdir)/pchfile.hpp
+       $(CXXCOMPILE) -x c++-header -c -o $@ -MD -MF $(DEPDIR)/address@hidden  
$<
+
+pchfile_wx.hpp.gch: $(srcdir)/pchfile_wx.hpp
+       $(CXXCOMPILE) $(WX_CXXFLAGS) -x c++-header -c -o $@ -MD -MF 
$(DEPDIR)/address@hidden $<
+
+include $(DEPDIR)/pchfile.hpp.gch.d
+include $(DEPDIR)/pchfile_wx.hpp.gch.d
+
+endif # LMI_USE_PCH
+
+##############################################################################
 # All Targets
 ##############################################################################
 
@@ -189,7 +216,7 @@
     wx_checks.cpp \
     wx_utility.cpp
 
-lmi_wx_CXXFLAGS = $(AM_CXXFLAGS) $(WX_CXXFLAGS) $(XMLWRAPP_CFLAGS) 
$(GTK_CFLAGS)
+lmi_wx_CXXFLAGS = $(AM_CXXFLAGS) $(WX_CXXFLAGS) $(XMLWRAPP_CFLAGS) 
$(GTK_CFLAGS) -DLMI_PCH_HEADER="<pchfile_wx.hpp>"
 # $(CGICC_INCLUDE_FLAGS)
 
 if LMI_MSW
@@ -347,7 +374,7 @@
     stratified_charges.cpp \
     tn_range_types.cpp \
     $(liblmi_common_sources)
-liblmi_la_CXXFLAGS = $(AM_CXXFLAGS) $(XMLWRAPP_CFLAGS)
+liblmi_la_CXXFLAGS = $(AM_CXXFLAGS) $(XMLWRAPP_CFLAGS) 
-DLMI_PCH_HEADER="<pchfile.hpp>"
 liblmi_la_CFLAGS = $(AM_CFLAGS)
 liblmi_la_LDFLAGS = -no-undefined $(AM_LDFLAGS)
 liblmi_la_LIBADD = \

=== modified file 'configure.ac'
--- configure.ac        revid:address@hidden
+++ configure.ac        revid:address@hidden
@@ -123,6 +123,20 @@
              esac],
              lmi_cgicc_option=no)
 
+dnl Note: PCH is not enabled by default, because it doesn't bring any
+dnl       speed improvements on typical setups. Because of that, it doesn't
+dnl       seem worth autodetecting PCH support either.
+AC_ARG_ENABLE(pch,
+             [AC_HELP_STRING([--enable-pch],
+                             [use GCC precompiled headers])],
+             [case "x${enableval}" in
+                   x) lmi_use_pch=yes ;;
+                xyes) lmi_use_pch=yes ;;
+                 xno) lmi_use_pch=no ;;
+                   *) AC_MSG_ERROR(bad value ${enableval} for 
--enable-pch[=yes|no]) ;;
+             esac], lmi_use_pch=no)
+AM_CONDITIONAL(LMI_USE_PCH, [ test "x$lmi_use_pch" = "xyes" ])
+
 dnl Pass standard options to wx.
 WX_STANDARD_OPTIONS([debug,shared,toolkit,wxshared])
 

=== modified file 'workhorse.make'
--- workhorse.make      revid:address@hidden
+++ workhorse.make      revid:address@hidden
@@ -275,6 +275,7 @@
 # so there's no point in calling them.
 
 all_include_directories := \
+  . \
   $(src_dir) \
   $(src_dir)/tools/pete-2.1.1 \
   $(overriding_include_directories) \
@@ -432,6 +433,7 @@
   -Wnon-template-friend \
   -Woverloaded-virtual \
   -Wpmf-conversions \
+  -Winvalid-pch \
   -Wsynth \
 
 # Too many warnings on correct code, e.g. exact comparison to zero:
@@ -588,6 +590,44 @@
   gcc_version_specific_warnings := -Wno-uninitialized
 endif
 
+pch_header := "<pchfile.hpp>"
+$(wx_dependent_objects): pch_header := "<pchfile_wx.hpp>"
+
+
+all:
+
+ifneq (,$(USE_PCH))
+
+.PHONY: pch
+pch: pchfile.hpp.gch pchfile_wx.hpp.gch
+
+%.hpp.gch: %.hpp
+       $(CXX) -x c++-header -c $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) $< -o$@
+
+# Files are deemed to depend on wx iff they contain 'include *<wx/'.
+# This heuristic isn't foolproof because wx headers might be included
+# indirectly. Include an innocuous header like <wx/version.h> in files
+# for which it fails.
+
+pch_using_objects := \
+  $(addsuffix .o,\
+    $(basename \
+      $(notdir \
+        $(shell $(GREP) \
+          --files-with-matches \
+          'include LMI_PCH_HEADER' \
+          $(src_dir)/*.?pp \
+        ) \
+      ) \
+    ) \
+  )
+
+$(pch_using_objects): pch
+
+actually_used_pch_flags := -DLMI_COMPILER_USES_PCH
+
+endif # USE_PCH
+
 CFLAGS = \
   $(debug_flag) $(optimization_flag) $(gprof_flag) \
 
@@ -615,6 +655,8 @@
   $(libstdcxx_warning_macros) \
   $(wx_predefinitions) \
   -DBOOST_STRICT_CONFIG \
+ -DLMI_PCH_HEADER=$(pch_header) \
+  $(actually_used_pch_flags) \
 
 REQUIRED_CFLAGS = \
   $(C_WARNINGS) \







reply via email to

[Prev in Thread] Current Thread [Next in Thread]