diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-02-07 20:42:40 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-02-10 10:10:46 +0100 |
commit | 396d1019413ea6d7e3965e47beae0837d2cf84f2 (patch) | |
tree | e391deb3089a354eb82e2a9a6a73f377aee96b71 | |
parent | 67770fc41f409e9d7e179b34eb84434ed237a6ce (diff) |
add BLOCK_PCH to gbuild, allowing partial non-PCH rebuilds
Both MSVC and Clang (with -building-pch-with-obj) generate one extra
object file for code from the PCH, saving repeated generating of this
code for every object using the PCH. This causes problems when
temporarily disabling PCH by doing 'make ENABLE_PCH=' (e.g. when
checking #include's are correct), as this object would no longer be
linked in, and objects not rebuilt with PCH disabled would still need
it.
This patch allows doing 'make BLOCK_PCH=1' instead, which will disable
PCH with the exception of this object file still getting linked in.
Change-Id: I8fcb150ef27ebb34118d62739a1a1558aa1a6f3d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88341
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | solenv/gbuild/LinkTarget.mk | 37 | ||||
-rw-r--r-- | solenv/gbuild/PrecompiledHeaders.mk | 22 | ||||
-rw-r--r-- | solenv/gbuild/gbuild.mk | 7 | ||||
-rw-r--r-- | solenv/gbuild/platform/com_GCC_defs.mk | 4 |
4 files changed, 47 insertions, 23 deletions
diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk index f3fa447a57bf..e71c6127d845 100644 --- a/solenv/gbuild/LinkTarget.mk +++ b/solenv/gbuild/LinkTarget.mk @@ -1532,8 +1532,6 @@ endef define gb_LinkTarget__set_precompiled_header_variables $(call gb_LinkTarget_get_target,$(1)) : PCH_NAME := $(3) $(call gb_LinkTarget_get_target,$(1)) : PCH_LINKTARGETMAKEFILENAME := $(4) -$(call gb_LinkTarget_get_target,$(1)) : PCHOBJEX = $(call gb_PrecompiledHeader_get_objectfile, $(call gb_PrecompiledHeader_get_target,$(3),$(4))) -$(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)) $(gb_LinkTarget_EXCEPTIONFLAGS) @@ -1556,14 +1554,22 @@ $(call gb_LinkTarget_get_pch_timestamp,$(4)) : $(call gb_PrecompiledHeader_get_t $(call gb_LinkTarget__set_precompiled_header_variables,$(1),$(2),$(3),$(4)) +ifeq ($(gb_FULLDEPS),$(true)) +-include $(call gb_PrecompiledHeader_get_dep_target,$(3),$(4)) +endif + +endef + +# call gb_LinkTarget__add_precompiled_header_object,linktarget,pchcxxfile,pchtarget,linktargetmakefilename +define gb_LinkTarget__add_precompiled_header_object +# Clang-style ifneq ($(BUILDING_PCH_WITH_OBJ),) $(call gb_LinkTarget_add_exception_object,$(1),$(2),,$(4)) $(call gb_CxxObject_get_target,$(2)) : T_PCH_EXTRA_CXXFLAGS += $(gb_PrecompiledHeader_pch_with_obj) endif - -ifeq ($(gb_FULLDEPS),$(true)) --include $(call gb_PrecompiledHeader_get_dep_target,$(3),$(4)) -endif +# MSVC-style +$(call gb_LinkTarget_get_target,$(1)) : PCHOBJEX = $(call gb_PrecompiledHeader_get_objectfile, $(call gb_PrecompiledHeader_get_target,$(3),$(4))) +$(call gb_LinkTarget_get_target,$(1)) : PCHOBJS = $$(PCHOBJEX) endef @@ -1573,6 +1579,9 @@ ifneq ($(gb_ENABLE_PCH),) $(call gb_LinkTarget__set_precompiled_header_impl,$(1),$(2),$(notdir $(2)),$(4)) $(call gb_PrecompiledHeader_generate_rules,$(notdir $(2)),$(1),$(4),$(2)) endif +ifneq ($(gb_ENABLE_PCH)$(BLOCK_PCH),) +$(call gb_LinkTarget__add_precompiled_header_object,$(1),$(2),$(notdir $(2)),$(4)) +endif endef @@ -1591,15 +1600,22 @@ $(call gb_LinkTarget_get_pch_reuse_timestamp,$(4)) : $(call gb_PrecompiledHeader $$(call gb_PrecompiledHeader__copy_reuse_files,$(1),$(3),$(4)) mkdir -p $$(dir $$@) && touch $$@ +endef + +# call gb_LinkTarget__add_reuse_precompiled_header_object,linktarget,pchcxxfile,pchtarget,linktargetmakefilename +define gb_LinkTarget__add_reuse_precompiled_header_object +# Clang-style ifneq ($(BUILDING_PCH_WITH_OBJ),) # We need to link in also the PCH's object file. Again, rely on a special for_reuse target for dependencies. $(if $(wildcard $(call gb_CxxObject_get_source,$(SRCDIR),$(2))),,$(eval $(call gb_Output_error,No such source file $(call gb_CxxObject_get_source,$(SRCDIR),$(2))))) $(call gb_LinkTarget_get_target,$(1)) : CXXOBJECTS += $(2) endif +# MSVC-style +$(call gb_LinkTarget_get_target,$(1)) : PCHOBJEX = $(call gb_PrecompiledHeader_get_objectfile, $(call gb_PrecompiledHeader_get_target,$(3),$(4))) +$(call gb_LinkTarget_get_target,$(1)) : PCHOBJS = $$(PCHOBJEX) endef - # call gb_LinkTarget__reuse_precompiled_header_workarounds,linktarget,pchcxxfile,pchtarget,linktargetmakefilename define gb_LinkTarget__reuse_precompiled_header_workarounds ifeq ($(COM_IS_CLANG),TRUE) @@ -1610,20 +1626,21 @@ endef # call gb_LinkTarget_reuse_precompiled_header,linktarget,pchcxxfile,,linktargetmakefilename define gb_LinkTarget_reuse_precompiled_header -ifneq ($(gb_ENABLE_PCH),) ifeq ($(gb_DISABLE_PCH_REUSE),$(false)) +ifneq ($(gb_ENABLE_PCH),) $(call gb_LinkTarget__reuse_precompiled_header_impl,$(1),$(2),$(notdir $(2)),$(4)) $(call gb_LinkTarget__reuse_precompiled_header_workarounds,$(1),$(2),$(notdir $(2)),$(4)) endif +ifneq ($(gb_ENABLE_PCH)$(BLOCK_PCH),) +$(call gb_LinkTarget__add_reuse_precompiled_header_object,$(1),$(2),$(notdir $(2)),$(4)) +endif endif endef # call gb_LinkTarget_use_common_precompiled_header,linktarget,,,linktargetmakefilename define gb_LinkTarget_use_common_precompiled_header -ifneq ($(gb_ENABLE_PCH),) $(call gb_LinkTarget_reuse_precompiled_header,$(1),pch/inc/pch/precompiled_system,,$(4)) -endif endef diff --git a/solenv/gbuild/PrecompiledHeaders.mk b/solenv/gbuild/PrecompiledHeaders.mk index 1ea64140c50c..b7b22b954872 100644 --- a/solenv/gbuild/PrecompiledHeaders.mk +++ b/solenv/gbuild/PrecompiledHeaders.mk @@ -20,11 +20,18 @@ # PrecompiledHeader class -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) +# $(call gb_PrecompiledHeader_generate_timestamp_rule,linktargetmakefilename) +define gb_PrecompiledHeader_generate_timestamp_rule +$(call gb_LinkTarget_get_pch_timestamp,$(1)) : + mkdir -p $$(dir $$@) && touch $$@ + +endef + +ifneq ($(gb_ENABLE_PCH),) + # IMPORTANT: Since these defines get expanded, every $ needs to be doubled to $$, except # for $(1)'s and things that are constant. # The defines are needed to get the right version of gb_PrecompiledHeader__get_debugdir. @@ -72,15 +79,6 @@ $(call gb_PrecompiledHeader_get_clean_target,$(1)) : endef -endif - -# $(call gb_PrecompiledHeader_generate_timestamp_rule,linktargetmakefilename) -define gb_PrecompiledHeader_generate_timestamp_rule -$(call gb_LinkTarget_get_pch_timestamp,$(1)) : - mkdir -p $$(dir $$@) && touch $$@ - -endef - # $(call gb_PrecompiledHeader_check_flags,linktargetmakefilename,pchcxxfile,pchfile,flags) # When creating a PCH, the PCH's CXXFLAGS are saved to a matching .flags file. When reusing the PCH # from another linktarget, use the file to check that the linktarget uses the same CXXFLAGS as the PCH. @@ -160,4 +158,6 @@ $(if $(filter-out $(2),$(1)),$(filter-out $(2),$(1)), \ ) endef +endif + # vim: set noet sw=4: diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk index 774bb5adfc8b..94bb0f93e866 100644 --- a/solenv/gbuild/gbuild.mk +++ b/solenv/gbuild/gbuild.mk @@ -142,7 +142,14 @@ ifeq ($(gb_ENABLE_SYMBOLS_FOR),no) gb_ENABLE_SYMBOLS_FOR := endif +ifeq ($(BLOCK_PCH),) gb_ENABLE_PCH := $(ENABLE_PCH) +else +# Setting BLOCK_PCH effectively disables PCH, but the extra object file will be still linked in. +# This is useful for rebuilding only some files with PCH disabled, e.g. to check #include's, +# disabling the whole ENABLE_PCH would lead to unresolved symbols at link time. +gb_ENABLE_PCH := +endif 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 9b61d6f3fb7f..530bc16e8da3 100644 --- a/solenv/gbuild/platform/com_GCC_defs.mk +++ b/solenv/gbuild/platform/com_GCC_defs.mk @@ -145,7 +145,7 @@ gb_CXXFLAGS_COMMON += $(gb_VISIBILITY_FLAGS_CXX) gb_LinkTarget_LDFLAGS += -fstack-protector-strong -ifneq ($(ENABLE_PCH),) +ifneq ($(gb_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 @@ -293,7 +293,7 @@ endef gb_Helper_get_rcfile = $(1)rc -ifneq ($(ENABLE_PCH),) +ifneq ($(gb_ENABLE_PCH),) # Enable use of .sum files for PCHs. gb_COMPILER_SETUP += CCACHE_PCH_EXTSUM=1 # CCACHE_SLOPPINESS should contain pch_defines,time_macros for PCHs. |