Debian Codegraph @

external/googletest/googlemock/CMakeLists.txt

raw
1 ########################################################################
2 # Note: CMake support is community-based. The maintainers do not use CMake
3 # internally.
4 #
5 # CMake build script for Google Mock.
6 #
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'.
10
11 option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
12
13 # A directory to find Google Test sources.
14 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
15 set(gtest_dir gtest)
16 else()
17 set(gtest_dir ../googletest)
18 endif()
19
20 # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
21 include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL)
22
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()
27 endif()
28
29 ########################################################################
30 #
31 # Project-wide settings
32
33 # Name of the project.
34 #
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 cmake_minimum_required(VERSION 3.6)
40 project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
41
42 if (COMMAND set_up_hermetic_build)
43 set_up_hermetic_build()
44 endif()
45
46 # Instructs CMake to process Google Test's CMakeLists.txt and add its
47 # targets to the current scope. We are placing Google Test's binary
48 # directory in a subdirectory of our own as VC compilation may break
49 # if they are the same (the default).
50 add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")
51
52
53 # These commands only run if this is the main project
54 if(CMAKE_PROJECT_NAME STREQUAL "gmock" OR CMAKE_PROJECT_NAME STREQUAL "googletest-distribution")
55 # BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to
56 # make it prominent in the GUI.
57 option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
58 else()
59 mark_as_advanced(gmock_build_tests)
60 endif()
61
62 # Although Google Test's CMakeLists.txt calls this function, the
63 # changes there don't affect the current scope. Therefore we have to
64 # call it again here.
65 config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
66
67 # Adds Google Mock's and Google Test's header directories to the search path.
68 set(gmock_build_include_dirs
69 "${gmock_SOURCE_DIR}/include"
70 "${gmock_SOURCE_DIR}"
71 "${gtest_SOURCE_DIR}/include"
72 # This directory is needed to build directly from Google Test sources.
73 "${gtest_SOURCE_DIR}")
74 include_directories(${gmock_build_include_dirs})
75
76 ########################################################################
77 #
78 # Defines the gmock & gmock_main libraries. User tests should link
79 # with one of them.
80
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.
84 if (MSVC)
85 cxx_library(gmock
86 "${cxx_strict}"
87 "${gtest_dir}/src/gtest-all.cc"
88 src/gmock-all.cc)
89
90 cxx_library(gmock_main
91 "${cxx_strict}"
92 "${gtest_dir}/src/gtest-all.cc"
93 src/gmock-all.cc
94 src/gmock_main.cc)
95 else()
96 cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
97 target_link_libraries(gmock PUBLIC gtest)
98 cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
99 target_link_libraries(gmock_main PUBLIC gmock)
100 endif()
101 # If the CMake version supports it, attach header directory information
102 # to the targets for when we are part of a parent build (ie being pulled
103 # in via add_subdirectory() rather than being a standalone build).
104 if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
105 target_include_directories(gmock SYSTEM INTERFACE
106 "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
107 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
108 target_include_directories(gmock_main SYSTEM INTERFACE
109 "$<BUILD_INTERFACE:${gmock_build_include_dirs}>"
110 "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
111 endif()
112
113 ########################################################################
114 #
115 # Install rules
116 install_project(gmock gmock_main)
117
118 ########################################################################
119 #
120 # Google Mock's own tests.
121 #
122 # You can skip this section if you aren't interested in testing
123 # Google Mock itself.
124 #
125 # The tests are not built by default. To build them, set the
126 # gmock_build_tests option to ON. You can do it by running ccmake
127 # or specifying the -Dgmock_build_tests=ON flag when running cmake.
128
129 if (gmock_build_tests)
130 # This must be set in the root directory for the tests to be run by
131 # 'make test' or ctest.
132 enable_testing()
133
134 if (WIN32)
135 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/RunTest.ps1"
136 CONTENT
137 "$project_bin = \"${CMAKE_BINARY_DIR}/bin/$<CONFIG>\"
138 $env:Path = \"$project_bin;$env:Path\"
139 & $args")
140 elseif (MINGW OR CYGWIN)
141 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/RunTest.ps1"
142 CONTENT
143 "$project_bin = (cygpath --windows ${CMAKE_BINARY_DIR}/bin)
144 $env:Path = \"$project_bin;$env:Path\"
145 & $args")
146 endif()
147
148 if (MINGW OR CYGWIN)
149 if (CMAKE_VERSION VERSION_LESS "2.8.12")
150 add_compile_options("-Wa,-mbig-obj")
151 else()
152 add_definitions("-Wa,-mbig-obj")
153 endif()
154 endif()
155
156 ############################################################
157 # C++ tests built with standard compiler flags.
158
159 cxx_test(gmock-actions_test gmock_main)
160 cxx_test(gmock-cardinalities_test gmock_main)
161 cxx_test(gmock_ex_test gmock_main)
162 cxx_test(gmock-function-mocker_test gmock_main)
163 cxx_test(gmock-generated-actions_test gmock_main)
164 cxx_test(gmock-generated-function-mockers_test gmock_main)
165 cxx_test(gmock-generated-matchers_test gmock_main)
166 cxx_test(gmock-internal-utils_test gmock_main)
167 cxx_test(gmock-matchers_test gmock_main)
168 cxx_test(gmock-more-actions_test gmock_main)
169 cxx_test(gmock-nice-strict_test gmock_main)
170 cxx_test(gmock-port_test gmock_main)
171 cxx_test(gmock-spec-builders_test gmock_main)
172 cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
173 cxx_test(gmock_test gmock_main)
174
175 if (DEFINED GTEST_HAS_PTHREAD)
176 cxx_test(gmock_stress_test gmock)
177 endif()
178
179 # gmock_all_test is commented to save time building and running tests.
180 # Uncomment if necessary.
181 # cxx_test(gmock_all_test gmock_main)
182
183 ############################################################
184 # C++ tests built with non-standard compiler flags.
185
186 if (MSVC)
187 cxx_library(gmock_main_no_exception "${cxx_no_exception}"
188 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
189
190 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
191 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
192
193 else()
194 cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc)
195 target_link_libraries(gmock_main_no_exception PUBLIC gmock)
196
197 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc)
198 target_link_libraries(gmock_main_no_rtti PUBLIC gmock)
199 endif()
200 cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
201 gmock_main_no_exception test/gmock-more-actions_test.cc)
202
203 cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
204 gmock_main_no_rtti test/gmock-spec-builders_test.cc)
205
206 cxx_shared_library(shared_gmock_main "${cxx_default}"
207 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
208
209 # Tests that a binary can be built with Google Mock as a shared library. On
210 # some system configurations, it may not possible to run the binary without
211 # knowing more details about the system configurations. We do not try to run
212 # this binary. To get a more robust shared library coverage, configure with
213 # -DBUILD_SHARED_LIBS=ON.
214 cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
215 shared_gmock_main test/gmock-spec-builders_test.cc)
216 set_target_properties(shared_gmock_test_
217 PROPERTIES
218 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
219
220 ############################################################
221 # Python tests.
222
223 cxx_executable(gmock_leak_test_ test gmock_main)
224 py_test(gmock_leak_test)
225
226 cxx_executable(gmock_output_test_ test gmock)
227 py_test(gmock_output_test)
228 endif()