1 ########################################################################
2 # CMake build script for Google Mock.
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'.
8 # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
9 # make it prominent in the GUI.
10 option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
12 option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
14 # A directory to find Google Test sources.
15 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
18 set(gtest_dir ../gtest)
21 # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
22 include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
24 if (COMMAND pre_project_set_up_hermetic_build)
25 # Google Test also calls hermetic setup functions from add_subdirectory,
26 # although its changes will not affect things at the current scope.
27 pre_project_set_up_hermetic_build()
30 ########################################################################
32 # Project-wide settings
34 # Name of the project.
36 # CMake files in this project can refer to the root source directory
37 # as ${gmock_SOURCE_DIR} and to the root binary directory as
38 # ${gmock_BINARY_DIR}.
39 # Language "C" is required for find_package(Threads).
41 cmake_minimum_required(VERSION 2.6.2)
43 if (COMMAND set_up_hermetic_build)
44 set_up_hermetic_build()
47 # Instructs CMake to process Google Test's CMakeLists.txt and add its
48 # targets to the current scope. We are placing Google Test's binary
49 # directory in a subdirectory of our own as VC compilation may break
50 # if they are the same (the default).
51 add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
53 # Although Google Test's CMakeLists.txt calls this function, the
54 # changes there don't affect the current scope. Therefore we have to
56 config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
58 # Adds Google Mock's and Google Test's header directories to the search path.
59 include_directories("${gmock_SOURCE_DIR}/include"
61 "${gtest_SOURCE_DIR}/include"
62 # This directory is needed to build directly from Google
64 "${gtest_SOURCE_DIR}")
66 # Summary of tuple support for Microsoft Visual Studio:
67 # Compiler version(MS) version(cmake) Support
68 # ---------- ----------- -------------- -----------------------------
69 # <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple.
70 # VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10
71 # VS 2013 12 1800 std::tr1::tuple
72 if (MSVC AND MSVC_VERSION EQUAL 1700)
73 add_definitions(/D _VARIADIC_MAX=10)
76 ########################################################################
78 # Defines the gmock & gmock_main libraries. User tests should link
81 # Google Mock libraries. We build them using more strict warnings than what
82 # are used for other targets, to ensure that Google Mock can be compiled by
83 # a user aggressive about warnings.
86 "${gtest_dir}/src/gtest-all.cc"
89 cxx_library(gmock_main
91 "${gtest_dir}/src/gtest-all.cc"
95 ########################################################################
97 # Google Mock's own tests.
99 # You can skip this section if you aren't interested in testing
100 # Google Mock itself.
102 # The tests are not built by default. To build them, set the
103 # gmock_build_tests option to ON. You can do it by running ccmake
104 # or specifying the -Dgmock_build_tests=ON flag when running cmake.
106 if (gmock_build_tests)
107 # This must be set in the root directory for the tests to be run by
108 # 'make test' or ctest.
111 ############################################################
112 # C++ tests built with standard compiler flags.
114 cxx_test(gmock-actions_test gmock_main)
115 cxx_test(gmock-cardinalities_test gmock_main)
116 cxx_test(gmock_ex_test gmock_main)
117 cxx_test(gmock-generated-actions_test gmock_main)
118 cxx_test(gmock-generated-function-mockers_test gmock_main)
119 cxx_test(gmock-generated-internal-utils_test gmock_main)
120 cxx_test(gmock-generated-matchers_test gmock_main)
121 cxx_test(gmock-internal-utils_test gmock_main)
122 cxx_test(gmock-matchers_test gmock_main)
123 cxx_test(gmock-more-actions_test gmock_main)
124 cxx_test(gmock-nice-strict_test gmock_main)
125 cxx_test(gmock-port_test gmock_main)
126 cxx_test(gmock-spec-builders_test gmock_main)
127 cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
128 cxx_test(gmock_test gmock_main)
130 if (CMAKE_USE_PTHREADS_INIT)
131 cxx_test(gmock_stress_test gmock)
134 # gmock_all_test is commented to save time building and running tests.
135 # Uncomment if necessary.
136 # cxx_test(gmock_all_test gmock_main)
138 ############################################################
139 # C++ tests built with non-standard compiler flags.
141 cxx_library(gmock_main_no_exception "${cxx_no_exception}"
142 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
144 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
145 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
147 if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010.
148 # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that
149 # conflict with our own definitions. Therefore using our own tuple does not
150 # work on those compilers.
151 cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
152 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
154 cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
155 gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
158 cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
159 gmock_main_no_exception test/gmock-more-actions_test.cc)
161 cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
162 gmock_main_no_rtti test/gmock-spec-builders_test.cc)
164 cxx_shared_library(shared_gmock_main "${cxx_default}"
165 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
167 # Tests that a binary can be built with Google Mock as a shared library. On
168 # some system configurations, it may not possible to run the binary without
169 # knowing more details about the system configurations. We do not try to run
170 # this binary. To get a more robust shared library coverage, configure with
171 # -DBUILD_SHARED_LIBS=ON.
172 cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
173 shared_gmock_main test/gmock-spec-builders_test.cc)
174 set_target_properties(shared_gmock_test_
176 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
178 ############################################################
181 cxx_executable(gmock_leak_test_ test gmock_main)
182 py_test(gmock_leak_test)
184 cxx_executable(gmock_output_test_ test gmock)
185 py_test(gmock_output_test)