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 ifneq ($(gb_ENABLE_PCH
),)
25 # Use different PCH file depending on whether we use debugging symbols.
26 gb_PrecompiledHeader__get_debugdir
= $(if
$(call gb_LinkTarget__symbols_enabled
,$(1)),debug
,nodebug
)
28 # IMPORTANT: Since these defines get expanded, every $ needs to be doubled to $$, except
29 # for $(1)'s and things that are constant.
30 # The defines are needed to get the right version of gb_PrecompiledHeader__get_debugdir.
32 # $(call gb_PrecompiledHeader_generate_rules,pchtarget,linktarget,linktargetmakefilename)
33 define gb_PrecompiledHeader_generate_rules
35 $(call gb_PrecompiledHeader_get_dep_target
,$(1),$(3)) :
36 $$(call gb_Helper_abbreviate_dirs
,\
37 mkdir
-p
$$(dir $$@
) && \
38 echo
"$$(call gb_PrecompiledHeader_get_target,$(1),$(3)) : $$(gb_Helper_PHONY)" > $$@
)
40 # despite this being only one .d file, need to run concat-deps on it to
41 # re-write external headers from UnpackedTarball
42 $(call gb_PrecompiledHeader_get_target
,$(1),$(3)) :
43 test "$$(PCH_LINKTARGETMAKEFILENAME)" = "$(3)" \
44 ||
( echo
"Error, PCH $(1) built by $$(PCH_LINKTARGETMAKEFILENAME) instead of $(3)" >&2; exit
1)
46 $$(call gb_PrecompiledHeader__command
,$$@
,$(1),$$<,$$(PCH_DEFS
),$$(PCH_CXXFLAGS
) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS
),$$(INCLUDE
),$(3))
47 $$(call gb_PrecompiledHeader__sum_command
,$$@
,$(1),$$<,$$(PCH_DEFS
),$$(PCH_CXXFLAGS
) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS
),$$(INCLUDE
),$(3))
48 echo
$$(sort $$(PCH_DEFS
) $$(PCH_CXXFLAGS
) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS
)) > $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).flags
49 ifeq ($(gb_FULLDEPS
),$(true
))
50 $$(call gb_Helper_abbreviate_dirs
,\
51 RESPONSEFILE
=$$(call var2file
,$$(shell $$(gb_MKTEMP
)),200,$$(call gb_PrecompiledHeader_get_dep_target_tmp
,$(1),$(3))) && \
52 $$(call gb_Executable_get_command
,concat-deps
) $$$${RESPONSEFILE} \
53 > $$(call gb_PrecompiledHeader_get_dep_target
,$(1),$(3)) && \
54 rm -f
$$$${RESPONSEFILE} $$(call gb_PrecompiledHeader_get_dep_target_tmp
,$(1),$(3)))
57 $(call gb_PrecompiledHeader_get_for_reuse_target
,$(1),$(3)) : $(call gb_LinkTarget_get_target
,$(2))
58 $$(call gb_PrecompiledHeader__create_reuse_files
,$(2),$(1),$(3))
59 mkdir
-p
$$(dir $$@
) && touch
$$@
61 .PHONY
: $(call gb_PrecompiledHeader_get_clean_target
,$(1))
62 $(call gb_PrecompiledHeader_get_clean_target
,$(1)) :
63 $$(call gb_Output_announce
,$(1),$(false
),PCH
,1)
64 -$$(call gb_Helper_abbreviate_dirs
,\
65 rm -f
$$(call gb_PrecompiledHeader_get_target
,$(1),$(3)) \
66 $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).obj \
67 $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).pdb \
68 $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).sum \
69 $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).flags \
70 $$(call gb_PrecompiledHeader_get_target
,$(1),$(3)).reuse \
71 $$(call gb_PrecompiledHeader_get_dep_target
,$(1),$(3)))
77 # $(call gb_PrecompiledHeader_generate_timestamp_rule,linktargetmakefilename)
78 define gb_PrecompiledHeader_generate_timestamp_rule
79 $(call gb_LinkTarget_get_pch_timestamp
,$(1)) :
80 mkdir
-p
$$(dir $$@
) && touch
$$@
84 # $(call gb_PrecompiledHeader_check_flags,linktargetmakefilename,pchcxxfile,pchfile,flags)
85 # When creating a PCH, the PCH's CXXFLAGS are saved to a matching .flags file. When reusing the PCH
86 # from another linktarget, use the file to check that the linktarget uses the same CXXFLAGS as the PCH.
87 # This complements the check in gb_CxxObject__set_pchflags.
88 define gb_PrecompiledHeader_check_flags
89 $$(call gb_Helper_abbreviate_dirs
,\
90 $$(if
$$(strip $$(call gb_PrecompiledHeader_check_flags_internal
,$$(shell cat
$(3).flags
),$(4),$(2))),false
,true
) ||
( \
91 echo Error reusing
$(2) by
$(1).
>&2 && \
92 echo
-n
" precompiled header flags : ">&2 && \
93 cat
$(3).flags
>&2 && \
94 echo
" object flags : "$$(sort $(4)) >&2 && \
95 echo
" reason : $$(call gb_PrecompiledHeader_check_flags_internal,$$(shell cat $(3).flags),$(4),$(2))" >&2 && \
96 echo Incorrect precompiled header setup or internal gbuild error.
>&2 ; \
102 # When trying to reuse one PCH between multiple linktargets, there is a problem that we have
103 # various defines that cause mismatch in the check above, but these defines actually should not affect the PCH.
104 # Specifically, there are 3 kinds:
105 # - -DXXX_DLLIMPLEMENTATION - they are used only in our headers, should not affect system headers.
106 # - -DSYSTEM_XXX - they are used only by our code (if at all), should not affect system headers
107 # - various LO configuration defines - they again should only be used by our code and not system headers
108 # Technically, different compilers handle additional defines like this:
110 # * It is explicitly allowed to have different macros, as long as they do not affect the PCH.
111 # * With -Winvalid-pch GCC will even warn if there is a change in a macro affecting the PCH.
112 # * https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
114 # * I could not find an official statement on what happens if definitions are different.
115 # * In practice a conflict does not seem to be detected, but the PCH and all the code in it
116 # acts according to the settings it was built with. Using a PCH and adding more defines
117 # seems to be functionally equivalent to creating the definitions only after the PCH inclusion.
118 # * As a side-effect, macros defined on the command line not present in the PCH suddenly
119 # trigger the -Wunused-macros warning. See bottom of pch/inc/clangfix.hxx .
121 # * MSVC explicitly states that the definitions must be the same, but they are not checked,
122 # and "unpredictable results can occur" if files depend on them.
123 # * In practice the situation seems to be the same as with Clang, the PCH and the code from it
124 # act according to the settings it was built with.
125 # * https://docs.microsoft.com/en-us/cpp/build/creating-precompiled-header-files
126 # So while this is officially tricky, in practice it seems to work to allow PCH reuse if the linktarget
127 # has more defines than the PCH was built with, as long as the defines do not affect the PCH.
128 gb_PrecompiledHeader_ignore_flags_system
:= \
129 -DFASTSAX_DLLIMPLEMENTATION \
130 -DSAX_DLLIMPLEMENTATION \
131 -DSCQAHELPER_DLLIMPLEMENTATION \
132 -DVCLPLUG_WIN_IMPLEMENTATION \
133 -DVCLPLUG_GEN_IMPLEMENTATION \
137 -DHAVE_VALGRIND_HEADERS \
139 -DUSE_XINERAMA_XORG \
140 -DDISABLE_CVE_TESTS \
141 -DCPPUNIT_PLUGIN_EXPORT
='extern "C" SAL_DLLPUBLIC_EXPORT' \
142 -DOOO_DLLIMPLEMENTATION_TEST \
143 -include $(SRCDIR
)/pch
/inc
/clangfix.hxx \
145 # Probably also update pch/inc/clangfix.hxx if you extend the list.
147 # $(call gb_PrecompiledHeader_check_flags_internal,pchfileflags,flags,pchcxxfile)
148 # Check if two sets of flags are compatible, allowing reuse of the PCH. Flags are compatible if
149 # - they are the same
150 # - the PCH is precompiled_system and the linktarget has additional defines listed above
151 define gb_PrecompiledHeader_check_flags_internal
152 $(if
$(filter-out $(2),$(1)),$(filter-out $(2),$(1)), \
153 $(if
$(filter-out $(1),$(2)),\
154 $(if
$(filter-out precompiled_system
,$(notdir $(3))),$(filter-out $(1),$(2)), \
155 $(foreach flag
,$(filter-out $(1),$(2)),$(filter-out $(gb_PrecompiledHeader_ignore_flags_system
),$(flag
))) \
161 # vim: set noet sw=4: