blob: 764cd7bc2e89c879cdad77593fb20b196f976e5d [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>.
zhanyong.wan32de5f52009-12-23 00:13:23 +0000113 ])
vladlosevb006f162009-11-18 00:44:26 +0000114
115# Note: The relative paths in SConscript files are relative to the location
116# of the SConscript file itself. To make a path relative to the location of
117# the main SConstruct file, prepend the path with the # sign.
118#
119# Include paths to gtest headers are relative to either the gmock
120# directory or the 'include' subdirectory of it, and this SConscript
121# file is one directory deeper than the gmock directory.
122env.Prepend(CPPPATH = ['..', '../include', GTEST_DIR + '/include'])
123
124env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
125env_with_exceptions = EnvCreator.Create(env, EnvCreator.WithExceptions)
126env_without_rtti = EnvCreator.Create(env, EnvCreator.NoRtti)
127
128############################################################
129# Helpers for creating build targets.
130
131def GmockStaticLibraries(build_env):
132 """Builds static libraries for gmock and gmock_main in build_env.
133
134 Args:
135 build_env: An environment in which to build libraries.
136
137 Returns:
138 A pair (gmock_library, gmock_main_library) built in the build_env
139 environment.
140 """
141
142 gmock_object = GtestObject(build_env, '../src/gmock-all.cc')
143 gmock_main_object = GtestObject(build_env, '../src/gmock_main.cc')
144
145 return (build_env.StaticLibrary(target='gmock' + build_env['OBJ_SUFFIX'],
146 source=[gmock_object]),
147 build_env.StaticLibrary(target='gmock_main' + build_env['OBJ_SUFFIX'],
148 source=[gmock_object, gmock_main_object]))
149
150
151############################################################
152# Object and library targets.
153
154gtest = gtest_exports['gtest']
155gtest_ex = gtest_exports['gtest_ex']
156gtest_no_rtti = gtest_exports['gtest_no_rtti']
157gtest_use_own_tuple = gtest_exports['gtest_use_own_tuple']
158
159# gmock.lib to be used by most apps (if you have your own main function).
160# gmock_main.lib can be used if you just want a basic main function; it is
161# also used by some tests for Google Test itself.
162gmock, gmock_main = GmockStaticLibraries(env)
163gmock_ex, gmock_main_ex = GmockStaticLibraries(env_with_exceptions)
164gmock_no_rtti, gmock_main_no_rtti = GmockStaticLibraries(env_without_rtti)
165gmock_use_own_tuple, gmock_main_use_own_tuple = GmockStaticLibraries(
166 env_use_own_tuple)
167
168# Install the libraries if needed.
169if 'LIB_OUTPUT' in env.Dictionary():
170 env.Install('$LIB_OUTPUT', source=[gmock, gmock_main,
171 gmock_ex, gmock_main_ex,
172 gmock_no_rtti, gmock_main_no_rtti,
173 gmock_use_own_tuple,
174 gmock_main_use_own_tuple])
175
176#############################################################
177# Test targets using the standard environment.
178GtestTest(env, 'gmock-actions_test', [gtest, gmock_main])
179GtestTest(env, 'gmock-cardinalities_test', [gtest, gmock_main])
180GtestTest(env, 'gmock-generated-actions_test', [gtest, gmock_main])
181GtestTest(env, 'gmock-generated-function-mockers_test', [gtest, gmock_main])
182GtestTest(env, 'gmock-generated-internal-utils_test', [gtest, gmock_main])
183GtestTest(env, 'gmock-generated-matchers_test', [gtest, gmock_main])
184GtestTest(env, 'gmock-internal-utils_test', [gtest, gmock_main])
185GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main])
186GtestTest(env, 'gmock-more-actions_test', [gtest, gmock_main])
187GtestTest(env, 'gmock-nice-strict_test', [gtest, gmock_main])
188GtestTest(env, 'gmock-port_test', [gtest, gmock_main])
189GtestTest(env, 'gmock-printers_test', [gtest, gmock_main])
190GtestTest(env, 'gmock-spec-builders_test', [gtest, gmock_main])
191GtestTest(env, 'gmock_leak_test_', [gtest, gmock_main])
192GtestTest(env, 'gmock_link_test', [gtest, gmock_main],
193 ['../test/gmock_link2_test.cc'])
194GtestTest(env, 'gmock_output_test_', [gtest, gmock])
195#GtestTest(env, 'gmock_stress_test', [gtest, gmock])
196GtestTest(env, 'gmock_test', [gtest, gmock_main])
197# gmock_all_test is commented to save time building and running tests.
198# Uncomment if necessary.
199#GtestTest(env, 'gmock_all_test', [gtest, gmock_main])
vladlosevb006f162009-11-18 00:44:26 +0000200
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'])