|
| 1 | +# A sample Makefile for building both Google Mock and Google Test and |
| 2 | +# using them in user tests. This file is self-contained, so you don't |
| 3 | +# need to use the Makefile in Google Test's source tree. Please tweak |
| 4 | +# it to suit your environment and project. You may want to move it to |
| 5 | +# your project's root directory. |
| 6 | +# |
| 7 | +# SYNOPSIS: |
| 8 | +# |
| 9 | +# make [all] - makes everything. |
| 10 | +# make TARGET - makes the given target. |
| 11 | +# make clean - removes all files generated by make. |
| 12 | + |
| 13 | +# Please tweak the following variable definitions as needed by your |
| 14 | +# project, except GMOCK_HEADERS and GTEST_HEADERS, which you can use |
| 15 | +# in your own targets but shouldn't modify. |
| 16 | + |
| 17 | +# Points to the root of Google Test, relative to where this file is. |
| 18 | +# Remember to tweak this if you move this file, or if you want to use |
| 19 | +# a copy of Google Test at a different location. |
| 20 | +GTEST_DIR = ../googletest/googletest/ |
| 21 | + |
| 22 | +# Points to the root of Google Mock, relative to where this file is. |
| 23 | +# Remember to tweak this if you move this file. |
| 24 | +GMOCK_DIR = ../googletest/googlemock/ |
| 25 | + |
| 26 | +# Points to the root of Arduino mock, relative to where this file is. |
| 27 | +# Remember to tweak this if you move this file. |
| 28 | +ARDUINO_MOCK_DIR = ../arduino-mock/ |
| 29 | + |
| 30 | +# Where to find user code. |
| 31 | +TEST_DIR = . |
| 32 | + |
| 33 | +PROJECT_ROOT = ../../ |
| 34 | +SRC_ROOT = $(PROJECT_ROOT)/src |
| 35 | + |
| 36 | +# Flags passed to the preprocessor. |
| 37 | +# Set Google Test and Google Mock's header directories as system |
| 38 | +# directories, such that the compiler doesn't generate warnings in |
| 39 | +# these headers. |
| 40 | +CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include \ |
| 41 | + -I$(ARDUINO_MOCK_DIR)/include/arduino-mock/ \ |
| 42 | + -I$(ARDUINO_MOCK_DIR)/include/ \ |
| 43 | + -I$(PROJECT_ROOT)/test/dummies \ |
| 44 | + -I$(PROJECT_ROOT)/src \ |
| 45 | + -I$(PROJECT_ROOT) |
| 46 | + |
| 47 | +# Flags passed to the C++ compiler. |
| 48 | +CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 |
| 49 | + |
| 50 | +# All tests produced by this Makefile. Remember to add new tests you |
| 51 | +# created to the list. |
| 52 | +TESTS = get-command_test set-command_test remove-command_test \ |
| 53 | + push-command_test begin-command_test stream-command_test |
| 54 | + |
| 55 | +# All Google Test headers. Usually you shouldn't change this |
| 56 | +# definition. |
| 57 | +GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ |
| 58 | + $(GTEST_DIR)/include/gtest/internal/*.h |
| 59 | + |
| 60 | +# All Google Mock headers. Note that all Google Test headers are |
| 61 | +# included here too, as they are #included by Google Mock headers. |
| 62 | +# Usually you shouldn't change this definition. |
| 63 | +GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \ |
| 64 | + $(GMOCK_DIR)/include/gmock/internal/*.h \ |
| 65 | + $(GTEST_HEADERS) |
| 66 | + |
| 67 | +# Arduino Mock headers. |
| 68 | +# Usually you shouldn't change this definition. |
| 69 | +ARDUINO_MOCK_HEADERS = $(ARDUINO_MOCK_DIR)/include/arduino-mock/*.h |
| 70 | + |
| 71 | +# House-keeping build targets. |
| 72 | + |
| 73 | +all : $(TESTS) |
| 74 | + |
| 75 | +test : $(TESTS) |
| 76 | + for t in $(TESTS); do ./$$t; done; |
| 77 | + |
| 78 | +clean : |
| 79 | + rm -f $(TESTS) gmock.a gmock_main.a arduino_mock_all.a *.o |
| 80 | + |
| 81 | +# Builds gmock.a and gmock_main.a. These libraries contain both |
| 82 | +# Google Mock and Google Test. A test should link with either gmock.a |
| 83 | +# or gmock_main.a, depending on whether it defines its own main() |
| 84 | +# function. It's fine if your test only uses features from Google |
| 85 | +# Test (and not Google Mock). |
| 86 | + |
| 87 | +# Usually you shouldn't tweak such internal variables, indicated by a |
| 88 | +# trailing _. |
| 89 | +GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) |
| 90 | +GMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS) |
| 91 | +ARDUINO_MOCK_SRCS_ = $(ARDUINO_MOCK_DIR)/src/*.cc $(ARDUINO_MOCK_HEADERS) |
| 92 | + |
| 93 | +# For simplicity and to avoid depending on implementation details of |
| 94 | +# Google Mock and Google Test, the dependencies specified below are |
| 95 | +# conservative and not optimized. This is fine as Google Mock and |
| 96 | +# Google Test compile fast and for ordinary users their source rarely |
| 97 | +# changes. |
| 98 | +gtest-all.o : $(GTEST_SRCS_) |
| 99 | + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ |
| 100 | + -c $(GTEST_DIR)/src/gtest-all.cc |
| 101 | + |
| 102 | +gmock-all.o : $(GMOCK_SRCS_) |
| 103 | + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ |
| 104 | + -c $(GMOCK_DIR)/src/gmock-all.cc |
| 105 | + |
| 106 | +gmock_main.o : $(GMOCK_SRCS_) |
| 107 | + $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ |
| 108 | + -c $(GMOCK_DIR)/src/gmock_main.cc |
| 109 | + |
| 110 | +gmock.a : gmock-all.o gtest-all.o |
| 111 | + $(AR) $(ARFLAGS) $@ $^ |
| 112 | + |
| 113 | +gmock_main.a : gmock-all.o gtest-all.o gmock_main.o |
| 114 | + $(AR) $(ARFLAGS) $@ $^ |
| 115 | + |
| 116 | + |
| 117 | +# Builds Arduino mocks. |
| 118 | +ArduinoMockAll.o : $(ARDUINO_MOCK_SRCS_) |
| 119 | + $(CXX) $(CPPFLAGS) -I$(ARDUINO_MOCK_DIR) $(CXXFLAGS) -c \ |
| 120 | + $(ARDUINO_MOCK_DIR)/src/ArduinoMockAll.cc |
| 121 | + |
| 122 | +arduino_mock_all.a : ArduinoMockAll.o |
| 123 | + $(AR) $(ARFLAGS) $@ $^ |
| 124 | + |
| 125 | +# Builds shared objects. |
| 126 | + |
| 127 | +Firebase.o : $(SRC_ROOT)/Firebase.cpp |
| 128 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/Firebase.cpp |
| 129 | + |
| 130 | +FirebaseHttpClient_dummy.o : $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp |
| 131 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp |
| 132 | + |
| 133 | +# Builds tests. |
| 134 | + |
| 135 | +get-command.o : $(SRC_ROOT)/modem/get-command.cpp |
| 136 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/get-command.cpp |
| 137 | + |
| 138 | +get-command_test.o : $(TEST_DIR)/get-command_test.cpp $(GMOCK_HEADERS) |
| 139 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cpp |
| 140 | + |
| 141 | +get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \ |
| 142 | + arduino_mock_all.a |
| 143 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 144 | + |
| 145 | + |
| 146 | +set-command.o : $(SRC_ROOT)/modem/set-command.cpp |
| 147 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/set-command.cpp |
| 148 | + |
| 149 | +set-command_test.o : $(TEST_DIR)/set-command_test.cpp $(GMOCK_HEADERS) |
| 150 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cpp |
| 151 | + |
| 152 | +set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ |
| 153 | + arduino_mock_all.a |
| 154 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 155 | + |
| 156 | + |
| 157 | +remove-command.o : $(SRC_ROOT)/modem/remove-command.cpp |
| 158 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/remove-command.cpp |
| 159 | + |
| 160 | +remove-command_test.o : $(TEST_DIR)/remove-command_test.cpp $(GMOCK_HEADERS) |
| 161 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cpp |
| 162 | + |
| 163 | +remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ |
| 164 | + arduino_mock_all.a |
| 165 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 166 | + |
| 167 | + |
| 168 | +push-command.o : $(SRC_ROOT)/modem/push-command.cpp |
| 169 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/push-command.cpp |
| 170 | + |
| 171 | +push-command_test.o : $(TEST_DIR)/push-command_test.cpp $(GMOCK_HEADERS) |
| 172 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cpp |
| 173 | + |
| 174 | +push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ |
| 175 | + arduino_mock_all.a |
| 176 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 177 | + |
| 178 | +begin-command.o : $(SRC_ROOT)/modem/begin-command.cpp |
| 179 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/begin-command.cpp |
| 180 | + |
| 181 | +begin-command_test.o : $(TEST_DIR)/begin-command_test.cpp $(GMOCK_HEADERS) |
| 182 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cpp |
| 183 | + |
| 184 | +begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ |
| 185 | + arduino_mock_all.a |
| 186 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 187 | + |
| 188 | +stream-command.o : $(SRC_ROOT)/modem/stream-command.cpp |
| 189 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/stream-command.cpp |
| 190 | + |
| 191 | +stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) |
| 192 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp |
| 193 | + |
| 194 | +stream-command_test : stream-command.o stream-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ |
| 195 | + arduino_mock_all.a |
| 196 | + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ |
| 197 | + |
0 commit comments