1 ########################################################################
2 # Experimental CMake build script for Google Test.
4 # Consider this a prototype. It will change drastically. For now,
5 # this is only for people on the cutting edge.
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 ########################################################################
12 # Project-wide settings
15 add_definitions(-DGTEST_OS_WINDOWS=1)
18 # Google Test requires headers which need _ALL_SOURCE to build on AIX
19 if (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
20 remove_definitions("-D_XOPEN_SOURCE=700")
21 add_definitions("-D_ALL_SOURCE")
24 if(SUPPORTS_VARIADIC_MACROS_FLAG)
25 add_definitions("-Wno-variadic-macros")
27 if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG)
28 add_definitions("-Wno-gnu-zero-variadic-macro-arguments")
30 if(CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG)
31 add_definitions("-Wno-covered-switch-default")
34 set(LLVM_REQUIRES_RTTI 1)
35 add_definitions( -DGTEST_HAS_RTTI=0 )
38 list(APPEND LIBS pthread)
41 # Do not build unittest libraries automatically, they will be pulled in
42 # by unittests if these are built.
44 set(BUILDTREE_ONLY BUILDTREE_ONLY)
45 set(EXCLUDE_FROM_ALL ON)
46 if (LLVM_INSTALL_GTEST)
47 set(EXCLUDE_FROM_ALL OFF)
48 set(BUILDTREE_ONLY "")
51 add_llvm_library(llvm_gtest
52 googletest/src/gtest-all.cc
53 googlemock/src/gmock-all.cc
59 Support # Depends on llvm::raw_ostream
61 # This is a library meant only for the build tree.
65 # The googletest and googlemock sources don't presently use the 'override'
66 # keyword, which leads to lots of warnings from -Wsuggest-override. Disable
67 # that warning here for any targets that link to gtest.
68 if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
69 add_definitions("-Wno-suggest-override")
70 set_target_properties(llvm_gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
73 if (NOT LLVM_ENABLE_THREADS)
74 target_compile_definitions(llvm_gtest PUBLIC GTEST_HAS_PTHREAD=0)
77 target_include_directories(llvm_gtest
78 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googletest/include>
79 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/googlemock/include>
80 $<INSTALL_INTERFACE:include/llvm-gtest/>
81 $<INSTALL_INTERFACE:include/llvm-gmock/>
82 PRIVATE googletest googlemock
85 add_subdirectory(UnitTestMain)
87 if (LLVM_INSTALL_GTEST)
88 install(TARGETS llvm_gtest llvm_gtest_main LLVMTestingSupport LLVMTestingAnnotations
89 ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT llvm_gtest)
90 install(DIRECTORY googletest/include/gtest/ DESTINATION include/llvm-gtest/gtest/ COMPONENT llvm_gtest)
91 install(DIRECTORY googlemock/include/gmock/ DESTINATION include/llvm-gmock/gmock/ COMPONENT llvm_gtest)
94 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
95 # link libraries for gtest and gtest_main. This means that any target, like
96 # unittests for example, that links against gtest will be forced to link
97 # against libLLVM.so. In some cases we may want to statically unittests if they
98 # need access to symbols that are marked private in libLLVM.so. The only
99 # way we can make this work is to remove libLLVM.so from the list of interface
100 # link libraries for gtest and then make gtest users responsible for explicitly
101 # adding libLLVM.so to their targets link libraries if they need it.
103 function (gtest_remove_dylib_from_link_interface target)
104 get_target_property(interface_libs ${target} INTERFACE_LINK_LIBRARIES)
106 list(REMOVE_ITEM interface_libs LLVM)
107 set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${interface_libs}")
111 gtest_remove_dylib_from_link_interface(llvm_gtest)
112 gtest_remove_dylib_from_link_interface(llvm_gtest_main)