bump product version to 7.6.3.2-android
[LibreOffice.git] / solenv / gbuild / PrecompiledHeaders.mk
blobd7b84e99157842c6973c029f61232ac1f243d3b0
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 # PrecompiledHeader class
23 # Use different PCH file depending on whether we use debugging symbols.
24 gb_PrecompiledHeader__get_debugdir = $(if $(call gb_target_symbols_enabled,$(1)),debug,nodebug)
26 # $(call gb_PrecompiledHeader_generate_timestamp_rule,linktargetmakefilename)
27 define gb_PrecompiledHeader_generate_timestamp_rule
28 $(call gb_LinkTarget_get_pch_timestamp,$(1)) :
29 mkdir -p $$(dir $$@) && touch $$@
31 endef
33 ifneq ($(gb_ENABLE_PCH),)
35 # IMPORTANT: Since these defines get expanded, every $ needs to be doubled to $$, except
36 # for $(1)'s and things that are constant.
37 # The defines are needed to get the right version of gb_PrecompiledHeader__get_debugdir.
39 # all cxxflags to use for compilation
40 gb_PrecompiledHeader_cxxflags_includes := $$(PCH_DEFS) $$(PCH_CXXFLAGS) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS)
41 # flags to save to the .flags file to check if they are the same as last time
42 # (note: the leading space in sed is important, to remove the option and its separating space)
43 gb_PrecompiledHeader_flags_for_flags_file := $$(sort $(gb_PrecompiledHeader_cxxflags_includes)) \
44 $(if $(gb_PrecompiledHeader_ignore_flags_for_flags_file),| sed 's/ $(gb_PrecompiledHeader_ignore_flags_for_flags_file)//')
46 # $(call gb_PrecompiledHeader_generate_rules,pchtarget,linktarget,linktargetmakefilename,pchcxxfile,compiler)
47 define gb_PrecompiledHeader_generate_rules
49 $(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)) :
50 $$(call gb_Helper_abbreviate_dirs,\
51 mkdir -p $$(dir $$@) && \
52 echo "$$(call gb_PrecompiledHeader_get_target,$(1),$(3)) : $$(gb_Helper_PHONY)" > $$@)
54 # keep the flags the PCH was built with in a separate file, update the file if and only if the flags
55 # change, and make the PCH depend on it => the PCH will be rebuilt on any flags change
56 .PHONY: force
57 $(call gb_PrecompiledHeader_get_flags_file,$(1),$(3)) : force
58 $$(call gb_Helper_abbreviate_dirs,\
59 mkdir -p $$(dir $$@) && \
60 echo $(gb_PrecompiledHeader_flags_for_flags_file) | cmp -s - $$@ \
61 || echo $(gb_PrecompiledHeader_flags_for_flags_file) > $$@)
63 # despite this being only one .d file, need to run concat-deps on it to
64 # re-write external headers from UnpackedTarball
65 $(call gb_PrecompiledHeader_get_target,$(1),$(3)) :
66 test "$$(PCH_LINKTARGETMAKEFILENAME)" = "$(3)" \
67 || ( echo "Error, PCH $(1) built by $$(PCH_LINKTARGETMAKEFILENAME) instead of $(3)" >&2; exit 1)
68 rm -f $$@
69 $$(call gb_PrecompiledHeader__command,$$@,$(1),$$<,$(gb_PrecompiledHeader_cxxflags_includes),$$(INCLUDE),$(3),$(5))
70 $$(call gb_PrecompiledHeader__sum_command,$$@,$(1),$$<,$(gb_PrecompiledHeader_cxxflags_includes),$$(INCLUDE),$(3),$(5))
71 ifeq ($(gb_FULLDEPS),$(true))
72 $$(call gb_Helper_abbreviate_dirs,\
73 RESPONSEFILE=$$(call gb_var2file,$$(shell $$(gb_MKTEMP)),$$(call gb_PrecompiledHeader_get_dep_target_tmp,$(1),$(3))) && \
74 SYSTEM_BOOST="$(SYSTEM_BOOST)" $$(call gb_Executable_get_command,concat-deps) $$$${RESPONSEFILE} \
75 > $$(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)) && \
76 rm -f $$$${RESPONSEFILE} $$(call gb_PrecompiledHeader_get_dep_target_tmp,$(1),$(3)))
77 endif
79 $(call gb_PrecompiledHeader_get_for_reuse_target,$(1),$(3)) : $(call gb_LinkTarget_get_target,$(2))
80 $$(call gb_PrecompiledHeader__create_reuse_files,$(2),$(1),$(3))
81 mkdir -p $$(dir $$@) && touch $$@
83 .PHONY : $(call gb_PrecompiledHeader_get_clean_target,$(1))
84 $(call gb_PrecompiledHeader_get_clean_target,$(1)) :
85 $$(call gb_Output_announce,$(1),$(false),PCH,1)
86 -$$(call gb_Helper_abbreviate_dirs,\
87 rm -f $$(call gb_PrecompiledHeader_get_target,$(1),$(3)) \
88 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).obj \
89 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).pdb \
90 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).sum \
91 $$(call gb_PrecompiledHeader_get_flags_file,$(1),$(3)) \
92 $$(call gb_PrecompiledHeader_get_for_reuse_target,$(1),$(3)) \
93 $$(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)))
95 endef
97 # $(call gb_PrecompiledHeader_check_flags,linktargetmakefilename,pchcxxfile,pchfile,flags)
98 # When creating a PCH, the PCH's CXXFLAGS are saved to a matching .flags file. When reusing the PCH
99 # from another linktarget, use the file to check that the linktarget uses the same CXXFLAGS as the PCH.
100 # This complements the check in gb_CxxObject__set_pchflags.
101 define gb_PrecompiledHeader_check_flags
102 $$(call gb_Helper_abbreviate_dirs,\
103 $$(if $$(strip $$(call gb_PrecompiledHeader_check_flags_internal,$$(shell cat $(4)),$(5),$(2))),false,true) || ( \
104 echo Error reusing $(2) by $(1). >&2 && \
105 echo -n " precompiled header flags : ">&2 && \
106 cat $(4) >&2 && \
107 echo " object flags : "$$(sort $(5)) >&2 && \
108 echo " reason : $$(call gb_PrecompiledHeader_check_flags_internal,$$(shell cat $(4)),$(5),$(2))" >&2 && \
109 echo Incorrect precompiled header setup or internal gbuild error. >&2 ; \
110 exit 1) \
113 endef
115 # When trying to reuse one PCH between multiple linktargets, there is a problem that we have
116 # various defines that cause mismatch in the check above, but these defines actually should not affect the PCH.
117 # Specifically, there are 3 kinds:
118 # - -DXXX_DLLIMPLEMENTATION - they are used only in our headers, should not affect system headers.
119 # - -DSYSTEM_XXX - they are used only by our code (if at all), should not affect system headers
120 # - various LO configuration defines - they again should only be used by our code and not system headers
121 # Technically, different compilers handle additional defines like this:
122 # - GCC
123 # * It is explicitly allowed to have different macros, as long as they do not affect the PCH.
124 # * With -Winvalid-pch GCC will even warn if there is a change in a macro affecting the PCH.
125 # * https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
126 # - Clang
127 # * I could not find an official statement on what happens if definitions are different.
128 # * In practice a conflict does not seem to be detected, but the PCH and all the code in it
129 # acts according to the settings it was built with. Using a PCH and adding more defines
130 # seems to be functionally equivalent to creating the definitions only after the PCH inclusion.
131 # * As a side-effect, macros defined on the command line not present in the PCH suddenly
132 # trigger the -Wunused-macros warning. See bottom of pch/inc/clangfix.hxx .
133 # - MSVC
134 # * MSVC explicitly states that the definitions must be the same, but they are not checked,
135 # and "unpredictable results can occur" if files depend on them.
136 # * In practice the situation seems to be the same as with Clang, the PCH and the code from it
137 # act according to the settings it was built with.
138 # * https://docs.microsoft.com/en-us/cpp/build/creating-precompiled-header-files
139 # So while this is officially tricky, in practice it seems to work to allow PCH reuse if the linktarget
140 # has more defines than the PCH was built with, as long as the defines do not affect the PCH.
141 gb_PrecompiledHeader_ignore_flags_system := \
142 -DSAX_DLLIMPLEMENTATION \
143 -DSCQAHELPER_DLLIMPLEMENTATION \
144 -DVCLPLUG_WIN_IMPLEMENTATION \
145 -DVCLPLUG_GEN_IMPLEMENTATION \
146 -DSYSTEM_EXPAT \
147 -DSYSTEM_LIBXML \
148 -DSYSTEM_ZLIB \
149 -DSYSTEM_NSS \
150 -DHAVE_VALGRIND_HEADERS \
151 -DUSE_RANDR \
152 -DUSE_XINERAMA_XORG \
153 -DDISABLE_CVE_TESTS \
154 -DCPPUNIT_PLUGIN_EXPORT='extern "C" SAL_DLLPUBLIC_EXPORT' \
155 -DOOO_DLLIMPLEMENTATION_TEST \
156 -DSK_USER_CONFIG_HEADER=% \
157 -DSKIA_DLL \
158 -DGLM_FORCE_CTOR_INIT \
159 -DVCL_INTERNALS \
160 -DZLIB_CONST \
161 $(gb_CXXFLAGS_include)$(SRCDIR)/pch/inc/clangfix.hxx \
162 $(gb_CXXFLAGS_no_pch_warnings) \
163 $(gb_PrecompiledHeader_ignore_flags_for_flags_file) \
165 # Probably also update pch/inc/clangfix.hxx if you extend the list.
167 # $(call gb_PrecompiledHeader_check_flags_internal,pchfileflags,flags,pchcxxfile)
168 # Check if two sets of flags are compatible, allowing reuse of the PCH. Flags are compatible if
169 # - they are the same
170 # - the PCH is precompiled_system and the linktarget has additional defines listed above
171 define gb_PrecompiledHeader_check_flags_internal
172 $(if $(filter-out $(2),$(1)),$(filter-out $(2),$(1)), \
173 $(if $(filter-out $(1),$(2)),\
174 $(if $(filter-out precompiled_system,$(notdir $(3))),$(filter-out $(1),$(2)), \
175 $(foreach flag,$(filter-out $(1),$(2)),$(filter-out $(gb_PrecompiledHeader_ignore_flags_system),$(flag))) \
177 ,) \
179 endef
181 endif
183 # vim: set noet sw=4: