1########################################################################
2# CMake build script for Google Mock.
3#
4# To run the tests for Google Mock itself on Linux, use 'make test' or
5# ctest.  You can select which tests to run using 'ctest -R regex'.
6# For more options, run 'ctest --help'.
7
8# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
9# make it prominent in the GUI.
10option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
11
12# Forces BUILD_SHARED_LIBS to OFF as Google Mock currently does not support
13# working in a DLL.
14# TODO(vladl@google.com): Implement building gMock as a DLL.
15set(BUILD_SHARED_LIBS OFF)
16
17option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
18
19# A directory to find Google Test sources.
20if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
21  set(gtest_dir gtest)
22else()
23  set(gtest_dir ../gtest)
24endif()
25
26# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
27include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
28
29if (COMMAND pre_project_set_up_hermetic_build)
30  # Google Test also calls hermetic setup functions from add_subdirectory,
31  # although its changes will not affect things at the current scope.
32  pre_project_set_up_hermetic_build()
33endif()
34
35########################################################################
36#
37# Project-wide settings
38
39# Name of the project.
40#
41# CMake files in this project can refer to the root source directory
42# as ${gmock_SOURCE_DIR} and to the root binary directory as
43# ${gmock_BINARY_DIR}.
44# Language "C" is required for find_package(Threads).
45project(gmock CXX C)
46cmake_minimum_required(VERSION 2.6.2)
47
48if (COMMAND set_up_hermetic_build)
49  set_up_hermetic_build()
50endif()
51
52# Instructs CMake to process Google Test's CMakeLists.txt and add its
53# targets to the current scope.  We are placing Google Test's binary
54# directory in a subdirectory of our own as VC compilation may break
55# if they are the same (the default).
56add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
57
58# Although Google Test's CMakeLists.txt calls this function, the
59# changes there don't affect the current scope.  Therefore we have to
60# call it again here.
61config_compiler_and_linker()  # from ${gtest_dir}/cmake/internal_utils.cmake
62
63# Adds Google Mock's and Google Test's header directories to the search path.
64include_directories("${gmock_SOURCE_DIR}/include"
65                    "${gmock_SOURCE_DIR}"
66                    "${gtest_SOURCE_DIR}/include"
67                    # This directory is needed to build directly from Google
68                    # Test sources.
69                    "${gtest_SOURCE_DIR}")
70
71########################################################################
72#
73# Defines the gmock & gmock_main libraries.  User tests should link
74# with one of them.
75
76# Google Mock libraries.  We build them using more strict warnings than what
77# are used for other targets, to ensure that Google Mock can be compiled by
78# a user aggressive about warnings.
79cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
80target_link_libraries(gmock gtest)
81
82cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
83target_link_libraries(gmock_main gmock)
84
85########################################################################
86#
87# Google Mock's own tests.
88#
89# You can skip this section if you aren't interested in testing
90# Google Mock itself.
91#
92# The tests are not built by default.  To build them, set the
93# gmock_build_tests option to ON.  You can do it by running ccmake
94# or specifying the -Dgmock_build_tests=ON flag when running cmake.
95
96if (gmock_build_tests)
97  # This must be set in the root directory for the tests to be run by
98  # 'make test' or ctest.
99  enable_testing()
100
101  ############################################################
102  # C++ tests built with standard compiler flags.
103
104  cxx_test(gmock-actions_test gmock_main)
105  cxx_test(gmock-cardinalities_test gmock_main)
106  cxx_test(gmock-generated-actions_test gmock_main)
107  cxx_test(gmock-generated-function-mockers_test gmock_main)
108  cxx_test(gmock-generated-internal-utils_test gmock_main)
109  cxx_test(gmock-generated-matchers_test gmock_main)
110  cxx_test(gmock-internal-utils_test gmock_main)
111  cxx_test(gmock-matchers_test gmock_main)
112  cxx_test(gmock-more-actions_test gmock_main)
113  cxx_test(gmock-nice-strict_test gmock_main)
114  cxx_test(gmock-port_test gmock_main)
115  cxx_test(gmock-spec-builders_test gmock_main)
116  cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
117  # cxx_test(gmock_stress_test gmock)
118  cxx_test(gmock_test gmock_main)
119
120  # gmock_all_test is commented to save time building and running tests.
121  # Uncomment if necessary.
122  # cxx_test(gmock_all_test gmock_main)
123
124  ############################################################
125  # C++ tests built with non-standard compiler flags.
126
127  cxx_library(gmock_main_no_exception "${cxx_no_exception}"
128    "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
129  cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
130    "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
131  cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
132    "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
133
134  cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
135    gmock_main_no_exception test/gmock-more-actions_test.cc)
136
137  cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
138    gmock_main_no_rtti test/gmock-spec-builders_test.cc)
139
140  cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
141    gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
142
143  ############################################################
144  # Python tests.
145
146  cxx_executable(gmock_leak_test_ test gmock_main)
147  py_test(gmock_leak_test)
148
149  cxx_executable(gmock_output_test_ test gmock)
150  py_test(gmock_output_test)
151endif()
152