您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

83 行
2.7 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. # Set Google Test's header directory as a system directory, such that
  20. # the compiler doesn't generate warnings in Google Test headers.
  21. CPPFLAGS += -isystem $(GTEST_DIR)/include
  22. # Flags passed to the C++ compiler.
  23. CXXFLAGS += -g -Wall -Wextra -pthread
  24. # All tests produced by this Makefile. Remember to add new tests you
  25. # created to the list.
  26. TESTS = sample1_unittest
  27. # All Google Test headers. Usually you shouldn't change this
  28. # definition.
  29. GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
  30. $(GTEST_DIR)/include/gtest/internal/*.h
  31. # House-keeping build targets.
  32. all : $(TESTS)
  33. clean :
  34. rm -f $(TESTS) gtest.a gtest_main.a *.o
  35. # Builds gtest.a and gtest_main.a.
  36. # Usually you shouldn't tweak such internal variables, indicated by a
  37. # trailing _.
  38. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
  39. # For simplicity and to avoid depending on Google Test's
  40. # implementation details, the dependencies specified below are
  41. # conservative and not optimized. This is fine as Google Test
  42. # compiles fast and for ordinary users its source rarely changes.
  43. gtest-all.o : $(GTEST_SRCS_)
  44. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
  45. $(GTEST_DIR)/src/gtest-all.cc
  46. gtest_main.o : $(GTEST_SRCS_)
  47. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
  48. $(GTEST_DIR)/src/gtest_main.cc
  49. gtest.a : gtest-all.o
  50. $(AR) $(ARFLAGS) $@ $^
  51. gtest_main.a : gtest-all.o gtest_main.o
  52. $(AR) $(ARFLAGS) $@ $^
  53. # Builds a sample test. A test should link with either gtest.a or
  54. # gtest_main.a, depending on whether it defines its own main()
  55. # function.
  56. sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
  57. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
  58. sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc \
  59. $(USER_DIR)/sample1.h $(GTEST_HEADERS)
  60. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
  61. sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
  62. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@