blob: 572d0444bf14834b1fde7f3e7398638cf4e4b7ce [file] [log] [blame]
vladlosev0f3f5012010-05-13 18:19:26 +00001########################################################################
zhanyong.wan7dfbea42010-10-05 19:24:04 +00002# CMake build script for Google Mock.
vladlosev0f3f5012010-05-13 18:19:26 +00003#
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
vladlosev0f3f5012010-05-13 18:19:26 +000012option(gmock_build_tests "Build all of Google Mock's own tests." OFF)
13
14# A directory to find Google Test sources.
vladlosev0a781df2010-05-20 22:17:28 +000015if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gtest/CMakeLists.txt")
vladlosev0f3f5012010-05-13 18:19:26 +000016 set(gtest_dir gtest)
17else()
18 set(gtest_dir ../gtest)
19endif()
20
zhanyong.wan7dfbea42010-10-05 19:24:04 +000021# Defines pre_project_set_up_hermetic_build() and set_up_hermetic_build().
vladlosev0f3f5012010-05-13 18:19:26 +000022include("${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).
40project(gmock CXX C)
41cmake_minimum_required(VERSION 2.6.2)
42
43if (COMMAND set_up_hermetic_build)
44 set_up_hermetic_build()
45endif()
46
vladlosev0f3f5012010-05-13 18:19:26 +000047# 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.wan7dfbea42010-10-05 19:24:04 +000049# directory in a subdirectory of our own as VC compilation may break
50# if they are the same (the default).
vladlosev0f3f5012010-05-13 18:19:26 +000051add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/gtest")
52
zhanyong.wan7dfbea42010-10-05 19:24:04 +000053# 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.
56config_compiler_and_linker() # from ${gtest_dir}/cmake/internal_utils.cmake
57
vladlosev0f3f5012010-05-13 18:19:26 +000058# Adds Google Mock's and Google Test's header directories to the search path.
59include_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
66########################################################################
67#
68# Defines the gmock & gmock_main libraries. User tests should link
69# with one of them.
70
71# Google Mock libraries. We build them using more strict warnings than what
72# are used for other targets, to ensure that Google Mock can be compiled by
73# a user aggressive about warnings.
vladlosev587c1b32011-05-20 00:42:22 +000074cxx_library(gmock
75 "${cxx_strict}"
76 "${gtest_dir}/src/gtest-all.cc"
77 src/gmock-all.cc)
vladlosev0f3f5012010-05-13 18:19:26 +000078
vladlosev587c1b32011-05-20 00:42:22 +000079cxx_library(gmock_main
80 "${cxx_strict}"
81 "${gtest_dir}/src/gtest-all.cc"
82 src/gmock-all.cc
83 src/gmock_main.cc)
vladlosev0f3f5012010-05-13 18:19:26 +000084
85########################################################################
86#
87# Google Mock's own tests.
88#
89# You can skip this section if you aren't interested in testing
90# Google Mock itself.
91#
92# The tests are not built by default. To build them, set the
93# gmock_build_tests option to ON. You can do it by running ccmake
94# or specifying the -Dgmock_build_tests=ON flag when running cmake.
95
96if (gmock_build_tests)
97 # This must be set in the root directory for the tests to be run by
98 # 'make test' or ctest.
99 enable_testing()
100
101 ############################################################
102 # C++ tests built with standard compiler flags.
103
104 cxx_test(gmock-actions_test gmock_main)
105 cxx_test(gmock-cardinalities_test gmock_main)
zhanyong.wana1a98f82013-03-01 21:28:40 +0000106 cxx_test(gmock_ex_test gmock_main)
vladlosev0f3f5012010-05-13 18:19:26 +0000107 cxx_test(gmock-generated-actions_test gmock_main)
108 cxx_test(gmock-generated-function-mockers_test gmock_main)
109 cxx_test(gmock-generated-internal-utils_test gmock_main)
110 cxx_test(gmock-generated-matchers_test gmock_main)
111 cxx_test(gmock-internal-utils_test gmock_main)
112 cxx_test(gmock-matchers_test gmock_main)
113 cxx_test(gmock-more-actions_test gmock_main)
114 cxx_test(gmock-nice-strict_test gmock_main)
115 cxx_test(gmock-port_test gmock_main)
116 cxx_test(gmock-spec-builders_test gmock_main)
117 cxx_test(gmock_link_test gmock_main test/gmock_link2_test.cc)
vladlosev0f3f5012010-05-13 18:19:26 +0000118 cxx_test(gmock_test gmock_main)
119
vladlosev47be72a2011-05-11 08:18:45 +0000120 if (CMAKE_USE_PTHREADS_INIT)
121 cxx_test(gmock_stress_test gmock)
122 endif()
123
vladlosev0f3f5012010-05-13 18:19:26 +0000124 # gmock_all_test is commented to save time building and running tests.
125 # Uncomment if necessary.
126 # cxx_test(gmock_all_test gmock_main)
127
128 ############################################################
129 # C++ tests built with non-standard compiler flags.
130
131 cxx_library(gmock_main_no_exception "${cxx_no_exception}"
132 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
vladlosev587c1b32011-05-20 00:42:22 +0000133
vladlosev0f3f5012010-05-13 18:19:26 +0000134 cxx_library(gmock_main_no_rtti "${cxx_no_rtti}"
135 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
vladlosev587c1b32011-05-20 00:42:22 +0000136
vladlosev0f3f5012010-05-13 18:19:26 +0000137 cxx_library(gmock_main_use_own_tuple "${cxx_use_own_tuple}"
138 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
139
140 cxx_test_with_flags(gmock-more-actions_no_exception_test "${cxx_no_exception}"
141 gmock_main_no_exception test/gmock-more-actions_test.cc)
142
143 cxx_test_with_flags(gmock_no_rtti_test "${cxx_no_rtti}"
144 gmock_main_no_rtti test/gmock-spec-builders_test.cc)
145
146 cxx_test_with_flags(gmock_use_own_tuple_test "${cxx_use_own_tuple}"
147 gmock_main_use_own_tuple test/gmock-spec-builders_test.cc)
148
vladlosev587c1b32011-05-20 00:42:22 +0000149 cxx_shared_library(shared_gmock_main "${cxx_default}"
150 "${gtest_dir}/src/gtest-all.cc" src/gmock-all.cc src/gmock_main.cc)
151
152 # Tests that a binary can be built with Google Mock as a shared library. On
153 # some system configurations, it may not possible to run the binary without
154 # knowing more details about the system configurations. We do not try to run
155 # this binary. To get a more robust shared library coverage, configure with
156 # -DBUILD_SHARED_LIBS=ON.
157 cxx_executable_with_flags(shared_gmock_test_ "${cxx_default}"
158 shared_gmock_main test/gmock-spec-builders_test.cc)
159 set_target_properties(shared_gmock_test_
160 PROPERTIES
161 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
162
vladlosev0f3f5012010-05-13 18:19:26 +0000163 ############################################################
164 # Python tests.
165
166 cxx_executable(gmock_leak_test_ test gmock_main)
167 py_test(gmock_leak_test)
168
169 cxx_executable(gmock_output_test_ test gmock)
170 py_test(gmock_output_test)
171endif()