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). |
| 40 | project(gmock CXX C) |
| 41 | cmake_minimum_required(VERSION 2.6.2) |
| 42 | |
| 43 | if (COMMAND set_up_hermetic_build) |
| 44 | set_up_hermetic_build() |
| 45 | endif() |
| 46 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 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 |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 49 | # directory in a subdirectory of our own as VC compilation may break |
| 50 | # if they are the same (the default). |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 51 | add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest") |
| 52 | |
zhanyong.wan | 7dfbea4 | 2010-10-05 19:24:04 +0000 | [diff] [blame] | 53 | # Although Google Test's CMakeLists.txt calls this function, the |
| 54 | # changes there don't affect the current scope. Therefore we have to |
| 55 | # call it again here. |
| 56 | config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake |
| 57 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 58 | # Adds Google Mock's and Google Test's header directories to the search path. |
| 59 | include_directories("${gmock_SOURCE_DIR}/include" |
| 60 | "${gmock_SOURCE_DIR}" |
| 61 | "${gtest_SOURCE_DIR}/include" |
| 62 | # This directory is needed to build directly from Google |
| 63 | # Test sources. |
| 64 | "${gtest_SOURCE_DIR}") |
| 65 | |
kosak | b93d0f1 | 2014-01-13 22:28:01 +0000 | [diff] [blame] | 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) |
| 74 | endif() |
| 75 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 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. |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 84 | cxx_library(gmock |
| 85 | "${cxx_strict}" |
| 86 | "${gtest_dir}/src/gtest-all.cc" |
| 87 | src/gmock-all.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 88 | |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 89 | cxx_library(gmock_main |
| 90 | "${cxx_strict}" |
| 91 | "${gtest_dir}/src/gtest-all.cc" |
| 92 | src/gmock-all.cc |
| 93 | src/gmock_main.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 94 | |
Craig Scott | f601ee1 | 2015-12-06 16:25:33 +1100 | [diff] [blame] | 95 | # If the CMake version supports it, attach header directory information |
| 96 | # to the targets for when we are part of a parent build (ie being pulled |
| 97 | # in via add_subdirectory() rather than being a standalone build). |
| 98 | if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11") |
| 99 | target_include_directories(gmock INTERFACE "${gmock_SOURCE_DIR}/include") |
| 100 | target_include_directories(gmock_main INTERFACE "${gmock_SOURCE_DIR}/include") |
| 101 | endif() |
| 102 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 103 | ######################################################################## |
| 104 | # |
Joan Puigcerver | 7c8ac48 | 2015-12-03 09:33:21 +0100 | [diff] [blame] | 105 | # Install rules |
| 106 | install(TARGETS gmock gmock_main |
| 107 | DESTINATION lib) |
| 108 | install(DIRECTORY ${gmock_SOURCE_DIR}/include/gmock |
| 109 | DESTINATION include) |
| 110 | |
| 111 | ######################################################################## |
| 112 | # |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 113 | # Google Mock's own tests. |
| 114 | # |
| 115 | # You can skip this section if you aren't interested in testing |
| 116 | # Google Mock itself. |
| 117 | # |
| 118 | # The tests are not built by default. To build them, set the |
| 119 | # gmock_build_tests option to ON. You can do it by running ccmake |
| 120 | # or specifying the -Dgmock_build_tests=ON flag when running cmake. |
| 121 | |
| 122 | if (gmock_build_tests) |
| 123 | # This must be set in the root directory for the tests to be run by |
| 124 | # 'make test' or ctest. |
| 125 | enable_testing() |
| 126 | |
| 127 | ############################################################ |
| 128 | # C++ tests built with standard compiler flags. |
| 129 | |
| 130 | cxx_test(gmock-actions_test gmock_main) |
| 131 | cxx_test(gmock-cardinalities_test gmock_main) |
zhanyong.wan | a1a98f8 | 2013-03-01 21:28:40 +0000 | [diff] [blame] | 132 | cxx_test(gmock_ex_test gmock_main) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 133 | cxx_test(gmock-generated-actions_test gmock_main) |
| 134 | cxx_test(gmock-generated-function-mockers_test gmock_main) |
| 135 | cxx_test(gmock-generated-internal-utils_test gmock_main) |
| 136 | cxx_test(gmock-generated-matchers_test gmock_main) |
| 137 | cxx_test(gmock-internal-utils_test gmock_main) |
| 138 | cxx_test(gmock-matchers_test gmock_main) |
| 139 | cxx_test(gmock-more-actions_test gmock_main) |
| 140 | cxx_test(gmock-nice-strict_test gmock_main) |
| 141 | cxx_test(gmock-port_test gmock_main) |
| 142 | cxx_test(gmock-spec-builders_test gmock_main) |
| 143 | cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc) |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 144 | cxx_test(gmock_test gmock_main) |
| 145 | |
vladlosev | 47be72a | 2011-05-11 08:18:45 +0000 | [diff] [blame] | 146 | if (CMAKE_USE_PTHREADS_INIT) |
| 147 | cxx_test(gmock_stress_test gmock) |
| 148 | endif() |
| 149 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 150 | # gmock_all_test is commented to save time building and running tests. |
| 151 | # Uncomment if necessary. |
| 152 | # cxx_test(gmock_all_test gmock_main) |
| 153 | |
| 154 | ############################################################ |
| 155 | # C++ tests built with non-standard compiler flags. |
| 156 | |
| 157 | cxx_library(gmock_main_no_exception "${cxx_no_exception}" |
| 158 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 159 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 160 | cxx_library(gmock_main_no_rtti "${cxx_no_rtti}" |
| 161 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 162 | |
kosak | b93d0f1 | 2014-01-13 22:28:01 +0000 | [diff] [blame] | 163 | if (NOT MSVC OR MSVC_VERSION LESS 1600) # 1600 is Visual Studio 2010. |
| 164 | # Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that |
| 165 | # conflict with our own definitions. Therefore using our own tuple does not |
| 166 | # work on those compilers. |
| 167 | cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}" |
| 168 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
| 169 | |
| 170 | cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}" |
| 171 | gmock_main_use_own_tuple test/gmock-spec-builders_test.cc) |
| 172 | endif() |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 173 | |
| 174 | cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}" |
| 175 | gmock_main_no_exception test/gmock-more-actions_test.cc) |
| 176 | |
| 177 | cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}" |
| 178 | gmock_main_no_rtti test/gmock-spec-builders_test.cc) |
| 179 | |
vladlosev | 587c1b3 | 2011-05-20 00:42:22 +0000 | [diff] [blame] | 180 | cxx_shared_library(shared_gmock_main "${cxx_default}" |
| 181 | "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc) |
| 182 | |
| 183 | # Tests that a binary can be built with Google Mock as a shared library. On |
| 184 | # some system configurations, it may not possible to run the binary without |
| 185 | # knowing more details about the system configurations. We do not try to run |
| 186 | # this binary. To get a more robust shared library coverage, configure with |
| 187 | # -DBUILD_SHARED_LIBS=ON. |
| 188 | cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}" |
| 189 | shared_gmock_main test/gmock-spec-builders_test.cc) |
| 190 | set_target_properties(shared_gmock_test_ |
| 191 | PROPERTIES |
| 192 | COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1") |
| 193 | |
vladlosev | 0f3f501 | 2010-05-13 18:19:26 +0000 | [diff] [blame] | 194 | ############################################################ |
| 195 | # Python tests. |
| 196 | |
| 197 | cxx_executable(gmock_leak_test_ test gmock_main) |
| 198 | py_test(gmock_leak_test) |
| 199 | |
| 200 | cxx_executable(gmock_output_test_ test gmock) |
| 201 | py_test(gmock_output_test) |
| 202 | endif() |