1aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# A sample Makefile for building Google Test and using it in user
2aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# tests.  Please tweak it to suit your environment and project.  You
3aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# may want to move it to your project's root directory.
4aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#
5aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# SYNOPSIS:
6aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#
7aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#   make [all]  - makes everything.
8aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#   make TARGET - makes the given target.
9aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter#   make clean  - removes all files generated by make.
10aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
11aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Please tweak the following variable definitions as needed by your
12aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# project, except GTEST_HEADERS, which you can use in your own targets
13aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# but shouldn't modify.
14aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
15aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Points to the root of Google Test, relative to where this file is.
16aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Remember to tweak this if you move this file.
17aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterGTEST_DIR = ..
18aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
19aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Where to find user code.
20aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterUSER_DIR = ../samples
21aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
22aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Flags passed to the preprocessor.
23aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Set Google Test's header directory as a system directory, such that
24aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# the compiler doesn't generate warnings in Google Test headers.
25aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterCPPFLAGS += -isystem $(GTEST_DIR)/include
26aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
27aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Flags passed to the C++ compiler.
28aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterCXXFLAGS += -g -Wall -Wextra -pthread
29aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
30aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# All tests produced by this Makefile.  Remember to add new tests you
31aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# created to the list.
32aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterTESTS = sample1_unittest
33aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
34aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# All Google Test headers.  Usually you shouldn't change this
35aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# definition.
36aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterGTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
37aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter                $(GTEST_DIR)/include/gtest/internal/*.h
38aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
39aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# House-keeping build targets.
40aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
41aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchterall : $(TESTS)
42aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
43aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchterclean :
44aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	rm -f $(TESTS) gtest.a gtest_main.a *.o
45aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
46aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Builds gtest.a and gtest_main.a.
47aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
48aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Usually you shouldn't tweak such internal variables, indicated by a
49aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# trailing _.
50aa46da279e2426caf1e103eb079dfec8124c5feeCourtney GoeltzenleuchterGTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
51aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
52aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# For simplicity and to avoid depending on Google Test's
53aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# implementation details, the dependencies specified below are
54aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# conservative and not optimized.  This is fine as Google Test
55aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# compiles fast and for ordinary users its source rarely changes.
56aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtergtest-all.o : $(GTEST_SRCS_)
57aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
58aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter            $(GTEST_DIR)/src/gtest-all.cc
59aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
60aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtergtest_main.o : $(GTEST_SRCS_)
61aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
62aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter            $(GTEST_DIR)/src/gtest_main.cc
63aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
64aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtergtest.a : gtest-all.o
65aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(AR) $(ARFLAGS) $@ $^
66aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
67aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtergtest_main.a : gtest-all.o gtest_main.o
68aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(AR) $(ARFLAGS) $@ $^
69aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
70aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# Builds a sample test.  A test should link with either gtest.a or
71aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# gtest_main.a, depending on whether it defines its own main()
72aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter# function.
73aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
74aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtersample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
75aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
76aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
77aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtersample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
78aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter                     $(USER_DIR)/sample1.h $(GTEST_HEADERS)
79aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
80aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter
81aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchtersample1_unittest : sample1.o sample1_unittest.o gtest_main.a
82aa46da279e2426caf1e103eb079dfec8124c5feeCourtney Goeltzenleuchter	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
83