Use MsLangId::getConfiguredSystemUILanguage()
[LibreOffice.git] / solenv / gbuild / PrecompiledHeaders.mk
blob4b24099525995ee2fc8058f6db09f74a283c30af
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_LinkTarget__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 # $(call gb_PrecompiledHeader_generate_rules,pchtarget,linktarget,linktargetmakefilename,pchcxxfile,compiler)
40 define gb_PrecompiledHeader_generate_rules
42 $(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)) :
43 $$(call gb_Helper_abbreviate_dirs,\
44 mkdir -p $$(dir $$@) && \
45 echo "$$(call gb_PrecompiledHeader_get_target,$(1),$(3)) : $$(gb_Helper_PHONY)" > $$@)
47 # despite this being only one .d file, need to run concat-deps on it to
48 # re-write external headers from UnpackedTarball
49 $(call gb_PrecompiledHeader_get_target,$(1),$(3)) :
50 test "$$(PCH_LINKTARGETMAKEFILENAME)" = "$(3)" \
51 || ( echo "Error, PCH $(1) built by $$(PCH_LINKTARGETMAKEFILENAME) instead of $(3)" >&2; exit 1)
52 rm -f $$@
53 $$(call gb_PrecompiledHeader__command,$$@,$(1),$$<,$$(PCH_DEFS),$$(PCH_CXXFLAGS) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS),$$(INCLUDE),$(3),$(5))
54 $$(call gb_PrecompiledHeader__sum_command,$$@,$(1),$$<,$$(PCH_DEFS),$$(PCH_CXXFLAGS) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS),$$(INCLUDE),$(3))
55 echo $$(sort $$(PCH_DEFS) $$(PCH_CXXFLAGS) $$(gb_PrecompiledHeader_EXCEPTIONFLAGS)) > $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).flags
56 ifeq ($(gb_FULLDEPS),$(true))
57 $$(call gb_Helper_abbreviate_dirs,\
58 RESPONSEFILE=$$(call var2file,$$(shell $$(gb_MKTEMP)),200,$$(call gb_PrecompiledHeader_get_dep_target_tmp,$(1),$(3))) && \
59 $$(call gb_Executable_get_command,concat-deps) $$$${RESPONSEFILE} \
60 > $$(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)) && \
61 rm -f $$$${RESPONSEFILE} $$(call gb_PrecompiledHeader_get_dep_target_tmp,$(1),$(3)))
62 endif
64 $(call gb_PrecompiledHeader_get_for_reuse_target,$(1),$(3)) : $(call gb_LinkTarget_get_target,$(2))
65 $$(call gb_PrecompiledHeader__create_reuse_files,$(2),$(1),$(3))
66 mkdir -p $$(dir $$@) && touch $$@
68 .PHONY : $(call gb_PrecompiledHeader_get_clean_target,$(1))
69 $(call gb_PrecompiledHeader_get_clean_target,$(1)) :
70 $$(call gb_Output_announce,$(1),$(false),PCH,1)
71 -$$(call gb_Helper_abbreviate_dirs,\
72 rm -f $$(call gb_PrecompiledHeader_get_target,$(1),$(3)) \
73 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).obj \
74 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).pdb \
75 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).sum \
76 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).flags \
77 $$(call gb_PrecompiledHeader_get_target,$(1),$(3)).reuse \
78 $$(call gb_PrecompiledHeader_get_dep_target,$(1),$(3)))
80 endef
82 # $(call gb_PrecompiledHeader_check_flags,linktargetmakefilename,pchcxxfile,pchfile,flags)
83 # When creating a PCH, the PCH's CXXFLAGS are saved to a matching .flags file. When reusing the PCH
84 # from another linktarget, use the file to check that the linktarget uses the same CXXFLAGS as the PCH.
85 # This complements the check in gb_CxxObject__set_pchflags.
86 define gb_PrecompiledHeader_check_flags
87 $$(call gb_Helper_abbreviate_dirs,\
88 $$(if $$(strip $$(call gb_PrecompiledHeader_check_flags_internal,$$(shell cat $(3).flags),$(4),$(2))),false,true) || ( \
89 echo Error reusing $(2) by $(1). >&2 && \
90 echo -n " precompiled header flags : ">&2 && \
91 cat $(3).flags >&2 && \
92 echo " object flags : "$$(sort $(4)) >&2 && \
93 echo " reason : $$(call gb_PrecompiledHeader_check_flags_internal,$$(shell cat $(3).flags),$(4),$(2))" >&2 && \
94 echo Incorrect precompiled header setup or internal gbuild error. >&2 ; \
95 exit 1) \
98 endef
100 # When trying to reuse one PCH between multiple linktargets, there is a problem that we have
101 # various defines that cause mismatch in the check above, but these defines actually should not affect the PCH.
102 # Specifically, there are 3 kinds:
103 # - -DXXX_DLLIMPLEMENTATION - they are used only in our headers, should not affect system headers.
104 # - -DSYSTEM_XXX - they are used only by our code (if at all), should not affect system headers
105 # - various LO configuration defines - they again should only be used by our code and not system headers
106 # Technically, different compilers handle additional defines like this:
107 # - GCC
108 # * It is explicitly allowed to have different macros, as long as they do not affect the PCH.
109 # * With -Winvalid-pch GCC will even warn if there is a change in a macro affecting the PCH.
110 # * https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
111 # - Clang
112 # * I could not find an official statement on what happens if definitions are different.
113 # * In practice a conflict does not seem to be detected, but the PCH and all the code in it
114 # acts according to the settings it was built with. Using a PCH and adding more defines
115 # seems to be functionally equivalent to creating the definitions only after the PCH inclusion.
116 # * As a side-effect, macros defined on the command line not present in the PCH suddenly
117 # trigger the -Wunused-macros warning. See bottom of pch/inc/clangfix.hxx .
118 # - MSVC
119 # * MSVC explicitly states that the definitions must be the same, but they are not checked,
120 # and "unpredictable results can occur" if files depend on them.
121 # * In practice the situation seems to be the same as with Clang, the PCH and the code from it
122 # act according to the settings it was built with.
123 # * https://docs.microsoft.com/en-us/cpp/build/creating-precompiled-header-files
124 # So while this is officially tricky, in practice it seems to work to allow PCH reuse if the linktarget
125 # has more defines than the PCH was built with, as long as the defines do not affect the PCH.
126 gb_PrecompiledHeader_ignore_flags_system := \
127 -DFASTSAX_DLLIMPLEMENTATION \
128 -DSAX_DLLIMPLEMENTATION \
129 -DSCQAHELPER_DLLIMPLEMENTATION \
130 -DVCLPLUG_WIN_IMPLEMENTATION \
131 -DVCLPLUG_GEN_IMPLEMENTATION \
132 -DSYSTEM_EXPAT \
133 -DSYSTEM_LIBXML \
134 -DSYSTEM_ZLIB \
135 -DSYSTEM_NSS \
136 -DHAVE_VALGRIND_HEADERS \
137 -DUSE_RANDR \
138 -DUSE_XINERAMA_XORG \
139 -DDISABLE_CVE_TESTS \
140 -DCPPUNIT_PLUGIN_EXPORT='extern "C" SAL_DLLPUBLIC_EXPORT' \
141 -DOOO_DLLIMPLEMENTATION_TEST \
142 -DSK_USER_CONFIG_HEADER=% \
143 -DSKIA_DLL \
144 -DGLM_FORCE_CTOR_INIT \
145 -DVCL_INTERNALS \
146 -DZLIB_CONST \
147 -include $(SRCDIR)/pch/inc/clangfix.hxx \
149 # Probably also update pch/inc/clangfix.hxx if you extend the list.
151 # $(call gb_PrecompiledHeader_check_flags_internal,pchfileflags,flags,pchcxxfile)
152 # Check if two sets of flags are compatible, allowing reuse of the PCH. Flags are compatible if
153 # - they are the same
154 # - the PCH is precompiled_system and the linktarget has additional defines listed above
155 define gb_PrecompiledHeader_check_flags_internal
156 $(if $(filter-out $(2),$(1)),$(filter-out $(2),$(1)), \
157 $(if $(filter-out $(1),$(2)),\
158 $(if $(filter-out precompiled_system,$(notdir $(3))),$(filter-out $(1),$(2)), \
159 $(foreach flag,$(filter-out $(1),$(2)),$(filter-out $(gb_PrecompiledHeader_ignore_flags_system),$(flag))) \
161 ,) \
163 endef
165 endif
167 # vim: set noet sw=4: