blob: 808912093a3b6ac8d46be7442e721fe181df1a05 [file] [log] [blame]
vladlosevb006f162009-11-18 00:44:26 +00001# -*- Python -*-
2#
3# Copyright 2008 Google Inc. All Rights Reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32"""Builds the Google Mock (gmock) lib.
33
34You should be able to call this file from more or less any SConscript
35file.
36
37You can optionally set a variable on the construction environment to
38have the unit test executables copied to your output directory. The
39variable should be env['EXE_OUTPUT'].
40
41Another optional variable is env['LIB_OUTPUT']. If set, the generated
42libraries are copied to the folder indicated by the variable.
43
44If you place the Google Mock sources within your own project's source
45directory, you should be able to call this SConscript file simply as
46follows:
47
48# -- cut here --
49# Build gmock library; first tell it where to copy executables.
50env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode' # example, optional
51env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib'
52env.SConscript('whateverpath/gmock/scons/SConscript')
53# -- cut here --
54
55If on the other hand you place the Google Mock sources in a directory
56outside of your project's source tree, you would use a snippet similar
57to the following:
58
59# -- cut here --
60
61# The following assumes that $BUILD_DIR refers to the root of the
62# directory for your current build mode, e.g. "#/mybuilddir/mybuildmode"
63
64# Build gmock library; as it is outside of our source root, we need to
65# tell SCons that the directory it will refer to as
66# e.g. $BUILD_DIR/gmock is actually on disk in original form as
67# ../../gmock (relative to your project root directory). Recall that
68# SCons by default copies all source files into the build directory
69# before building.
70gmock_dir = env.Dir('$BUILD_DIR/gmock')
71
72# Modify this part to point to Google Mock relative to the current
73# SConscript or SConstruct file's directory. The ../.. path would
74# be different per project, to locate the base directory for Google Mock.
75gmock_dir.addRepository(env.Dir('../../gmock'))
76
77# Tell the Google Mock SCons file where to copy executables.
78env['EXE_OUTPUT'] = '$BUILD_DIR' # example, optional
79
80# Call the Google Mock SConscript to build gmock.lib and unit tests. The
81# location of the library should end up as
82# '$BUILD_DIR/gmock/scons/gmock.lib'
83env.SConscript(env.File('scons/SConscript', gmock_dir))
84
85# -- cut here --
86"""
87
88
89__author__ = 'joi@google.com (Joi Sigurdsson)'
90
91
92import os
93
94############################################################
95# Environments for building the targets, sorted by name.
96
97Import('env', 'gtest_exports')
98
99GTEST_DIR = env['GTEST_DIR']
100
101GtestObject = gtest_exports['GtestObject']
102GtestBinary = gtest_exports['GtestBinary']
103GtestTest = gtest_exports['GtestTest']
104
105gtest_common_exports = SConscript(GTEST_DIR + '/scons/SConscript.common')
106EnvCreator = gtest_common_exports['EnvCreator']
107
108# TODO(vladl@google.com): restore warnings as errors once all warnings are fixed
109# in gMock.
110env = EnvCreator.Create(env, EnvCreator.WarningOk)
111
112# Note: The relative paths in SConscript files are relative to the location
113# of the SConscript file itself. To make a path relative to the location of
114# the main SConstruct file, prepend the path with the # sign.
115#
116# Include paths to gtest headers are relative to either the gmock
117# directory or the 'include' subdirectory of it, and this SConscript
118# file is one directory deeper than the gmock directory.
119env.Prepend(CPPPATH = ['..', '../include', GTEST_DIR + '/include'])
120
121env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
122env_with_exceptions = EnvCreator.Create(env, EnvCreator.WithExceptions)
123env_without_rtti = EnvCreator.Create(env, EnvCreator.NoRtti)
124
125############################################################
126# Helpers for creating build targets.
127
128def GmockStaticLibraries(build_env):
129 """Builds static libraries for gmock and gmock_main in build_env.
130
131 Args:
132 build_env: An environment in which to build libraries.
133
134 Returns:
135 A pair (gmock_library, gmock_main_library) built in the build_env
136 environment.
137 """
138
139 gmock_object = GtestObject(build_env, '../src/gmock-all.cc')
140 gmock_main_object = GtestObject(build_env, '../src/gmock_main.cc')
141
142 return (build_env.StaticLibrary(target='gmock' + build_env['OBJ_SUFFIX'],
143 source=[gmock_object]),
144 build_env.StaticLibrary(target='gmock_main' + build_env['OBJ_SUFFIX'],
145 source=[gmock_object, gmock_main_object]))
146
147
148############################################################
149# Object and library targets.
150
151gtest = gtest_exports['gtest']
152gtest_ex = gtest_exports['gtest_ex']
153gtest_no_rtti = gtest_exports['gtest_no_rtti']
154gtest_use_own_tuple = gtest_exports['gtest_use_own_tuple']
155
156# gmock.lib to be used by most apps (if you have your own main function).
157# gmock_main.lib can be used if you just want a basic main function; it is
158# also used by some tests for Google Test itself.
159gmock, gmock_main = GmockStaticLibraries(env)
160gmock_ex, gmock_main_ex = GmockStaticLibraries(env_with_exceptions)
161gmock_no_rtti, gmock_main_no_rtti = GmockStaticLibraries(env_without_rtti)
162gmock_use_own_tuple, gmock_main_use_own_tuple = GmockStaticLibraries(
163 env_use_own_tuple)
164
165# Install the libraries if needed.
166if 'LIB_OUTPUT' in env.Dictionary():
167 env.Install('$LIB_OUTPUT', source=[gmock, gmock_main,
168 gmock_ex, gmock_main_ex,
169 gmock_no_rtti, gmock_main_no_rtti,
170 gmock_use_own_tuple,
171 gmock_main_use_own_tuple])
172
173#############################################################
174# Test targets using the standard environment.
175GtestTest(env, 'gmock-actions_test', [gtest, gmock_main])
176GtestTest(env, 'gmock-cardinalities_test', [gtest, gmock_main])
177GtestTest(env, 'gmock-generated-actions_test', [gtest, gmock_main])
178GtestTest(env, 'gmock-generated-function-mockers_test', [gtest, gmock_main])
179GtestTest(env, 'gmock-generated-internal-utils_test', [gtest, gmock_main])
180GtestTest(env, 'gmock-generated-matchers_test', [gtest, gmock_main])
181GtestTest(env, 'gmock-internal-utils_test', [gtest, gmock_main])
182GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main])
183GtestTest(env, 'gmock-more-actions_test', [gtest, gmock_main])
184GtestTest(env, 'gmock-nice-strict_test', [gtest, gmock_main])
185GtestTest(env, 'gmock-port_test', [gtest, gmock_main])
186GtestTest(env, 'gmock-printers_test', [gtest, gmock_main])
187GtestTest(env, 'gmock-spec-builders_test', [gtest, gmock_main])
188GtestTest(env, 'gmock_leak_test_', [gtest, gmock_main])
189GtestTest(env, 'gmock_link_test', [gtest, gmock_main],
190 ['../test/gmock_link2_test.cc'])
191GtestTest(env, 'gmock_output_test_', [gtest, gmock])
192#GtestTest(env, 'gmock_stress_test', [gtest, gmock])
193GtestTest(env, 'gmock_test', [gtest, gmock_main])
194# gmock_all_test is commented to save time building and running tests.
195# Uncomment if necessary.
196#GtestTest(env, 'gmock_all_test', [gtest, gmock_main])
197# TODO (vladl): Add a test verifying that gmock can be built from
198# testing/base/gunit.cc and testing/base/internal/gmock-all.cc after merging
199# into the main branch. This is the API for Windows users.
200
201############################################################
202# Tests targets using custom environments.
203GtestBinary(env_with_exceptions,
204 'gmock-more-actions-ex_test',
205 [gtest_ex, gmock_main_ex],
206 ['../test/gmock-more-actions_test.cc'])
207
208GtestBinary(env_without_rtti,
209 'gmock_no_rtti_test',
210 [gtest_no_rtti, gmock_main_no_rtti],
211 ['../test/gmock-spec-builders_test.cc'])
212
213GtestBinary(env_use_own_tuple,
214 'gmock_use_own_tuple_test',
215 [gtest_use_own_tuple, gmock_main_use_own_tuple],
216 ['../test/gmock-spec-builders_test.cc'])