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 )
37 find_library(LLVM_PTHREAD_LIBRARY_PATH pthread)
38 if (LLVM_PTHREAD_LIBRARY_PATH)
39 list(APPEND LIBS pthread)
42 add_llvm_library(gtest
43 googletest/src/gtest-all.cc
44 googlemock/src/gmock-all.cc
50 Support # Depends on llvm::raw_ostream
52 # This is a library meant only for the build tree.
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.
59 if(CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
60 add_definitions("-Wno-suggest-override")
61 set_target_properties(gtest PROPERTIES INTERFACE_COMPILE_OPTIONS "-Wno-suggest-override")
64 if (NOT LLVM_ENABLE_THREADS)
65 target_compile_definitions(gtest PUBLIC GTEST_HAS_PTHREAD=0)
68 target_include_directories(gtest
69 PUBLIC googletest/include googlemock/include
70 PRIVATE googletest googlemock
73 add_subdirectory(UnitTestMain)
75 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
76 # link libraries for gtest and gtest_main. This means that any target, like
77 # unittests for example, that links against gtest will be forced to link
78 # against libLLVM.so. In some cases we may want to statically unittests if they
79 # need access to symbols that are marked private in libLLVM.so. The only
80 # way we can make this work is to remove libLLVM.so from the list of interface
81 # link libraries for gtest and then make gtest users responsible for explicitly
82 # adding libLLVM.so to their targets link libraries if they need it.
84 function (gtest_remove_dylib_from_link_interface target)
85 get_target_property(interface_libs ${target} INTERFACE_LINK_LIBRARIES)
87 list(REMOVE_ITEM interface_libs LLVM)
88 set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${interface_libs}")
92 gtest_remove_dylib_from_link_interface(gtest)
93 gtest_remove_dylib_from_link_interface(gtest_main)