vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 1 | ######################################################################## |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 2 | # CMake build script for Google Mock. |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 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. |
| 10 | option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) |
| 11 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 12 | option(gmock_build_tests "Build all of Google Mock's own tests." OFF) |
| 13 | |
| 14 | # A directory to find Google Test sources. |
vladlosev | 0a781df | 2010-05-20 22:17:28 +0000 | [diff] [blame] | 15 | if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt") |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 16 | set(gtest_dir gtest) |
| 17 | else() |
Arnaud Lacombe | eff38a7 | 2015-08-26 21:50:38 -0700 | [diff] [blame] | 18 | set(gtest_dir ../googletest) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 19 | endif() |
| 20 | |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 21 | # Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build(). |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 22 | include("${gtest_dir}/cmake/hermetic_build.cmake" OPTIONAL) |
| 23 | |
| 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() |
| 28 | endif() |
| 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). |
David Seifert | 8604c4a | 2017-08-14 13:45:56 +0200 | [diff] [blame] | 40 | if (CMAKE_VERSION VERSION_LESS 3.0) |
| 41 | project(gmock CXX C) |
| 42 | else() |
| 43 | cmake_policy(SET CMP0048 NEW) |
| 44 | project(gmock VERSION 1.9.0 LANGUAGES CXX C) |
| 45 | endif() |
Craig Scott | c0059a7 | 2016-01-01 11:01:15 +1100 | [diff] [blame] | 46 | cmake_minimum_required(VERSION 2.6.4) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 47 | |
| 48 | if (COMMAND set_up_hermetic_build) |
| 49 | set_up_hermetic_build() |
| 50 | endif() |
| 51 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 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 |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 54 | # directory in a subdirectory of our own as VC compilation may break |
| 55 | # if they are the same (the default). |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 56 | add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest") |
| 57 | |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 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. |
| 61 | config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake |
| 62 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 63 | # Adds Google Mock's and Google Test's header directories to the search path. |
| 64 | include_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 | |
kosak | b93d0f1 | 2014-01-13 22:28:01 +0000 | [diff] [blame] | 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 |
Wojciech Mamrak | 3464f76 | 2017-12-07 18:18:17 +0100 | [diff] [blame] | 77 | # VS 2015 14 1900 std::tuple |
| 78 | # VS 2017 15 >= 1910 std::tuple |
kosak | b93d0f1 | 2014-01-13 22:28:01 +0000 | [diff] [blame] | 79 | if (MSVC AND MSVC_VERSION EQUAL 1700) |
| 80 | add_definitions(/D _VARIADIC_MAX=10) |
| 81 | endif() |
| 82 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 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. |
Romain Geissler | 0663ce9 | 2017-12-02 22:47:20 +0100 | [diff] [blame] | 91 | if (MSVC) |
| 92 | cxx_library(gmock |
| 93 | "${cxx_strict}" |
| 94 | "${gtest_dir}/src/gtest-all.cc" |
| 95 | src/gmock-all.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 96 | |
Romain Geissler | 0663ce9 | 2017-12-02 22:47:20 +0100 | [diff] [blame] | 97 | cxx_library(gmock_main |
| 98 | "${cxx_strict}" |
| 99 | "${gtest_dir}/src/gtest-all.cc" |
| 100 | src/gmock-all.cc |
| 101 | src/gmock_main.cc) |
| 102 | else() |
| 103 | cxx_library(gmock "${cxx_strict}" src/gmock-all.cc) |
| 104 | target_link_libraries(gmock gtest) |
| 105 | cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc) |
| 106 | target_link_libraries(gmock_main gmock) |
| 107 | endif() |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 108 | |
Craig Scott | f601ee1 | 2015-12-06 16:25:33 +1100 | [diff] [blame] | 109 | # If the CMake version supports it, attach header directory information |
| 110 | # to the targets for when we are part of a parent build (ie being pulled |
| 111 | # in via add_subdirectory() rather than being a standalone build). |
| 112 | if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") |
Sam Lunt | f46bd00 | 2017-11-27 17:07:56 -0600 | [diff] [blame] | 113 | target_include_directories(gmock SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include") |
| 114 | target_include_directories(gmock_main SYSTEM INTERFACE "${gmock_SOURCE_DIR}/include") |
Craig Scott | f601ee1 | 2015-12-06 16:25:33 +1100 | [diff] [blame] | 115 | endif() |
| 116 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 117 | ######################################################################## |
| 118 | # |
Joan Puigcerver | 7c8ac48 | 2015-12-03 09:33:21 +0100 | [diff] [blame] | 119 | # Install rules |
Matthew Woehlke | 0e8e0e0 | 2017-08-09 15:29:36 -0400 | [diff] [blame] | 120 | if(INSTALL_GMOCK) |
| 121 | install(TARGETS gmock gmock_main |
Bryan Zimmerman | 1ae4096 | 2017-10-27 14:01:16 -0400 | [diff] [blame] | 122 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 123 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 124 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") |
| 125 | install(DIRECTORY "${gmock_SOURCE_DIR}/include/gmock" |
| 126 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") |
David Seifert | 8604c4a | 2017-08-14 13:45:56 +0200 | [diff] [blame] | 127 | |
| 128 | # configure and install pkgconfig files |
| 129 | configure_file( |
| 130 | cmake/gmock.pc.in |
| 131 | "${CMAKE_BINARY_DIR}/gmock.pc" |
| 132 | @ONLY) |
| 133 | configure_file( |
| 134 | cmake/gmock_main.pc.in |
| 135 | "${CMAKE_BINARY_DIR}/gmock_main.pc" |
| 136 | @ONLY) |
| 137 | install(FILES "${CMAKE_BINARY_DIR}/gmock.pc" "${CMAKE_BINARY_DIR}/gmock_main.pc" |
| 138 | DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
Matthew Woehlke | 0e8e0e0 | 2017-08-09 15:29:36 -0400 | [diff] [blame] | 139 | endif() |
Joan Puigcerver | 7c8ac48 | 2015-12-03 09:33:21 +0100 | [diff] [blame] | 140 | |
| 141 | ######################################################################## |
| 142 | # |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 143 | # Google Mock's own tests. |
| 144 | # |
| 145 | # You can skip this section if you aren't interested in testing |
| 146 | # Google Mock itself. |
| 147 | # |
| 148 | # The tests are not built by default. To build them, set the |
| 149 | # gmock_build_tests option to ON. You can do it by running ccmake |
| 150 | # or specifying the -Dgmock_build_tests=ON flag when running cmake. |
| 151 | |
| 152 | if (gmock_build_tests) |
| 153 | # This must be set in the root directory for the tests to be run by |
| 154 | # 'make test' or ctest. |
| 155 | enable_testing() |
| 156 | |
| 157 | ############################################################ |
| 158 | # C++ tests built with standard compiler flags. |
| 159 | |
| 160 | cxx_test(gmock-actions_test gmock_main) |
| 161 | cxx_test(gmock-cardinalities_test gmock_main) |
zhanyong.wan | a1a98f8 | 2013-03-01 21:28:40 +0000 | [diff] [blame] | 162 | cxx_test(gmock_ex_test gmock_main) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 163 | cxx_test(gmock-generated-actions_test gmock_main) |
| 164 | cxx_test(gmock-generated-function-mockers_test gmock_main) |
| 165 | cxx_test(gmock-generated-internal-utils_test gmock_main) |
| 166 | cxx_test(gmock-generated-matchers_test gmock_main) |
| 167 | cxx_test(gmock-internal-utils_test gmock_main) |
| 168 | cxx_test(gmock-matchers_test gmock_main) |
| 169 | cxx_test(gmock-more-actions_test gmock_main) |
| 170 | cxx_test(gmock-nice-strict_test gmock_main) |
| 171 | cxx_test(gmock-port_test gmock_main) |
| 172 | cxx_test(gmock-spec-builders_test gmock_main) |
| 173 | cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 174 | cxx_test(gmock_test gmock_main) |
| 175 | |
Roman Lebedev | 1a62d1b | 2016-12-30 10:46:39 +0300 | [diff] [blame] | 176 | if (DEFINED GTEST_HAS_PTHREAD) |
vladlosev | 47be72a | 2011-05-11 08:18:45 +0000 | [diff] [blame] | 177 | cxx_test(gmock_stress_test gmock) |
| 178 | endif() |
| 179 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 180 | # gmock_all_test is commented to save time building and running tests. |
| 181 | # Uncomment if necessary. |
| 182 | # cxx_test(gmock_all_test gmock_main) |
| 183 | |
| 184 | ############################################################ |
| 185 | # C++ tests built with non-standard compiler flags. |
| 186 | |
Romain Geissler | 0663ce9 | 2017-12-02 22:47:20 +0100 | [diff] [blame] | 187 | if (MSVC) |
| 188 | cxx_library(gmock_main_no_exception "${cxx_no_exception}" |
kosak | b93d0f1 | 2014-01-13 22:28:01 +0000 | [diff] [blame] | 189 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
| 190 | |
Romain Geissler | 0663ce9 | 2017-12-02 22:47:20 +0100 | [diff] [blame] | 191 | cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" |
| 192 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 193 | |
Romain Geissler | 0663ce9 | 2017-12-02 22:47:20 +0100 | [diff] [blame] | 194 | if (MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. |
| 195 | # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that |
| 196 | # conflict with our own definitions. Therefore using our own tuple does not |
| 197 | # work on those compilers. |
| 198 | cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" |
| 199 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
| 200 | |
| 201 | cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}" |
| 202 | gmock_main_use_own_tuple test/gmock-spec-builders_test.cc) |
| 203 | endif() |
| 204 | else() |
| 205 | cxx_library(gmock_main_no_exception "${cxx_no_exception}" src/gmock_main.cc) |
| 206 | target_link_libraries(gmock_main_no_exception gmock) |
| 207 | |
| 208 | cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" src/gmock_main.cc) |
| 209 | target_link_libraries(gmock_main_no_rtti gmock) |
| 210 | |
| 211 | cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" src/gmock_main.cc) |
| 212 | target_link_libraries(gmock_main_use_own_tuple gmock) |
| 213 | endif() |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 214 | cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" |
| 215 | gmock_main_no_exception test/gmock-more-actions_test.cc) |
| 216 | |
| 217 | cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}" |
| 218 | gmock_main_no_rtti test/gmock-spec-builders_test.cc) |
| 219 | |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 220 | cxx_shared_library(shared_gmock_main "${cxx_default}" |
| 221 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
| 222 | |
| 223 | # Tests that a binary can be built with Google Mock as a shared library. On |
| 224 | # some system configurations, it may not possible to run the binary without |
| 225 | # knowing more details about the system configurations. We do not try to run |
| 226 | # this binary. To get a more robust shared library coverage, configure with |
| 227 | # -DBUILD_SHARED_LIBS=ON. |
| 228 | cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}" |
| 229 | shared_gmock_main test/gmock-spec-builders_test.cc) |
| 230 | set_target_properties(shared_gmock_test_ |
| 231 | PROPERTIES |
| 232 | COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") |
| 233 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 234 | ############################################################ |
| 235 | # Python tests. |
| 236 | |
| 237 | cxx_executable(gmock_leak_test_ test gmock_main) |
| 238 | py_test(gmock_leak_test) |
| 239 | |
| 240 | cxx_executable(gmock_output_test_ test gmock) |
| 241 | py_test(gmock_output_test) |
| 242 | endif() |