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:${CMAKE_INSTALL_INCLUDEDIR}/llvm-gtest/>
81 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/llvm-gmock/>
82 PRIVATE googletest googlemock
85 add_subdirectory(UnitTestMain)
87 if (LLVM_INSTALL_GTEST)
88 install(DIRECTORY googletest/include/gtest/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gtest/gtest/" COMPONENT llvm_gtest)
89 install(DIRECTORY googlemock/include/gmock/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-gmock/gmock/" COMPONENT llvm_gtest)
92 # When LLVM_LINK_LLVM_DYLIB is enabled, libLLVM.so is added to the interface
93 # link libraries for gtest and gtest_main. This means that any target, like
94 # unittests for example, that links against gtest will be forced to link
95 # against libLLVM.so. In some cases we may want to statically unittests if they
96 # need access to symbols that are marked private in libLLVM.so. The only
97 # way we can make this work is to remove libLLVM.so from the list of interface
98 # link libraries for gtest and then make gtest users responsible for explicitly
99 # adding libLLVM.so to their targets link libraries if they need it.
101 function (gtest_remove_dylib_from_link_interface target)
102 get_target_property(interface_libs ${target} INTERFACE_LINK_LIBRARIES)
104 list(REMOVE_ITEM interface_libs LLVM)
105 set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${interface_libs}")
109 gtest_remove_dylib_from_link_interface(llvm_gtest)
110 gtest_remove_dylib_from_link_interface(llvm_gtest_main)