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 12option(gmock_build_tests "Build all of Google Mock's own tests." OFF) 13 14# A directory to find Google Test sources. 15if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") 16 set(gtest_dir gtest) 17else() 18 set(gtest_dir ../googletest) 19endif() 20 21# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). 22include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) 23 24if (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() 28endif() 29 30######################################################################## 31# 32# Project-wide settings 33 34# Name of the project. 35# 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). 40if (CMAKE_VERSION VERSION_LESS 3.0) 41 project(gmock CXX C) 42else() 43 cmake_policy(SET CMP0048 NEW) 44 project(gmock VERSION 1.9.0 LANGUAGES CXX C) 45endif() 46cmake_minimum_required(VERSION 2.6.4) 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# Summary of tuple support for Microsoft Visual Studio: 72# Compiler version(MS) version(cmake) Support 73# ---------- ----------- -------------- ----------------------------- 74# <= VS 2010 <= 10 <= 1600 Use Google Tests's own tuple. 75# VS 2012 11 1700 std::tr1::tuple + _VARIADIC_MAX=10 76# VS 2013 12 1800 std::tr1::tuple 77# VS 2015 14 1900 std::tuple 78# VS 2017 15 >= 1910 std::tuple 79if (MSVC AND MSVC_VERSION EQUAL 1700) 80 add_definitions(/D _VARIADIC_MAX=10) 81endif() 82 83######################################################################## 84# 85# Defines the gmock & gmock_main libraries. User tests should link 86# with one of them. 87 88# Google Mock libraries. We build them using more strict warnings than what 89# are used for other targets, to ensure that Google Mock can be compiled by 90# a user aggressive about warnings. 91cxx_library(gmock 92 "${cxx_strict}" 93 "${gtest_dir}/src/gtest-all.cc" 94 src/gmock-all.cc) 95 96cxx_library(gmock_main 97 "${cxx_strict}" 98 "${gtest_dir}/src/gtest-all.cc" 99 src/gmock-all.cc 100 src/gmock_main.cc) 101 102# If the CMake version supports it, attach header directory information 103# to the targets for when we are part of a parent build (ie being pulled 104# in via add_subdirectory() rather than being a standalone build). 105if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") 106 target_include_directories(gmock SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include") 107 target_include_directories(gmock_main SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include") 108endif() 109 110######################################################################## 111# 112# Install rules 113if(INSTALL_GMOCK) 114 install(TARGETS gmock gmock_main 115 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 116 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 117 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 118 install(DIRECTORY ${gmock_SOURCE_DIR}/include/gmock 119 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 120 121 # configure and install pkgconfig files 122 configure_file( 123 cmake/gmock.pc.in 124 "${CMAKE_BINARY_DIR}/gmock.pc" 125 @ONLY) 126 configure_file( 127 cmake/gmock_main.pc.in 128 "${CMAKE_BINARY_DIR}/gmock_main.pc" 129 @ONLY) 130 install(FILES "${CMAKE_BINARY_DIR}/gmock.pc" "${CMAKE_BINARY_DIR}/gmock_main.pc" 131 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 132endif() 133 134######################################################################## 135# 136# Google Mock's own tests. 137# 138# You can skip this section if you aren't interested in testing 139# Google Mock itself. 140# 141# The tests are not built by default. To build them, set the 142# gmock_build_tests option to ON. You can do it by running ccmake 143# or specifying the -Dgmock_build_tests=ON flag when running cmake. 144 145if (gmock_build_tests) 146 # This must be set in the root directory for the tests to be run by 147 # 'make test' or ctest. 148 enable_testing() 149 150 ############################################################ 151 # C++ tests built with standard compiler flags. 152 153 cxx_test(gmock-actions_test gmock_main) 154 cxx_test(gmock-cardinalities_test gmock_main) 155 cxx_test(gmock_ex_test gmock_main) 156 cxx_test(gmock-generated-actions_test gmock_main) 157 cxx_test(gmock-generated-function-mockers_test gmock_main) 158 cxx_test(gmock-generated-internal-utils_test gmock_main) 159 cxx_test(gmock-generated-matchers_test gmock_main) 160 cxx_test(gmock-internal-utils_test gmock_main) 161 cxx_test(gmock-matchers_test gmock_main) 162 cxx_test(gmock-more-actions_test gmock_main) 163 cxx_test(gmock-nice-strict_test gmock_main) 164 cxx_test(gmock-port_test gmock_main) 165 cxx_test(gmock-spec-builders_test gmock_main) 166 cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) 167 cxx_test(gmock_test gmock_main) 168 169 if (DEFINED GTEST_HAS_PTHREAD) 170 cxx_test(gmock_stress_test gmock) 171 endif() 172 173 # gmock_all_test is commented to save time building and running tests. 174 # Uncomment if necessary. 175 # cxx_test(gmock_all_test gmock_main) 176 177 ############################################################ 178 # C++ tests built with non-standard compiler flags. 179 180 cxx_library(gmock_main_no_exception "${cxx_no_exception}" 181 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) 182 183 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" 184 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) 185 186 if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. 187 # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that 188 # conflict with our own definitions. Therefore using our own tuple does not 189 # work on those compilers. 190 cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" 191 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) 192 193 cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}" 194 gmock_main_use_own_tuple test/gmock-spec-builders_test.cc) 195 endif() 196 197 cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" 198 gmock_main_no_exception test/gmock-more-actions_test.cc) 199 200 cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}" 201 gmock_main_no_rtti test/gmock-spec-builders_test.cc) 202 203 cxx_shared_library(shared_gmock_main "${cxx_default}" 204 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) 205 206 # Tests that a binary can be built with Google Mock as a shared library. On 207 # some system configurations, it may not possible to run the binary without 208 # knowing more details about the system configurations. We do not try to run 209 # this binary. To get a more robust shared library coverage, configure with 210 # -DBUILD_SHARED_LIBS=ON. 211 cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}" 212 shared_gmock_main test/gmock-spec-builders_test.cc) 213 set_target_properties(shared_gmock_test_ 214 PROPERTIES 215 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") 216 217 ############################################################ 218 # Python tests. 219 220 cxx_executable(gmock_leak_test_ test gmock_main) 221 py_test(gmock_leak_test) 222 223 cxx_executable(gmock_output_test_ test gmock) 224 py_test(gmock_output_test) 225endif() 226