aboutsummaryrefslogtreecommitdiffstats
path: root/scons/SConscript
blob: 764cd7bc2e89c879cdad77593fb20b196f976e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# -*- Python -*-
#
# Copyright 2008 Google Inc. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


"""Builds the Google Mock (gmock) lib.

You should be able to call this file from more or less any SConscript
file.

You can optionally set a variable on the construction environment to
have the unit test executables copied to your output directory.  The
variable should be env['EXE_OUTPUT'].

Another optional variable is env['LIB_OUTPUT'].  If set, the generated
libraries are copied to the folder indicated by the variable.

If you place the Google Mock sources within your own project's source
directory, you should be able to call this SConscript file simply as
follows:

# -- cut here --
# Build gmock library; first tell it where to copy executables.
env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode'  # example, optional
env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib'
env.SConscript('whateverpath/gmock/scons/SConscript')
# -- cut here --

If on the other hand you place the Google Mock sources in a directory
outside of your project's source tree, you would use a snippet similar
to the following:

# -- cut here --

# The following assumes that $BUILD_DIR refers to the root of the
# directory for your current build mode, e.g. "#/mybuilddir/mybuildmode"

# Build gmock library; as it is outside of our source root, we need to
# tell SCons that the directory it will refer to as
# e.g. $BUILD_DIR/gmock is actually on disk in original form as
# ../../gmock (relative to your project root directory).  Recall that
# SCons by default copies all source files into the build directory
# before building.
gmock_dir = env.Dir('$BUILD_DIR/gmock')

# Modify this part to point to Google Mock relative to the current
# SConscript or SConstruct file's directory.  The ../.. path would
# be different per project, to locate the base directory for Google Mock.
gmock_dir.addRepository(env.Dir('../../gmock'))

# Tell the Google Mock SCons file where to copy executables.
env['EXE_OUTPUT'] = '$BUILD_DIR'  # example, optional

# Call the Google Mock SConscript to build gmock.lib and unit tests.  The
# location of the library should end up as
# '$BUILD_DIR/gmock/scons/gmock.lib'
env.SConscript(env.File('scons/SConscript', gmock_dir))

# -- cut here --
"""


__author__ = 'joi@google.com (Joi Sigurdsson)'


import os

############################################################
# Environments for building the targets, sorted by name.

Import('env', 'gtest_exports')

GTEST_DIR = env['GTEST_DIR']

GtestObject = gtest_exports['GtestObject']
GtestBinary = gtest_exports['GtestBinary']
GtestTest = gtest_exports['GtestTest']

gtest_common_exports = SConscript(GTEST_DIR + '/scons/SConscript.common')
EnvCreator = gtest_common_exports['EnvCreator']

env = env.Clone()
if env['PLATFORM'] == 'win32':
  env.Append(CCFLAGS=[
      '-wd4127',  # Disables warning "conditional expression is constant",
                  # triggered by VC 8.0's own STL header <list>.
      ])

# Note: The relative paths in SConscript files are relative to the location
# of the SConscript file itself. To make a path relative to the location of
# the main SConstruct file, prepend the path with the # sign.
#
# Include paths to gtest headers are relative to either the gmock
# directory or the 'include' subdirectory of it, and this SConscript
# file is one directory deeper than the gmock directory.
env.Prepend(CPPPATH = ['..', '../include', GTEST_DIR + '/include'])

env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
env_with_exceptions = EnvCreator.Create(env, EnvCreator.WithExceptions)
env_without_rtti = EnvCreator.Create(env, EnvCreator.NoRtti)

############################################################
# Helpers for creating build targets.

