|
Packit |
bd1cd8 |
# A sample Makefile for building both Google Mock and Google Test and
|
|
Packit |
bd1cd8 |
# using them in user tests. This file is self-contained, so you don't
|
|
Packit |
bd1cd8 |
# need to use the Makefile in Google Test's source tree. Please tweak
|
|
Packit |
bd1cd8 |
# it to suit your environment and project. You may want to move it to
|
|
Packit |
bd1cd8 |
# your project's root directory.
|
|
Packit |
bd1cd8 |
#
|
|
Packit |
bd1cd8 |
# SYNOPSIS:
|
|
Packit |
bd1cd8 |
#
|
|
Packit |
bd1cd8 |
# make [all] - makes everything.
|
|
Packit |
bd1cd8 |
# make TARGET - makes the given target.
|
|
Packit |
bd1cd8 |
# make clean - removes all files generated by make.
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Please tweak the following variable definitions as needed by your
|
|
Packit |
bd1cd8 |
# project, except GMOCK_HEADERS and GTEST_HEADERS, which you can use
|
|
Packit |
bd1cd8 |
# in your own targets but shouldn't modify.
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Points to the root of Google Test, relative to where this file is.
|
|
Packit |
bd1cd8 |
# Remember to tweak this if you move this file, or if you want to use
|
|
Packit |
bd1cd8 |
# a copy of Google Test at a different location.
|
|
Packit |
bd1cd8 |
GTEST_DIR = ../../googletest
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Points to the root of Google Mock, relative to where this file is.
|
|
Packit |
bd1cd8 |
# Remember to tweak this if you move this file.
|
|
Packit |
bd1cd8 |
GMOCK_DIR = ..
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Where to find user code.
|
|
Packit |
bd1cd8 |
USER_DIR = ../test
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Flags passed to the preprocessor.
|
|
Packit |
bd1cd8 |
# Set Google Test and Google Mock's header directories as system
|
|
Packit |
bd1cd8 |
# directories, such that the compiler doesn't generate warnings in
|
|
Packit |
bd1cd8 |
# these headers.
|
|
Packit |
bd1cd8 |
CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Flags passed to the C++ compiler.
|
|
Packit |
bd1cd8 |
CXXFLAGS += -g -Wall -Wextra -pthread
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# All tests produced by this Makefile. Remember to add new tests you
|
|
Packit |
bd1cd8 |
# created to the list.
|
|
Packit |
bd1cd8 |
TESTS = gmock_test
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# All Google Test headers. Usually you shouldn't change this
|
|
Packit |
bd1cd8 |
# definition.
|
|
Packit |
bd1cd8 |
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
|
|
Packit |
bd1cd8 |
$(GTEST_DIR)/include/gtest/internal/*.h
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# All Google Mock headers. Note that all Google Test headers are
|
|
Packit |
bd1cd8 |
# included here too, as they are #included by Google Mock headers.
|
|
Packit |
bd1cd8 |
# Usually you shouldn't change this definition.
|
|
Packit |
bd1cd8 |
GMOCK_HEADERS = $(GMOCK_DIR)/include/gmock/*.h \
|
|
Packit |
bd1cd8 |
$(GMOCK_DIR)/include/gmock/internal/*.h \
|
|
Packit |
bd1cd8 |
$(GTEST_HEADERS)
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# House-keeping build targets.
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
all : $(TESTS)
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
clean :
|
|
Packit |
bd1cd8 |
rm -f $(TESTS) gmock.a gmock_main.a *.o
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Builds gmock.a and gmock_main.a. These libraries contain both
|
|
Packit |
bd1cd8 |
# Google Mock and Google Test. A test should link with either gmock.a
|
|
Packit |
bd1cd8 |
# or gmock_main.a, depending on whether it defines its own main()
|
|
Packit |
bd1cd8 |
# function. It's fine if your test only uses features from Google
|
|
Packit |
bd1cd8 |
# Test (and not Google Mock).
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Usually you shouldn't tweak such internal variables, indicated by a
|
|
Packit |
bd1cd8 |
# trailing _.
|
|
Packit |
bd1cd8 |
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
|
|
Packit |
bd1cd8 |
GMOCK_SRCS_ = $(GMOCK_DIR)/src/*.cc $(GMOCK_HEADERS)
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# For simplicity and to avoid depending on implementation details of
|
|
Packit |
bd1cd8 |
# Google Mock and Google Test, the dependencies specified below are
|
|
Packit |
bd1cd8 |
# conservative and not optimized. This is fine as Google Mock and
|
|
Packit |
bd1cd8 |
# Google Test compile fast and for ordinary users their source rarely
|
|
Packit |
bd1cd8 |
# changes.
|
|
Packit |
bd1cd8 |
gtest-all.o : $(GTEST_SRCS_)
|
|
Packit |
bd1cd8 |
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
|
Packit |
bd1cd8 |
-c $(GTEST_DIR)/src/gtest-all.cc
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock-all.o : $(GMOCK_SRCS_)
|
|
Packit |
bd1cd8 |
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
|
Packit |
bd1cd8 |
-c $(GMOCK_DIR)/src/gmock-all.cc
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock_main.o : $(GMOCK_SRCS_)
|
|
Packit |
bd1cd8 |
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GMOCK_DIR) $(CXXFLAGS) \
|
|
Packit |
bd1cd8 |
-c $(GMOCK_DIR)/src/gmock_main.cc
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock.a : gmock-all.o gtest-all.o
|
|
Packit |
bd1cd8 |
$(AR) $(ARFLAGS) $@ $^
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock_main.a : gmock-all.o gtest-all.o gmock_main.o
|
|
Packit |
bd1cd8 |
$(AR) $(ARFLAGS) $@ $^
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
# Builds a sample test.
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock_test.o : $(USER_DIR)/gmock_test.cc $(GMOCK_HEADERS)
|
|
Packit |
bd1cd8 |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/gmock_test.cc
|
|
Packit |
bd1cd8 |
|
|
Packit |
bd1cd8 |
gmock_test : gmock_test.o gmock_main.a
|
|
Packit |
bd1cd8 |
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
|