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. 20GTEST_DIR = ../../googletest 21 22# Points to the location of the Google Test libraries 23GTEST_LIB_DIR = . 24 25# Points to the root of Google Mock, relative to where this file is. 26# Remember to tweak this if you move this file. 27GMOCK_DIR = .. 28 29# Where to find user code. 30USER_DIR = ../test 31 32# Flags passed to the preprocessor. 33# Set Google Test and Google Mock's header directories as system 34# directories, such that the compiler doesn't generate warnings in 35# these headers. 36CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include 37 38# Flags passed to the C++ compiler. 39CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 40 41# Google Test libraries 42GTEST_LIBS = libgtest.a libgtest_main.a libgmock.a libgmock_main.a 43 44# All tests produced by this Makefile. Remember to add new tests you 45# created to the list. 46TESTS = gmock_test 47 48# All Google Test headers. Usually you shouldn't change this 49# definition. 50GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ 51 $(GTEST_DIR)/include/gtest/internal/*.h 52 53# All Google Mock headers. Note that all Google Test headers are 54# included here too, as they are #included by Google Mock headers. 55# Usually you shouldn't change this definition. 56GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \ 57 $(GMOCK_DIR)/include/gmock/internal/*.h \ 58 $(GTEST_HEADERS) 59 60# House-keeping build targets. 61 62all : $(GTEST_LIBS) $(TESTS) 63 64clean : 65 rm -f $(GTEST_LIBS) $(TESTS) *.o 66 67# Builds gmock.a and gmock_main.a. These libraries contain both 68# Google Mock and Google Test. A test should link with either gmock.a 69# or gmock_main.a, depending on whether it defines its own main() 70# function. It's fine if your test only uses features from Google 71# Test (and not Google Mock). 72 73# Usually you shouldn't tweak such internal variables, indicated by a 74# trailing _. 75GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) 76GMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS) 77 78# For simplicity and to avoid depending on implementation details of 79# Google Mock and Google Test, the dependencies specified below are 80# conservative and not optimized. This is fine as Google Mock and 81# Google Test compile fast and for ordinary users their source rarely 82# changes. 83gtest-all.o : $(GTEST_SRCS_) 84 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 85 -c $(GTEST_DIR)/src/gtest-all.cc 86 87gtest_main.o : $(GTEST_SRCS_) 88 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 89 -c $(GTEST_DIR)/src/gtest_main.cc 90 91gmock-all.o : $(GMOCK_SRCS_) 92 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 93 -c $(GMOCK_DIR)/src/gmock-all.cc 94 95gmock_main.o : $(GMOCK_SRCS_) 96 $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 97 -c $(GMOCK_DIR)/src/gmock_main.cc 98 99libgtest.a : gtest-all.o 100 $(AR) $(ARFLAGS) $@ $^ 101 102libgtest_main.a : gtest_main.o 103 $(AR) $(ARFLAGS) $@ $^ 104 105libgmock.a : gmock-all.o 106 $(AR) $(ARFLAGS) $@ $^ 107 108libgmock_main.a : gmock_main.o 109 $(AR) $(ARFLAGS) $@ $^ 110 111# Builds a sample test. 112 113gmock_test.o : $(USER_DIR)/gmock_test.cc $(GMOCK_HEADERS) 114 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_test.cc 115 116gmock_test : gmock_test.o $(GTEST_LIBS) 117 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -L$(GTEST_LIB_DIR) -lgmock -lpthread $^ -o $@ 118