def GmockStaticLibraries(build_env):
  """Builds static libraries for gmock and gmock_main in build_env.

  Args:
    build_env: An environment in which to build libraries.

  Returns:
    A pair (gmock_library, gmock_main_library) built in the build_env
    environment.
  """

  gmock_object = GtestObject(build_env, '../src/gmock-all.cc')
  gmock_main_object = GtestObject(build_env, '../src/gmock_main.cc')

  return (build_env.StaticLibrary(target='gmock' + build_env['OBJ_SUFFIX'],
                                  source=[gmock_object]),
          build_env.StaticLibrary(target='gmock_main' + build_env['OBJ_SUFFIX'],
                                  source=[gmock_object, gmock_main_object]))


############################################################
# Object and library targets.

gtest = gtest_exports['gtest']
gtest_ex = gtest_exports['gtest_ex']
gtest_no_rtti = gtest_exports['gtest_no_rtti']
gtest_use_own_tuple = gtest_exports['gtest_use_own_tuple']

# gmock.lib to be used by most apps (if you have your own main function).
# gmock_main.lib can be used if you just want a basic main function; it is
# also used by some tests for Google Test itself.
gmock, gmock_main = GmockStaticLibraries(env)
gmock_ex, gmock_main_ex = GmockStaticLibraries(env_with_exceptions)
gmock_no_rtti, gmock_main_no_rtti = GmockStaticLibraries(env_without_rtti)
gmock_use_own_tuple, gmock_main_use_own_tuple = GmockStaticLibraries(
    env_use_own_tuple)

# Install the libraries if needed.
if 'LIB_OUTPUT' in env.Dictionary():
  env.Install('$LIB_OUTPUT', source=[gmock, gmock_main,
                                     gmock_ex, gmock_main_ex,
                                     gmock_no_rtti, gmock_main_no_rtti,
                                     gmock_use_own_tuple,
                                     gmock_main_use_own_tuple])

#############################################################
# Test targets using the standard environment.
GtestTest(env, 'gmock-actions_test', [gtest, gmock_main])
GtestTest(env, 'gmock-cardinalities_test', [gtest, gmock_main])
GtestTest(env, 'gmock-generated-actions_test', [gtest, gmock_main])
GtestTest(env, 'gmock-generated-function-mockers_test', [gtest, gmock_main])
GtestTest(env, 'gmock-generated-internal-utils_test', [gtest, gmock_main])
GtestTest(env, 'gmock-generated-matchers_test', [gtest, gmock_main])
GtestTest(env, 'gmock-internal-utils_test', [gtest, gmock_main])
GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main])
GtestTest(env, 'gmock-more-actions_test', [gtest, gmock_main])
GtestTest(env, 'gmock-nice-strict_test', [gtest, gmock_main])
GtestTest(env, 'gmock-port_test', [gtest, gmock_main])
GtestTest(env, 'gmock-printers_test', [gtest, gmock_main])
GtestTest(env, 'gmock-spec-builders_test', [gtest, gmock_main])
GtestTest(env, 'gmock_leak_test_', [gtest, gmock_main])
GtestTest(env, 'gmock_link_test', [gtest, gmock_main],
          ['../test/gmock_link2_test.cc'])
GtestTest(env, 'gmock_output_test_', [gtest, gmock])
#GtestTest(env, 'gmock_stress_test', [gtest, gmock])
GtestTest(env, 'gmock_test', [gtest, gmock_main])
# gmock_all_test is commented to save time building and running tests.
# Uncomment if necessary.
#GtestTest(env, 'gmock_all_test', [gtest, gmock_main])

############################################################
# Tests targets using custom environments.
GtestBinary(env_with_exceptions,
            'gmock-more-actions-ex_test',
            [gtest_ex, gmock_main_ex],
            ['../test/gmock-more-actions_test.cc'])

GtestBinary(env_without_rtti,
            'gmock_no_rtti_test',
            [gtest_no_rtti, gmock_main_no_rtti],
            ['../test/gmock-spec-builders_test.cc'])

GtestBinary(env_use_own_tuple,
            'gmock_use_own_tuple_test',
            [gtest_use_own_tuple, gmock_main_use_own_tuple],
            ['../test/gmock-spec-builders_test.cc'])