1 ########################################################################
2 # Note: CMake support is community-based. The maintainers do not use CMake
5 # CMake build script for Google Mock.
7 # To run the tests for Google Mock 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'.
11 option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
13 # A directory to find Google Test sources.
14 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
17 set(gtest_dir ../googletest)
20 # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
21 include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
23 if (COMMAND pre_project_set_up_hermetic_build)
24 # Google Test also calls hermetic setup functions from add_subdirectory,
25 # although its changes will not affect things at the current scope.
26 pre_project_set_up_hermetic_build()
29 ########################################################################
31 # Project-wide settings
33 # Name of the project.
35 # CMake files in this project can refer to the root source directory
36 # as ${gmock_SOURCE_DIR} and to the root binary directory as
37 # ${gmock_BINARY_DIR}.
38 # Language "C" is required for find_package(Threads).
39 if (CMAKE_VERSION VERSION_LESS 3.0)
42 cmake_policy(SET CMP0048 NEW)
43 project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
45 cmake_minimum_required(VERSION 2.8.12)
47 if (COMMAND set_up_hermetic_build)
48 set_up_hermetic_build()
51 # Instructs CMake to process Google Test's CMakeLists.txt and add its
52 # targets to the current scope. We are placing Google Test's binary
53 # directory in a subdirectory of our own as VC compilation may break
54 # if they are the same (the default).
55 add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
58 # These commands only run if this is the main project
59 if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
60 # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
61 # make it prominent in the GUI.
62 option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
64 mark_as_advanced(gmock_build_tests)
67 # Although Google Test's CMakeLists.txt calls this function, the
68 # changes there don't affect the current scope. Therefore we have to
70 config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
72 # Adds Google Mock's and Google Test's header directories to the search path.
73 set(gmock_build_include_dirs
74 "${gmock_SOURCE_DIR}/include"
76 "${gtest_SOURCE_DIR}/include"
77 # This directory is needed to build directly from Google Test sources.
78 "${gtest_SOURCE_DIR}")
79 include_directories(${gmock_build_include_dirs})
81 ########################################################################
83 # Defines the gmock & gmock_main libraries. User tests should link
86 # Google Mock libraries. We build them using more strict warnings than what
87 # are used for other targets, to ensure that Google Mock can be compiled by
88 # a user aggressive about warnings.
92 "${gtest_dir}/src/gtest-all.cc"
95 cxx_library(gmock_main
97 "${gtest_dir}/src/gtest-all.cc"
101 cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
102 target_link_libraries(gmock PUBLIC gtest)
103 set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION})
104 cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
105 target_link_libraries(gmock_main PUBLIC gmock)
106 set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
108 # If the CMake version supports it, attach header directory information
109 # to the targets for when we are part of a parent build (ie being pulled
110 # in via add_subdirectory() rather than being a standalone build).
111 if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
112 target_include_directories(gmock SYSTEM INTERFACE
113 "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
114 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
115 target_include_directories(gmock_main SYSTEM INTERFACE
116 "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
117 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
120 ########################################################################
123 install_project(gmock gmock_main)
125 ########################################################################
127 # Google Mock's own tests.
129 # You can skip this section if you aren't interested in testing
130 # Google Mock itself.
132 # The tests are not built by default. To build them, set the
133 # gmock_build_tests option to ON. You can do it by running ccmake
134 # or specifying the -Dgmock_build_tests=ON flag when running cmake.
136 if (gmock_build_tests)
137 # This must be set in the root directory for the tests to be run by
138 # 'make test' or ctest.
142 if (CMAKE_VERSION VERSION_LESS "2.8.12")
143 add_compile_options("-Wa,-mbig-obj")
145 add_definitions("-Wa,-mbig-obj")
149 ############################################################
150 # C++ tests built with standard compiler flags.
152 cxx_test(gmock-actions_test gmock_main)
153 cxx_test(gmock-cardinalities_test gmock_main)
154 cxx_test(gmock_ex_test gmock_main)
155 cxx_test(gmock-function-mocker_test gmock_main)
156 cxx_test(gmock-internal-utils_test gmock_main)
157 cxx_test(gmock-matchers_test gmock_main)
158 cxx_test(gmock-more-actions_test gmock_main)
159 cxx_test(gmock-nice-strict_test gmock_main)
160 cxx_test(gmock-port_test gmock_main)
161 cxx_test(gmock-spec-builders_test gmock_main)
162 cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
163 cxx_test(gmock_test gmock_main)
165 if (DEFINED GTEST_HAS_PTHREAD)
166 cxx_test(gmock_stress_test gmock)
169 # gmock_all_test is commented to save time building and running tests.
170 # Uncomment if necessary.
171 # cxx_test(gmock_all_test gmock_main)
173 ############################################################
174 # C++ tests built with non-standard compiler flags.
177 cxx_library(gmock_main_no_exception "${cxx_no_exception}"
178 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
180 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
181 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
184 cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
185 target_link_libraries(gmock_main_no_exception PUBLIC gmock)
187 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
188 target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
190 cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
191 gmock_main_no_exception test/gmock-more-actions_test.cc)
193 cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
194 gmock_main_no_rtti test/gmock-spec-builders_test.cc)
196 cxx_shared_library(shared_gmock_main "${cxx_default}"
197 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
199 # Tests that a binary can be built with Google Mock as a shared library. On
200 # some system configurations, it may not possible to run the binary without
201 # knowing more details about the system configurations. We do not try to run
202 # this binary. To get a more robust shared library coverage, configure with
203 # -DBUILD_SHARED_LIBS=ON.
204 cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
205 shared_gmock_main test/gmock-spec-builders_test.cc)
206 set_target_properties(shared_gmock_test_
208 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
210 ############################################################
213 cxx_executable(gmock_leak_test_ test gmock_main)
214 py_test(gmock_leak_test)
216 cxx_executable(gmock_output_test_ test gmock)
217 py_test(gmock_output_test)