Makefile.unittest 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ##===- unittests/Makefile.unittest -------------------------*- Makefile -*-===##
  2. #
  3. # The LLVM Compiler Infrastructure
  4. #
  5. # This file is distributed under the University of Illinois Open Source
  6. # License. See LICENSE.TXT for details.
  7. #
  8. ##===----------------------------------------------------------------------===##
  9. #
  10. # This file is included by all of the unit test makefiles.
  11. #
  12. ##===----------------------------------------------------------------------===##
  13. ifndef MAKEFILE_UNITTEST_NO_INCLUDE_COMMON
  14. include $(LEVEL)/Makefile.common
  15. endif
  16. # Clean up out-of-tree stray unittests for Lit not to pick one up.
  17. .PHONY: cleanup-local
  18. cleanup-local:
  19. -$(Verb) $(FIND) $(filter-out $(PARALLEL_DIRS), $(wildcard *)) -type f \
  20. -path '*/$(BuildMode)/*Tests$(EXEEXT)' \
  21. -exec rm -f '{}' \;
  22. all:: cleanup-local
  23. clean:: cleanup-local
  24. # Set up variables for building a unit test.
  25. ifdef TESTNAME
  26. LLVMUnitTestExe = $(BuildMode)/$(TESTNAME)Tests$(EXEEXT)
  27. # Note that these flags are duplicated when building GoogleTest itself in
  28. # utils/unittest/googletest/Makefile; ensure that any changes are made to both.
  29. CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include
  30. CPP.Flags += $(NO_MISSING_FIELD_INITIALIZERS) $(NO_VARIADIC_MACROS)
  31. CPP.Flags += -DGTEST_HAS_RTTI=0
  32. # libstdc++'s TR1 <tuple> header depends on RTTI and uses C++'0x features not
  33. # supported by Clang, so force googletest to use its own tuple implementation.
  34. CPP.Flags += -DGTEST_USE_OWN_TR1_TUPLE
  35. # Disable pthreads if LLVM was configured without them.
  36. ifneq ($(HAVE_PTHREAD), 1)
  37. CPP.Flags += -DGTEST_HAS_PTHREAD=0
  38. endif
  39. TESTLIBS = -lgtest -lgtest_main
  40. ifeq ($(ENABLE_SHARED), 1)
  41. ifneq (,$(RPATH))
  42. # Add the absolute path to the dynamic library. This is ok because
  43. # we'll never install unittests.
  44. LD.Flags += $(RPATH) -Wl,$(SharedLibDir)
  45. endif
  46. endif
  47. $(LLVMUnitTestExe): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths)
  48. $(Echo) Linking $(BuildMode) unit test $(TESTNAME) $(StripWarnMsg)
  49. $(Verb) $(Link) -o $@ $(TOOLLINKOPTS) $(ObjectsO) $(ProjLibsOptions) \
  50. $(TESTLIBS) $(LLVMLibsOptions) $(ExtraLibs) $(TOOLLINKOPTSB) $(LIBS)
  51. $(Echo) ======= Finished Linking $(BuildMode) Unit test $(TESTNAME) \
  52. $(StripWarnMsg)
  53. all:: $(LLVMUnitTestExe)
  54. unitcheck:: $(LLVMUnitTestExe)
  55. $(LLVMUnitTestExe)
  56. endif