funchelpers: Add a way to invoke a callable with a list of arguments
[quassel.git] / cmake / FindGTest.cmake
1 # It is recommended that projects build GTest/GMock themselves, rather
2 # than relying on system-provided libraries. This is to ensure that the
3 # same build configuration is used for both test cases and the
4 # libraries.
5 #
6 # This find module includes bundled sources to build the GTest and GMock
7 # libraries. Since including the provided CMake build system as a
8 # subproject would not allow for proper target installation,
9 # and linking GTest as a static library poses a special kind of hell,
10 # we rely on GTest build system internals to setup targets under our
11 # control.
12 #
13 # This means that this find module will only work properly as long as
14 # the layout and the internals of the provided GTest/GMock sources
15 # do not change in incompatible ways. Thus, if the bundled sources
16 # are updated, this find script may have to be adapted, too.
17 #
18 # This find module defines one alias target GMock::GMock to depend on.
19 ########################################################################
20
21 include(FindPackageHandleStandardArgs)
22
23 set(GTEST_VERSION "1.8.1")
24
25 set(GTEST_BASE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/googletest-${GTEST_VERSION}")
26 set(GTEST_SRC_DIR "${GTEST_BASE_DIR}/googletest")
27 set(GTEST_INC_DIR "${GTEST_BASE_DIR}/googletest/include")
28 set(GMOCK_SRC_DIR "${GTEST_BASE_DIR}/googlemock")
29 set(GMOCK_INC_DIR "${GTEST_BASE_DIR}/googlemock/include")
30
31 # We don't install our tests
32 set(INSTALL_GTEST OFF)
33
34 # Link against the runtime dynamically on Windows
35 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
36
37 # Here's where it gets shaky... include GTest's CMake macros, which
38 # we'll use to setup the target with the expected compile flags.
39 include(${GTEST_SRC_DIR}/cmake/internal_utils.cmake)
40
41 # Provided by GTest, configure compile flags
42 config_compiler_and_linker()
43
44 # Create target using GTest's macro and compile flags
45 set(TARGET gtest)
46 cxx_shared_library(${TARGET}
47     ${cxx_strict}
48     ${GTEST_SRC_DIR}/src/gtest-all.cc
49     ${GMOCK_SRC_DIR}/src/gmock-all.cc
50 )
51
52 # Alias to follow our convention of namespaced targets
53 add_library(GTest::GTest ALIAS gtest)
54
55 # Set include dirs
56 target_include_directories(${TARGET} SYSTEM BEFORE
57     PUBLIC
58         ${GTEST_INC_DIR}
59         ${GMOCK_INC_DIR}
60     PRIVATE
61         ${GTEST_SRC_DIR}
62         ${GMOCK_SRC_DIR}
63 )
64
65 # Ensure symbols are exported
66 target_compile_definitions(${TARGET} INTERFACE -DGTEST_LINKED_AS_SHARED_LIBRARY=1)
67
68 # Add support for find_package
69 find_package_handle_standard_args(GTest DEFAULT_MSG GTEST_INC_DIR)