• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1########################################################################
2# Experimental CMake build script for Google Test.
3#
4# Consider this a prototype.  It will change drastically.  For now,
5# this is only for people on the cutting edge.
6#
7# To run the tests for Google Test itself on Linux, use 'make test' or
8# ctest.  You can select which tests to run using 'ctest -R regex'.
9# For more options, run 'ctest --help'.
10########################################################################
11#
12# Project-wide settings
13
14if(WIN32)
15  add_definitions(-DGTEST_OS_WINDOWS=1)
16endif()
17
18# Google Test requires headers which need _ALL_SOURCE to build on AIX
19if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
20  remove_definitions("-D_XOPEN_SOURCE=700")
21  add_definitions("-D_ALL_SOURCE")
22endif()
23
24if(SUPPORTS_VARIADIC_MACROS_FLAG)
25  add_definitions("-Wno-variadic-macros")
26endif()
27if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
28  add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
29endif()
30if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
31  add_definitions("-Wno-covered-switch-default")
32endif()
33
34set(LLVM_REQUIRES_RTTI 1)
35add_definitions( -DGTEST_HAS_RTTI=0 )
36
37find_library(LLVM_PTHREAD_LIBRARY_PATH pthread)
38if (LLVM_PTHREAD_LIBRARY_PATH)
39  list(APPEND LIBS pthread)
40endif()
41
42add_llvm_library(gtest
43  googletest/src/gtest-all.cc
44  googlemock/src/gmock-all.cc
45
46  LINK_LIBS
47  ${LIBS}
48
49  LINK_COMPONENTS
50  Support # Depends on llvm::raw_ostream
51
52  # This is a library meant only for the build tree.
53  BUILDTREE_ONLY
54)
55
56# The googletest and googlemock sources don't presently use the 'override'
57# keyword, which leads to lots of warnings from -Wsuggest-override. Disable
58# that warning here for any targets that link to gtest.
59if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
60  add_definitions("-Wno-suggest-override")
61  set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
62endif()
63
64# Gtest 1.8.0 uses tr1/tuple which is deprecated on MSVC, so we force it off.
65target_compile_definitions(gtest PUBLIC GTEST_HAS_TR1_TUPLE=0)
66
67if (NOT LLVM_ENABLE_THREADS)
68  target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
69endif ()
70
71target_include_directories(gtest
72  PUBLIC googletest/include googlemock/include
73  PRIVATE googletest googlemock
74  )
75
76add_subdirectory(UnitTestMain)
77
78# When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
79# link libraries for gtest and gtest_main.  This means that any target, like
80# unittests for example, that links against gtest will be forced to link
81# against libLLVM.so.  In some cases we may want to statically unittests if they
82# need access to symbols that are marked private in libLLVM.so.  The only
83# way we can make this work is to remove libLLVM.so from the list of interface
84# link libraries for gtest and then make gtest users responsible for explicitly
85# adding libLLVM.so to their targets link libraries if they need it.
86
87function (gtest_remove_dylib_from_link_interface target)
88  get_target_property(interface_libs ${target} INTERFACE_LINK_LIBRARIES)
89  if (interface_libs)
90    list(REMOVE_ITEM interface_libs LLVM)
91    set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${interface_libs}")
92  endif()
93endfunction()
94
95gtest_remove_dylib_from_link_interface(gtest)
96gtest_remove_dylib_from_link_interface(gtest_main)
97