Makefile 3.6 KB

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