blob: 7c2bfbf66d760bb3735a7f262224817ad844e51a [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
zhanyong.wan32de5f52009-12-23 00:13:23 +0000108env = env.Clone()
109if env['PLATFORM'] == 'win32':
110 env.Append(CCFLAGS=[
111 '-wd4127', # Disables warning "conditional expression is constant",
112 # triggered by VC 8.0's own STL header <list>.
113 '-wd4702', # Disables warning "unreachable code", triggered by VC
114 # 7.1's own STL header <xtree>.
115 '-wd4675', # Disables warning "resolved overload was found by
116 # argument-dependent lookup" generated by VC 7.1.
117 # It just says that VC 7.1 fixed a bug in earlier
118 # versions of VC so the code behavior will be
119 # different than compiled with VC 6.0, for example.
120 ])
vladlosevb006f162009-11-18 00:44:26 +0000121
122# Note: The relative paths in SConscript files are relative to the location
123# of the SConscript file itself. To make a path relative to the location of
124# the main SConstruct file, prepend the path with the # sign.
125#
126# Include paths to gtest headers are relative to either the gmock
127# directory or the 'include' subdirectory of it, and this SConscript
128# file is one directory deeper than the gmock directory.
129env.Prepend(CPPPATH = ['..', '../include', GTEST_DIR + '/include'])
130
131env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
132env_with_exceptions = EnvCreator.Create(env, EnvCreator.WithExceptions)
133env_without_rtti = EnvCreator.Create(env, EnvCreator.NoRtti)
134
135############################################################
136# Helpers for creating build targets.
137
138def GmockStaticLibraries(build_env):
139 """Builds static libraries for gmock and gmock_main in build_env.
140
141 Args:
142 build_env: An environment in which to build libraries.
143
144 Returns:
145 A pair (gmock_library, gmock_main_library) built in the build_env
146 environment.
147 """
148
149 gmock_object = GtestObject(build_env, '../src/gmock-all.cc')
150 gmock_main_object = GtestObject(build_env, '../src/gmock_main.cc')
151
152 return (build_env.StaticLibrary(target='gmock' + build_env['OBJ_SUFFIX'],
153 source=[gmock_object]),
154 build_env.StaticLibrary(target='gmock_main' + build_env['OBJ_SUFFIX'],
155 source=[gmock_object, gmock_main_object]))
156
157
158############################################################
159# Object and library targets.
160
161gtest = gtest_exports['gtest']
162gtest_ex = gtest_exports['gtest_ex']
163gtest_no_rtti = gtest_exports['gtest_no_rtti']
164gtest_use_own_tuple = gtest_exports['gtest_use_own_tuple']
165
166# gmock.lib to be used by most apps (if you have your own main function).
167# gmock_main.lib can be used if you just want a basic main function; it is
168# also used by some tests for Google Test itself.
169gmock, gmock_main = GmockStaticLibraries(env)
170gmock_ex, gmock_main_ex = GmockStaticLibraries(env_with_exceptions)
171gmock_no_rtti, gmock_main_no_rtti = GmockStaticLibraries(env_without_rtti)
172gmock_use_own_tuple, gmock_main_use_own_tuple = GmockStaticLibraries(
173 env_use_own_tuple)
174
175# Install the libraries if needed.
176if 'LIB_OUTPUT' in env.Dictionary():
177 env.Install('$LIB_OUTPUT', source=[gmock, gmock_main,
178 gmock_ex, gmock_main_ex,
179 gmock_no_rtti, gmock_main_no_rtti,
180 gmock_use_own_tuple,
181 gmock_main_use_own_tuple])
182
183#############################################################
184# Test targets using the standard environment.
185GtestTest(env, 'gmock-actions_test', [gtest, gmock_main])
186GtestTest(env, 'gmock-cardinalities_test', [gtest, gmock_main])
187GtestTest(env, 'gmock-generated-actions_test', [gtest, gmock_main])
188GtestTest(env, 'gmock-generated-function-mockers_test', [gtest, gmock_main])
189GtestTest(env, 'gmock-generated-internal-utils_test', [gtest, gmock_main])
190GtestTest(env, 'gmock-generated-matchers_test', [gtest, gmock_main])
191GtestTest(env, 'gmock-internal-utils_test', [gtest, gmock_main])
192GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main])
193GtestTest(env, 'gmock-more-actions_test', [gtest, gmock_main])
194GtestTest(env, 'gmock-nice-strict_test', [gtest, gmock_main])
195GtestTest(env, 'gmock-port_test', [gtest, gmock_main])
196GtestTest(env, 'gmock-printers_test', [gtest, gmock_main])
197GtestTest(env, 'gmock-spec-builders_test', [gtest, gmock_main])
198GtestTest(env, 'gmock_leak_test_', [gtest, gmock_main])
199GtestTest(env, 'gmock_link_test', [gtest, gmock_main],
200 ['../test/gmock_link2_test.cc'])
201GtestTest(env, 'gmock_output_test_', [gtest, gmock])
202#GtestTest(env, 'gmock_stress_test', [gtest, gmock])
203GtestTest(env, 'gmock_test', [gtest, gmock_main])
204# gmock_all_test is commented to save time building and running tests.
205# Uncomment if necessary.
206#GtestTest(env, 'gmock_all_test', [gtest, gmock_main])
vladlosevb006f162009-11-18 00:44:26 +0000207
208############################################################
209# Tests targets using custom environments.
210GtestBinary(env_with_exceptions,
211 'gmock-more-actions-ex_test',
212 [gtest_ex, gmock_main_ex],
213 ['../test/gmock-more-actions_test.cc'])
214
215GtestBinary(env_without_rtti,
216 'gmock_no_rtti_test',
217 [gtest_no_rtti, gmock_main_no_rtti],
218 ['../test/gmock-spec-builders_test.cc'])
219
220GtestBinary(env_use_own_tuple,
221 'gmock_use_own_tuple_test',
222 [gtest_use_own_tuple, gmock_main_use_own_tuple],
223 ['../test/gmock-spec-builders_test.cc'])