Bump for 3.6-28
[LibreOffice.git] / solenv / gbuild / CppunitTest.mk
blobbc522be843b285c44da17eb83e4fbb3a91dcd0fe
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 #
6 # Copyright 2000, 2011 Oracle and/or its affiliates.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # This file is part of OpenOffice.org.
12 # OpenOffice.org is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License version 3
14 # only, as published by the Free Software Foundation.
16 # OpenOffice.org is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Lesser General Public License version 3 for more details
20 # (a copy is included in the LICENSE file that accompanied this code).
22 # You should have received a copy of the GNU Lesser General Public License
23 # version 3 along with OpenOffice.org. If not, see
24 # <http://www.openoffice.org/license.html>
25 # for a copy of the LGPLv3 License.
27 #*************************************************************************
30 # CppunitTest class
33 UNIT_FAILED_MSG := echo; echo "Error: a unit test failed, please do one of:"; echo; echo "export DEBUGCPPUNIT=TRUE \# for exception catching"; echo "export GDBCPPUNITTRACE=\"gdb --args\" \# for interactive debugging"; echo "export VALGRIND=memcheck \# for memory checking" ; echo "and retry."
35 ifeq ($(strip $(DEBUGCPPUNIT)),TRUE)
36 gb_CppunitTest_GDBTRACE := gdb -nx --command=$(SOLARENV)/bin/gdbtrycatchtrace-stdout -return-child-result --args
37 else ifneq ($(strip $(GDBCPPUNITTRACE)),)
38 gb_CppunitTest_GDBTRACE := $(GDBCPPUNITTRACE)
39 gb_CppunitTest__interactive := $(true)
40 endif
42 ifneq ($(strip $(VALGRIND)),)
43 gb_CppunitTest_VALGRINDTOOL := valgrind --tool=$(VALGRIND) --num-callers=50
44 ifeq ($(strip $(VALGRIND)),memcheck)
45 G_SLICE := always-malloc
46 GLIBCXX_FORCE_NEW := 1
47 endif
48 endif
50 # defined by platform
51 # gb_CppunitTest_TARGETTYPE
52 # gb_CppunitTest_get_filename
53 # DBGSV_ERROR_OUT => in non-product builds, ensure that tools-based assertions do not pop up as message box, but are routed to the shell
54 ifneq ($(OS),IOS)
55 gb_CppunitTest_CPPTESTTARGET := $(call gb_Executable_get_target,cppunit/cppunittester)
56 endif
58 gb_CppunitTest__get_linktargetname = CppunitTest/$(call gb_CppunitTest_get_filename,$(1))
60 define gb_CppunitTest__make_args
61 --headless \
62 $(if $(URE),\
63 $(if $(strip $(CONFIGURATION_LAYERS)),\
64 "-env:CONFIGURATION_LAYERS=$(strip $(CONFIGURATION_LAYERS))") \
65 $(if $(strip $(UNO_TYPES)),\
66 "-env:UNO_TYPES=$(foreach item,$(UNO_TYPES),$(call gb_Helper_make_url,$(item)))") \
67 $(if $(strip $(UNO_SERVICES)),\
68 "-env:UNO_SERVICES=$(foreach item,$(UNO_SERVICES),$(call gb_Helper_make_url,$(item)))") \
69 $(foreach dir,URE_INTERNAL_LIB_DIR LO_LIB_DIR,\
70 -env:$(dir)=$(call gb_Helper_make_url,$(gb_CppunitTest_LIBDIR))) \
71 --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \
72 --protector unobootstrapprotector$(gb_Library_DLLEXT) unobootstrapprotector \
73 ) $(ARGS)
74 endef
76 .PHONY : $(call gb_CppunitTest_get_clean_target,%)
77 $(call gb_CppunitTest_get_clean_target,%) :
78 $(call gb_Helper_abbreviate_dirs,\
79 rm -f $(call gb_CppunitTest_get_target,$*) $(call gb_CppunitTest_get_target,$*).log)
81 .PHONY : $(call gb_CppunitTest_get_target,%)
82 $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTTARGET)
83 $(call gb_Output_announce,$*,$(true),CUT,2)
84 $(call gb_Helper_abbreviate_dirs,\
85 mkdir -p $(dir $@) && \
86 ($(gb_CppunitTest_CPPTESTPRECOMMAND) \
87 $(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
88 $(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
89 $(if $(DBGSV_ERROR_OUT),DBGSV_ERROR_OUT=$(DBGSV_ERROR_OUT)) \
90 $(if $(SAL_DIAGNOSE_ABORT),SAL_DIAGNOSE_ABORT=$(SAL_DIAGNOSE_ABORT)) \
91 STAR_RESOURCEPATH=$(dir $(call gb_ResTarget_get_outdir_target,example)) \
92 $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTTARGET) \
93 $(call gb_LinkTarget_get_target,CppunitTest/$(call gb_CppunitTest_get_libfilename,$*)) \
94 $(call gb_CppunitTest__make_args) \
95 $(if $(gb_CppunitTest__interactive),,> $@.log 2>&1 || (cat $@.log && $(UNIT_FAILED_MSG) && false))))
97 define gb_CppunitTest_CppunitTest
98 $(call gb_CppunitTest__CppunitTest_impl,$(1),$(call gb_CppunitTest__get_linktargetname,$(1)))
100 endef
102 define gb_CppunitTest__CppunitTest_impl
103 $(call gb_LinkTarget_LinkTarget,$(2))
104 $(call gb_LinkTarget_set_targettype,$(2),CppunitTest)
105 $(call gb_LinkTarget_add_defs,$(2),\
106 $(gb_CppunitTest_DEFS) \
108 $(call gb_LinkTarget_use_external,$(2),cppunit)
109 $(call gb_LinkTarget_set_include,$(2),\
110 $$(INCLUDE) \
111 $(filter -I%,$(CPPUNIT_CFLAGS)) \
113 $(call gb_LinkTarget_add_defs,$(2), \
114 $(filter-out -I%,$(CPPUNIT_CFLAGS)) \
116 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_LinkTarget_get_target,$(2))
117 $(call gb_CppunitTest_get_clean_target,$(1)) : $(call gb_LinkTarget_get_clean_target,$(2))
118 $(call gb_CppunitTest_CppunitTest_platform,$(1),$(2),$(gb_CppunitTest_DLLDIR)/$(call gb_CppunitTest_get_libfilename,$(1)))
119 $(call gb_CppunitTest_get_target,$(1)) : ARGS :=
120 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS :=
121 $(call gb_CppunitTest_get_target,$(1)) : URE := $(false)
122 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES :=
123 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES :=
124 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := shell
125 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT :=
126 $$(eval $$(call gb_Module_register_target,$(call gb_CppunitTest_get_target,$(1)),$(call gb_CppunitTest_get_clean_target,$(1))))
128 endef
130 define gb_CppunitTest_abort_on_assertion
131 $(call gb_CppunitTest_get_target,$(1)) : DBGSV_ERROR_OUT := abort
132 $(call gb_CppunitTest_get_target,$(1)) : SAL_DIAGNOSE_ABORT := TRUE
134 endef
136 define gb_CppunitTest_set_args
137 $$(call gb_Output_error,gb_CppunitTest_set_args: use gb_CppunitTest_add_arguments instead.))
138 endef
140 # Add additional command line arguments for the test.
142 # You should practically never need to use this, as there are special
143 # functions for adding many commonly used arguments.
144 define gb_CppunitTest_add_arguments
145 $(call gb_CppunitTest_get_target,$(1)) : ARGS += $(2)
147 endef
149 define gb_CppunitTest_uses_ure
150 $$(call gb_Output_error,gb_CppunitTest_uses_ure: use gb_CppunitTest_use_ure instead.))
151 endef
153 define gb_CppunitTest_use_ure
154 $(call gb_CppunitTest_use_rdb,$(1),ure/services)
155 $(call gb_CppunitTest_get_target,$(1)) : URE := $(true)
157 endef
159 define gb_CppunitTest_add_type_rdb
160 $$(call gb_Output_error,\
161 gb_CppunitTest_add_type_rdb: use gb_CppunitTest_use_api instead.)
162 endef
164 define gb_CppunitTest_use_type_rdb
165 $$(call gb_Output_error,\
166 gb_CppunitTest_use_type_rdb: use gb_CppunitTest_use_api instead.)
167 endef
169 define gb_CppunitTest__use_api
170 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_UnoApi_get_target,$(2))
171 $(call gb_CppunitTest_get_target,$(1)) : UNO_TYPES += $(call gb_UnoApi_get_target,$(2))
173 endef
175 define gb_CppunitTest_add_type_rdbs
176 $$(call gb_Output_error,\
177 gb_CppunitTest_add_type_rdbs: use gb_CppunitTest_use_api instead.)
178 endef
180 define gb_CppunitTest_use_type_rdbs
181 $$(call gb_Output_error,\
182 gb_CppunitTest_use_type_rdbs: use gb_CppunitTest_use_api instead.)
183 endef
185 define gb_CppunitTest_use_api
186 $(call gb_LinkTarget_use_api,$(call gb_CppunitTest__get_linktargetname,$(1)),$(2))
187 $(foreach rdb,$(2),$(call gb_CppunitTest__use_api,$(1),$(rdb)))
189 endef
191 define gb_CppunitTest_add_service_rdb
192 $$(call gb_Output_error,\
193 gb_CppunitTest_add_service_rdb: use gb_CppunitTest_use_rdb instead.)
194 endef
196 define gb_CppunitTest_use_service_rdb
197 $$(call gb_Output_error,gb_CppunitTest_use_service_rdb: use gb_CppunitTest_use_rdb instead.))
198 endef
200 define gb_CppunitTest_use_rdb
201 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Rdb_get_outdir_target,$(2))
202 $(call gb_CppunitTest_get_target,$(1)) : UNO_SERVICES += $(call gb_Rdb_get_outdir_target,$(2))
204 endef
206 define gb_CppunitTest_add_service_rdbs
207 $$(call gb_Output_error,\
208 gb_CppunitTest_add_service_rdbs: use gb_CppunitTest_use_rdbs instead.)
209 endef
211 define gb_CppunitTest_use_service_rdbs
212 $$(call gb_Output_error,gb_CppunitTest_use_service_rdbs: use gb_CppunitTest_use_rdbs instead.))
213 endef
215 define gb_CppunitTest_use_rdbs
216 $(foreach rdb,$(2),$(call gb_CppunitTest_use_rdb,$(1),$(rdb)))
218 endef
220 define gb_CppunitTest_add_component
221 $$(call gb_Output_error,\
222 gb_CppunitTest_add_component: use gb_CppunitTest_use_component instead.)
223 endef
225 define gb_CppunitTest_use_component
226 $(call gb_CppunitTest_get_target,$(1)) : \
227 $(call gb_ComponentTarget_get_outdir_target,$(2))
228 $(call gb_CppunitTest_get_target,$(1)) : \
229 UNO_SERVICES += $(call gb_ComponentTarget_get_outdir_target,$(2))
231 endef
233 # Given a list of component files, filter out those corresponding
234 # to libraries not built in this configuration.
235 define gb_CppunitTest__filter_not_built_components
236 $(filter-out \
237 $(if $(filter SCRIPTING,$(BUILD_TYPE)),, \
238 basic/util/sb \
239 sw/util/vbaswobj \
240 scripting/source/basprov/basprov \
241 scripting/util/scriptframe) \
242 $(if $(filter DBCONNECTIVITY,$(BUILD_TYPE)),, \
243 dbaccess/util/dba \
244 forms/util/frm),$(1))
245 endef
247 define gb_CppunitTest_add_components
248 $$(call gb_Output_error,\
249 gb_CppunitTest_add_components: use gb_CppunitTest_use_components instead.)
250 endef
252 define gb_CppunitTest_use_components
253 $(foreach component,$(call gb_CppunitTest__filter_not_built_components,$(2)),$(call gb_CppunitTest_use_component,$(1),$(component)))
255 endef
257 define gb_CppunitTest_add_old_component
258 $$(call gb_Output_error,\
259 gb_CppunitTest_add_old_component: use gb_CppunitTest_use_old_component instead.)
260 endef
262 define gb_CppunitTest_use_old_component
263 $(call gb_CppunitTest_get_target,$(1)) : \
264 $(call gb_CppunitTest__get_old_component_target,$(2))
265 $(call gb_CppunitTest_get_target,$(1)) : \
266 UNO_SERVICES += $(call gb_ComponentTarget__get_old_component_target,$(2))
268 endef
270 define gb_CppunitTest_add_old_components
271 $$(call gb_Output_error,\
272 gb_CppunitTest_add_old_components: use gb_CppunitTest_use_old_components instead.)
273 endef
275 define gb_CppunitTest_use_old_components
276 $(foreach component,$(2),$(call gb_CppunitTest_use_old_component,$(1),$(component)))
278 endef
280 gb_ComponentTarget__get_old_component_target = $(OUTDIR)/xml/$(1).component
282 define gb_CppunitTest__use_configuration
283 $(call gb_CppunitTest_get_target,$(1)) : CONFIGURATION_LAYERS += $(2):$(call gb_Helper_make_url,$(3))
285 endef
287 # Use standard configuration.
288 define gb_CppunitTest_use_configuration
289 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Configuration_get_target,officecfg)
290 $(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(gb_Configuration_registry))
292 endef
294 # Use configuration for filters.
296 # Okay, this is not exactly true, because there may be configuration
297 # for more things than just filters in spool, but it is good enough.
298 define gb_CppunitTest_use_filter_configuration
299 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Configuration_get_target,fcfg_langpack)
300 $(call gb_CppunitTest__use_configuration,$(1),module,$(gb_Configuration_registry)/spool)
302 endef
304 # Use extra configuration dir(s).
305 define gb_CppunitTest_use_extra_configuration
306 $(foreach extra,$(2),$(call gb_CppunitTest__use_configuration,$(1),xcsxcu,$(extra)))
308 endef
310 define gb_CppunitTest_use_executable
311 $(call gb_CppunitTest_get_target,$(1)) : $(call gb_Executable_get_target,$(2))
312 endef
314 define gb_CppunitTest__forward_to_Linktarget
315 gb_CppunitTest_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_CppunitTest__get_linktargetname,$$(1)),$$(2),$$(3),CppunitTest_$$(1))
317 endef
319 $(eval $(foreach method,\
320 add_api \
321 add_cobject \
322 add_cobjects \
323 add_cxxobject \
324 add_cxxobjects \
325 add_exception_objects \
326 add_executable_objects \
327 use_executable_objects \
328 add_library_objects \
329 use_library_objects \
330 add_linked_libs \
331 use_libraries \
332 add_linked_static_libs \
333 use_static_libraries \
334 add_noexception_objects \
335 add_objcobject \
336 add_objcobjects \
337 add_objcxxobject \
338 add_objcxxobjects \
339 add_asmobject \
340 add_asmobjects \
341 add_package_headers \
342 use_package \
343 use_packages \
344 add_sdi_headers \
345 add_cflags \
346 set_cflags \
347 add_cxxflags \
348 set_yaccflags \
349 add_objcflags \
350 add_objcxxflags \
351 add_defs \
352 set_defs \
353 set_include \
354 add_ldflags \
355 set_ldflags \
356 add_libs \
357 use_internal_api \
358 use_internal_bootstrap_api \
359 use_internal_comprehensive_api \
360 set_library_path_flags \
361 set_objcflags \
362 set_objcxxflags \
363 use_external \
364 use_externals \
366 $(call gb_CppunitTest__forward_to_Linktarget,$(method))\
369 # vim: set noet sw=4: