diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-03-09 23:19:10 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-05-09 11:01:38 +0200 |
commit | a3e92f9bcf72ebe94da181c0b1dd873ebbc2c9cc (patch) | |
tree | 8b0f555ff82a2070e2d2d0a17830a4adeef0a601 | |
parent | a0ff28ea8c10a4a897330c64aa3db6af88285994 (diff) |
support different levels of PCH usage
There are now 4 levels of PCH support, the previous 'full' level
adding to PCH whatever the update_pch script finds useful,
and new levels 'system', which adds only external headers,
'base', which is 'system' and LO basic headers (sal, osl, rtl, vcl)
and 'normal', which is 'full' without headers from the module
built itself.
With Clang/GCC even 'system' still saves some time (10-15%) and since external
headers should rarely if even change, it should be without most
of the disadvantages of PCH. And even 'base' should be pretty easy
to use, as those headers should be rarely changed while developing,
thus avoiding the need for massive rebuilds. Using 'normal' or 'full'
does not seem to be worth it with Clang or GCC, but with MSVC that still
makes a difference, so keep(?) 'full' the default there.
The update_pch script unfortunately does not include as many system
headers as it could, since it includes only what is directly included
by the .cxx, but not what's included indirectly by .hxx files.
https://lists.freedesktop.org/archives/libreoffice/2019-May/082685.html
Change-Id: If83a07a1fc9b77d0134502b0d89348944f82806b
Reviewed-on: https://gerrit.libreoffice.org/71580
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rwxr-xr-x | bin/update_pch | 15 | ||||
-rw-r--r-- | configure.ac | 68 | ||||
-rw-r--r-- | solenv/gbuild/LinkTarget.mk | 13 | ||||
-rw-r--r-- | solenv/gbuild/PrecompiledHeaders.mk | 2 | ||||
-rw-r--r-- | solenv/gbuild/gbuild.mk | 6 | ||||
-rw-r--r-- | solenv/gbuild/platform/com_GCC_defs.mk | 2 |
6 files changed, 78 insertions, 28 deletions
diff --git a/bin/update_pch b/bin/update_pch index cc9022ad2a24..587cd2cd8bfb 100755 --- a/bin/update_pch +++ b/bin/update_pch @@ -488,17 +488,28 @@ def sort_by_category(list, root, module, filter_local): boo.append(i) elif '<osl' in i or '<rtl' in i or '<sal' in i or '<vcl' in i: cor.append(i) - elif prefix in i: + elif prefix in i or not '/' in i: + mod.append(i) + # Headers from another module that is closely tied to the module. + elif module == 'sc' and '<formula' in i: mod.append(i) else: rst.append(i) out = [] + out += [ "#if PCH_LEVEL >= 1" ] out += sorted(sys) out += sorted(boo) + out += [ "#endif // PCH_LEVEL >= 1" ] + out += [ "#if PCH_LEVEL >= 2" ] out += sorted(cor) + out += [ "#endif // PCH_LEVEL >= 2" ] + out += [ "#if PCH_LEVEL >= 3" ] out += sorted(rst) + out += [ "#endif // PCH_LEVEL >= 3" ] + out += [ "#if PCH_LEVEL >= 4" ] out += sorted(mod) + out += [ "#endif // PCH_LEVEL >= 4" ] return out def parse_makefile(groups, lines, lineno, lastif, ifstack): @@ -964,7 +975,7 @@ def main(): # Find the first include in the old pch. start = -1 for i in xrange(len(old_pch_lines)): - if old_pch_lines[i].startswith('#include'): + if old_pch_lines[i].startswith('#include') or old_pch_lines[i].startswith('#if PCH_LEVEL'): start = i break # Clobber if there is a mismatch. diff --git a/configure.ac b/configure.ac index 14249897ba02..8ed51262b391 100644 --- a/configure.ac +++ b/configure.ac @@ -1075,8 +1075,11 @@ AC_ARG_ENABLE(fuzzers, ) libo_FUZZ_ARG_ENABLE(pch, - AS_HELP_STRING([--enable-pch], - [Enables precompiled header support for C++. Forced default on Windows/VC build]) + AS_HELP_STRING([--enable-pch=<yes/no/system/base/normal/full>], + [Enables precompiled header support for C++. Forced default on Windows/VC build. + Using 'system' will include only external headers, 'basic' will add also headers + from base modules, 'normal' will also add all headers except from the module built, + 'full' will use all suitable headers even from a module itself.]) ) libo_FUZZ_ARG_ENABLE(epm, @@ -5028,24 +5031,61 @@ AC_SUBST(HYPH_SYSTEM_DIR) AC_SUBST(THES_SYSTEM_DIR) dnl =================================================================== -dnl enable pch by default on windows -dnl enable it explicitly otherwise +dnl Precompiled headers. ENABLE_PCH="" AC_MSG_CHECKING([whether to enable pch feature]) -if test "$enable_pch" != "no"; then +if test -z "$enable_pch"; then if test "$_os" = "WINNT"; then - ENABLE_PCH="TRUE" - AC_MSG_RESULT([yes]) - elif test -n "$enable_pch" && test "$GCC" = "yes"; then - ENABLE_PCH="TRUE" - AC_MSG_RESULT([yes]) - elif test -n "$enable_pch"; then - AC_MSG_ERROR([Precompiled header not yet supported for your platform/compiler]) + # Enabled by default on Windows. + enable_pch=yes + else + enable_pch=no + fi +fi +if test "$enable_pch" != "no" -a "$_os" != "WINNT" -a "$GCC" != "yes" ; then + AC_MSG_ERROR([Precompiled header not yet supported for your platform/compiler]) +fi +if test "$enable_pch" = "system"; then + ENABLE_PCH="1" + AC_MSG_RESULT([yes (system headers)]) +elif test "$enable_pch" = "base"; then + ENABLE_PCH="2" + AC_MSG_RESULT([yes (system and base headers)]) +elif test "$enable_pch" = "normal"; then + ENABLE_PCH="3" + AC_MSG_RESULT([yes (normal)]) +elif test "$enable_pch" = "full"; then + ENABLE_PCH="4" + AC_MSG_RESULT([yes (full)]) +elif test "$enable_pch" = "yes"; then + # Pick a suitable default. + if test "$GCC" = "yes"; then + # With Clang and GCC higher levels do not seem to make a noticeable improvement, + # while making the PCHs larger and rebuilds more likely. + ENABLE_PCH="2" + AC_MSG_RESULT([yes (system and base headers)]) else - AC_MSG_RESULT([no]) + # With MSVC the highest level makes a significant difference, + # and it was the default when there used to be no PCH levels. + ENABLE_PCH="4" + AC_MSG_RESULT([yes (full)]) fi -else +elif test "$enable_pch" = "no"; then AC_MSG_RESULT([no]) +else + AC_MSG_ERROR([Unknown value for --enable-pch]) +fi +if test -n "$ENABLE_PCH"; then + if test -n "$CCACHE"; then + if ! echo "$CCACHE_SLOPPINESS" | grep -q pch_defines | grep -q time_macros; then + AC_MSG_WARN([PCH with ccache requires CCACHE_SLOPPINESS to include 'pch_defines,time_macros']) + add_warning "PCH with ccache requires CCACHE_SLOPPINESS to include 'pch_defines,time_macros'" + fi + if test -z "$CCACHE_PCH_EXTSUM"; then + AC_MSG_WARN([It is recommended to set CCACHE_PCH_EXTSUM=1 for PCH with ccache.]) + add_warning "It is recommended to set CCACHE_PCH_EXTSUM=1 for PCH with ccache." + fi + fi fi AC_SUBST(ENABLE_PCH) diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk index d1e5b9a7c644..5eed2a4edb1c 100644 --- a/solenv/gbuild/LinkTarget.mk +++ b/solenv/gbuild/LinkTarget.mk @@ -268,7 +268,7 @@ gb_CxxObject_get_source = $(1)/$(2).cxx # compiled with different flags and link that in rather than mixing different # flags in one linktarget. define gb_CxxObject__set_pchflags -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) ifneq ($(strip $$(PCH_NAME)),) ifeq ($$(sort $$(PCH_CXXFLAGS) $$(PCH_DEFS) $$(gb_LinkTarget_EXCEPTIONFLAGS)),$$(sort $$(T_CXXFLAGS) $$(T_CXXFLAGS_APPEND) $$(DEFS))) $$@ : PCHFLAGS := $$(call gb_PrecompiledHeader_get_enableflags,$$(PCH_NAME),$$(PCH_LINKTARGETMAKEFILENAME)) @@ -1121,7 +1121,7 @@ $(call gb_CxxObject_get_target,$(2)) : | $(call gb_LinkTarget_get_headers_target $(call gb_CxxObject_get_target,$(2)) : T_CXXFLAGS += $(3) $(call gb_CxxObject_get_target,$(2)) : \ OBJECTOWNER := $(call gb_Object__owner,$(2),$(1)) -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) $(call gb_CxxObject_get_target,$(2)) : $(call gb_PrecompiledHeader_get_timestamp,$(4)) endif @@ -1258,7 +1258,7 @@ $(call gb_GenCxxObject_get_target,$(2)) : T_CXXFLAGS += $(3) $(call gb_GenCxxObject_get_target,$(2)) : \ OBJECTOWNER := $(call gb_Object__owner,$(2),$(1)) $(call gb_GenCxxObject_get_target,$(2)) : GEN_CXX_SOURCE := $(call gb_GenCxxObject_get_source,$(2),$(1)) -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) $(call gb_GenCxxObject_get_target,$(2)) : $(call gb_PrecompiledHeader_get_timestamp,$(4)) endif @@ -1517,6 +1517,9 @@ $(call gb_LinkTarget_get_target,$(1)) : PCHOBJS = $$(PCHOBJEX) $(call gb_LinkTarget_get_target,$(1)) : PCH_DEFS := $$(DEFS) $(call gb_LinkTarget_get_target,$(1)) : PCH_CXXFLAGS := $$(T_CXXFLAGS) $(call gb_LinkTarget__get_cxxflags,$(4)) +$(call gb_LinkTarget_get_target,$(1)) : DEFS += -DPCH_LEVEL=$(gb_ENABLE_PCH) +$(call gb_LinkTarget_get_target,$(1)) : PCH_DEFS += -DPCH_LEVEL=$(gb_ENABLE_PCH) + $(call gb_PrecompiledHeader_get_target,$(3),$(4)) : VISIBILITY := $(call gb_PrecompiledHeader_get_timestamp,$(4)) : $(call gb_PrecompiledHeader_get_target,$(3),$(4)) @@ -1529,7 +1532,7 @@ endef # call gb_LinkTarget_set_precompiled_header,linktarget,pchcxxfile,,linktargetmakefilename define gb_LinkTarget_set_precompiled_header -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) $(call gb_LinkTarget__set_precompiled_header_impl,$(1),$(2),$(notdir $(2)),$(4)) $(call gb_PrecompiledHeader_generate_rules,$(notdir $(2)),$(4)) endif @@ -1593,7 +1596,7 @@ gb_LinkTarget_use_externals = \ # call gb_LinkTarget_set_visibility_default,linktarget define gb_LinkTarget_set_visibility_default $(call gb_LinkTarget_get_target,$(1)) : VISIBILITY := default -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) ifneq ($(strip $$(PCH_NAME)),) $(call gb_PrecompiledHeader_get_target,$$(PCH_NAME),$$(PCH_LINKTARGETMAKEFILENAME)) : VISIBILITY := default endif diff --git a/solenv/gbuild/PrecompiledHeaders.mk b/solenv/gbuild/PrecompiledHeaders.mk index e5635e816b42..e7df26abd77a 100644 --- a/solenv/gbuild/PrecompiledHeaders.mk +++ b/solenv/gbuild/PrecompiledHeaders.mk @@ -20,7 +20,7 @@ # PrecompiledHeader class -ifeq ($(gb_ENABLE_PCH),$(true)) +ifneq ($(gb_ENABLE_PCH),) # Use different PCH file depending on whether we use debugging symbols. gb_PrecompiledHeader__get_debugdir = $(if $(call gb_LinkTarget__symbols_enabled,$(1)),debug,nodebug) diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk index 6aa83c5903ed..889041172000 100644 --- a/solenv/gbuild/gbuild.mk +++ b/solenv/gbuild/gbuild.mk @@ -142,11 +142,7 @@ ifeq ($(gb_ENABLE_SYMBOLS_FOR),no) gb_ENABLE_SYMBOLS_FOR := endif -ifneq ($(strip $(ENABLE_PCH)),) -gb_ENABLE_PCH := $(true) -else -gb_ENABLE_PCH := $(false) -endif +gb_ENABLE_PCH := $(ENABLE_PCH) ifneq ($(nodep)$(ENABLE_PRINT_DEPS),) gb_FULLDEPS := $(false) diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk index 3f3273753364..5d5c69ddeb9c 100644 --- a/solenv/gbuild/platform/com_GCC_defs.mk +++ b/solenv/gbuild/platform/com_GCC_defs.mk @@ -136,7 +136,7 @@ gb_CXXFLAGS_COMMON += -fstack-protector-strong gb_LinkTarget_LDFLAGS += -fstack-protector-strong endif -ifeq ($(ENABLE_PCH),TRUE) +ifneq ($(ENABLE_PCH),) ifeq ($(COM_IS_CLANG),TRUE) # Clang by default includes in the PCH timestamps of the files it was # generated from, which would make the PCH be a "new" file for ccache |