Makefile revision 13481
113481Sgiacomo.travaglini@arm.com# A sample Makefile for building both Google Mock and Google Test and 213481Sgiacomo.travaglini@arm.com# using them in user tests. This file is self-contained, so you don't 313481Sgiacomo.travaglini@arm.com# need to use the Makefile in Google Test's source tree. Please tweak 413481Sgiacomo.travaglini@arm.com# it to suit your environment and project. You may want to move it to 513481Sgiacomo.travaglini@arm.com# your project's root directory. 613481Sgiacomo.travaglini@arm.com# 713481Sgiacomo.travaglini@arm.com# SYNOPSIS: 813481Sgiacomo.travaglini@arm.com# 913481Sgiacomo.travaglini@arm.com# make [all] - makes everything. 1013481Sgiacomo.travaglini@arm.com# make TARGET - makes the given target. 1113481Sgiacomo.travaglini@arm.com# make clean - removes all files generated by make. 1213481Sgiacomo.travaglini@arm.com 1313481Sgiacomo.travaglini@arm.com# Please tweak the following variable definitions as needed by your 1413481Sgiacomo.travaglini@arm.com# project, except GMOCK_HEADERS and GTEST_HEADERS, which you can use 1513481Sgiacomo.travaglini@arm.com# in your own targets but shouldn't modify. 1613481Sgiacomo.travaglini@arm.com 1713481Sgiacomo.travaglini@arm.com# Points to the root of Google Test, relative to where this file is. 1813481Sgiacomo.travaglini@arm.com# Remember to tweak this if you move this file, or if you want to use 1913481Sgiacomo.travaglini@arm.com# a copy of Google Test at a different location. 2013481Sgiacomo.travaglini@arm.comGTEST_DIR = ../../googletest 2113481Sgiacomo.travaglini@arm.com 2213481Sgiacomo.travaglini@arm.com# Points to the root of Google Mock, relative to where this file is. 2313481Sgiacomo.travaglini@arm.com# Remember to tweak this if you move this file. 2413481Sgiacomo.travaglini@arm.comGMOCK_DIR = .. 2513481Sgiacomo.travaglini@arm.com 2613481Sgiacomo.travaglini@arm.com# Where to find user code. 2713481Sgiacomo.travaglini@arm.comUSER_DIR = ../test 2813481Sgiacomo.travaglini@arm.com 2913481Sgiacomo.travaglini@arm.com# Flags passed to the preprocessor. 3013481Sgiacomo.travaglini@arm.com# Set Google Test and Google Mock's header directories as system 3113481Sgiacomo.travaglini@arm.com# directories, such that the compiler doesn't generate warnings in 3213481Sgiacomo.travaglini@arm.com# these headers. 3313481Sgiacomo.travaglini@arm.comCPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include 3413481Sgiacomo.travaglini@arm.com 3513481Sgiacomo.travaglini@arm.com# Flags passed to the C++ compiler. 3613481Sgiacomo.travaglini@arm.comCXXFLAGS += -g -Wall -Wextra -pthread 3713481Sgiacomo.travaglini@arm.com 3813481Sgiacomo.travaglini@arm.com# All tests produced by this Makefile. Remember to add new tests you 3913481Sgiacomo.travaglini@arm.com# created to the list. 4013481Sgiacomo.travaglini@arm.comTESTS = gmock_test 4113481Sgiacomo.travaglini@arm.com 4213481Sgiacomo.travaglini@arm.com# All Google Test headers. Usually you shouldn't change this 4313481Sgiacomo.travaglini@arm.com# definition. 4413481Sgiacomo.travaglini@arm.comGTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ 4513481Sgiacomo.travaglini@arm.com $(GTEST_DIR)/include/gtest/internal/*.h 4613481Sgiacomo.travaglini@arm.com 4713481Sgiacomo.travaglini@arm.com# All Google Mock headers. Note that all Google Test headers are 4813481Sgiacomo.travaglini@arm.com# included here too, as they are #included by Google Mock headers. 4913481Sgiacomo.travaglini@arm.com# Usually you shouldn't change this definition. 5013481Sgiacomo.travaglini@arm.comGMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \ 5113481Sgiacomo.travaglini@arm.com $(GMOCK_DIR)/include/gmock/internal/*.h \ 5213481Sgiacomo.travaglini@arm.com $(GTEST_HEADERS) 5313481Sgiacomo.travaglini@arm.com 5413481Sgiacomo.travaglini@arm.com# House-keeping build targets. 5513481Sgiacomo.travaglini@arm.com 5613481Sgiacomo.travaglini@arm.comall : $(TESTS) 5713481Sgiacomo.travaglini@arm.com 5813481Sgiacomo.travaglini@arm.comclean : 5913481Sgiacomo.travaglini@arm.com rm -f $(TESTS) gmock.a gmock_main.a *.o 6013481Sgiacomo.travaglini@arm.com 6113481Sgiacomo.travaglini@arm.com# Builds gmock.a and gmock_main.a. These libraries contain both 6213481Sgiacomo.travaglini@arm.com# Google Mock and Google Test. A test should link with either gmock.a 6313481Sgiacomo.travaglini@arm.com# or gmock_main.a, depending on whether it defines its own main() 6413481Sgiacomo.travaglini@arm.com# function. It's fine if your test only uses features from Google 6513481Sgiacomo.travaglini@arm.com# Test (and not Google Mock). 6613481Sgiacomo.travaglini@arm.com 6713481Sgiacomo.travaglini@arm.com# Usually you shouldn't tweak such internal variables, indicated by a 6813481Sgiacomo.travaglini@arm.com# trailing _. 6913481Sgiacomo.travaglini@arm.comGTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) 7013481Sgiacomo.travaglini@arm.comGMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS) 7113481Sgiacomo.travaglini@arm.com 7213481Sgiacomo.travaglini@arm.com# For simplicity and to avoid depending on implementation details of 7313481Sgiacomo.travaglini@arm.com# Google Mock and Google Test, the dependencies specified below are 7413481Sgiacomo.travaglini@arm.com# conservative and not optimized. This is fine as Google Mock and 7513481Sgiacomo.travaglini@arm.com# Google Test compile fast and for ordinary users their source rarely 7613481Sgiacomo.travaglini@arm.com# changes. 7713481Sgiacomo.travaglini@arm.comgtest-all.o : $(GTEST_SRCS_) 7813481Sgiacomo.travaglini@arm.com $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 7913481Sgiacomo.travaglini@arm.com -c $(GTEST_DIR)/src/gtest-all.cc 8013481Sgiacomo.travaglini@arm.com 8113481Sgiacomo.travaglini@arm.comgmock-all.o : $(GMOCK_SRCS_) 8213481Sgiacomo.travaglini@arm.com $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 8313481Sgiacomo.travaglini@arm.com -c $(GMOCK_DIR)/src/gmock-all.cc 8413481Sgiacomo.travaglini@arm.com 8513481Sgiacomo.travaglini@arm.comgmock_main.o : $(GMOCK_SRCS_) 8613481Sgiacomo.travaglini@arm.com $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \ 8713481Sgiacomo.travaglini@arm.com -c $(GMOCK_DIR)/src/gmock_main.cc 8813481Sgiacomo.travaglini@arm.com 8913481Sgiacomo.travaglini@arm.comgmock.a : gmock-all.o gtest-all.o 9013481Sgiacomo.travaglini@arm.com $(AR) $(ARFLAGS) $@ $^ 9113481Sgiacomo.travaglini@arm.com 9213481Sgiacomo.travaglini@arm.comgmock_main.a : gmock-all.o gtest-all.o gmock_main.o 9313481Sgiacomo.travaglini@arm.com $(AR) $(ARFLAGS) $@ $^ 9413481Sgiacomo.travaglini@arm.com 9513481Sgiacomo.travaglini@arm.com# Builds a sample test. 9613481Sgiacomo.travaglini@arm.com 9713481Sgiacomo.travaglini@arm.comgmock_test.o : $(USER_DIR)/gmock_test.cc $(GMOCK_HEADERS) 9813481Sgiacomo.travaglini@arm.com $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_test.cc 9913481Sgiacomo.travaglini@arm.com 10013481Sgiacomo.travaglini@arm.comgmock_test : gmock_test.o gmock_main.a 10113481Sgiacomo.travaglini@arm.com $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ 102