1# Copyright (C) 2009 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15#
16
17# Test for gtest. Run using 'runtest'.
18# The linux build and tests are run under valgrind by 'runtest'.
19
20LOCAL_PATH := $(call my-dir)
21include $(CLEAR_VARS)
22
23# TODO: Refactor these as 1st class build templates as suggested in
24# review of the original import.
25
26libgtest_test_common_includes := \
27    $(LOCAL_PATH)/../include \
28    $(LOCAL_PATH)/..
29
30libgtest_test_includes := $(libgtest_test_common_includes)
31libgtest_test_static_lib := libgtest_main libgtest
32libgtest_test_ldflags :=
33
34libgtest_test_host_includes := $(libgtest_test_common_includes)
35libgtest_test_host_static_lib := libgtest_main_host libgtest_host
36libgtest_test_host_ldflags := -lpthread
37
38# $(2) and $(4) must be set or cleared in sync. $(2) is used to
39# generate the right make target (host vs device). $(4) is used in the
40# module's name and to have different module names for the host vs
41# device builds. Finally $(4) is used to pick up the right set of
42# libraries, typically the host libs have a _host suffix in their
43# names.
44# $(1): source list
45# $(2): "HOST_" or empty
46# $(3): extra CFLAGS or empty
47# $(4): "_host" or empty
48# $(5): "TARGET_OUT_DATA_NATIVE_TESTS" or empty (where to install)
49define _define-test
50$(foreach file,$(1), \
51  $(eval include $(CLEAR_VARS)) \
52  $(eval LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk) \
53  $(eval LOCAL_CPP_EXTENSION := .cc) \
54  $(eval LOCAL_SRC_FILES := $(file)) \
55  $(eval LOCAL_C_INCLUDES := $(libgtest_test$(4)_includes)) \
56  $(eval LOCAL_MODULE := $(notdir $(file:%.cc=%))$(4)) \
57  $(eval LOCAL_CFLAGS += $(3) -Wno-empty-body) \
58  $(eval LOCAL_LDFLAGS += $(libgtest_test$(4)_ldflags)) \
59  $(eval LOCAL_STATIC_LIBRARIES := $(libgtest_test$(4)_static_lib)) \
60  $(eval LOCAL_SHARED_LIBRARIES := $(libgtest_test$(4)_shared_lib)) \
61  $(if $(2),,$(eval LOCAL_MODULE_TAGS := tests)) \
62  $(eval LOCAL_MODULE_PATH := $($(5))) \
63  $(eval include $(BUILD_$(2)EXECUTABLE)) \
64)
65endef
66
67define host-test
68$(call _define-test,$(1),HOST_,-O0,_host,)
69endef
70
71define target-test
72$(call _define-test,$(1),,,,TARGET_OUT_DATA_NATIVE_TESTS)
73endef
74
75sources := \
76    gtest_all_test.cc \
77    gtest-death-test_test.cc \
78    gtest_environment_test.cc \
79    gtest-listener_test.cc \
80    gtest_main_unittest.cc \
81    gtest_no_test_unittest.cc \
82    gtest-param-test2_test.cc \
83    gtest_premature_exit_test.cc \
84    gtest_repeat_test.cc \
85    gtest_sole_header_test.cc \
86    gtest_stress_test.cc \
87    gtest-unittest-api_test.cc \
88
89# We don't have exceptions.
90#    gtest-death-test_ex_test.cc \
91#    gtest_throw_on_failure_ex_test.cc \
92# We don't have tr1::tuple.
93#    gtest-tuple_test.cc \
94# These don't build.
95#    gtest-param-test_test.cc \
96#    gtest-printers_test.cc \
97
98$(call host-test, $(sources))
99$(call target-test, $(sources))
100