You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

  1. # A sample Makefile for building Google Test and using it in user
  2. # tests. Please tweak it to suit your environment and project. You
  3. # may want to move it to your project's root directory.
  4. #
  5. # SYNOPSIS:
  6. #
  7. # make [all] - makes everything.
  8. # make TARGET - makes the given target.
  9. # make clean - removes all files generated by make.
  10. # Please tweak the following variable definitions as needed by your
  11. # project, except GTEST_HEADERS, which you can use in your own targets
  12. # but shouldn't modify.
  13. # Points to the root of Google Test, relative to where this file is.
  14. # Remember to tweak this if you move this file.
  15. GTEST_DIR = ..
  16. # Where to find user code.
  17. USER_DIR = ../samples
  18. # Flags passed to the preprocessor.
  19. CPPFLAGS += -I$(GTEST_DIR)/include
  20. # Flags passed to the C++ compiler.
  21. CXXFLAGS += -g -Wall -Wextra
  22. # All tests produced by this Makefile. Remember to add new tests you
  23. # created to the list.
  24. TESTS = sample1_unittest
  25. # All Google Test headers. Usually you shouldn't change this
  26. # definition.
  27. GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
  28. $(GTEST_DIR)/include/gtest/internal/*.h
  29. # House-keeping build targets.
  30. all : $(TESTS)
  31. clean :
  32. rm -f $(TESTS) gtest.a gtest_main.a *.o
  33. # Builds gtest.a and gtest_main.a.
  34. # Usually you shouldn't tweak such internal variables, indicated by a
  35. # trailing _.
  36. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
  37. # For simplicity and to avoid depending on Google Test's
  38. # implementation details, the dependencies specified below are
  39. # conservative and not optimized. This is fine as Google Test
  40. # compiles fast and for ordinary users its source rarely changes.
  41. gtest-all.o : $(GTEST_SRCS_)
  42. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
  43. $(GTEST_DIR)/src/gtest-all.cc
  44. gtest_main.o : $(GTEST_SRCS_)
  45. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
  46. $(GTEST_DIR)/src/gtest_main.cc
  47. gtest.a : gtest-all.o
  48. $(AR) $(ARFLAGS) $@ $^
  49. gtest_main.a : gtest-all.o gtest_main.o
  50. $(AR) $(ARFLAGS) $@ $^
  51. # Builds a sample test. A test should link with either gtest.a or
  52. # gtest_main.a, depending on whether it defines its own main()
  53. # function.
  54. sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
  55. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
  56. sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
  57. $(USER_DIR)/sample1.h $(GTEST_HEADERS)
  58. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
  59. sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
  60. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@