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