Adds SCons build files for Google Mock

pull/511/head
vladlosev 15 years ago
parent 79b83505bc
commit b006f165b1
  1. 216
      scons/SConscript
  2. 99
      scons/SConstruct

@ -0,0 +1,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']
# TODO(vladl@google.com): restore warnings as errors once all warnings are fixed
# in gMock.
env = EnvCreator.Create(env, EnvCreator.WarningOk)
# 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])
# TODO (vladl): Add a test verifying that gmock can be built from
# testing/base/gunit.cc and testing/base/internal/gmock-all.cc after merging
# into the main branch. This is the API for Windows users.
############################################################
# 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'])

@ -0,0 +1,99 @@
# -*- 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.
#
# Author: joi@google.com (Joi Sigurdsson)
# Author: vladl@google.com (Vlad Losev)
#
# Build file for Google Mock and its tests.
#
# Usage:
# cd to the directory with this file, then
# ./scons.py [OPTIONS]
#
# where frequently used command-line options include:
# -h print usage help.
# BUILD=all build all build types.
# BUILD=win-opt build the given build type.
EnsurePythonVersion(2, 3)
# Path to the Google Test code this Google Mock will use.
GTEST_DIR = '../gtest'
# TODO(vladl@google.com): Factor the looping logic out for reuse.
def BuildGMockSelectedEnvironments(sconstruct_helper):
# Build using whichever environments the 'BUILD' option selected
for build_name in sconstruct_helper.env_base['BUILD']:
print 'BUILDING %s' % build_name
env = sconstruct_helper.env_dict[build_name]
# Make sure SConscript files can refer to base build dir
env['MAIN_DIR'] = env.Dir(env['BUILD_DIR'])
#print 'CCFLAGS: %s' % env.subst('$CCFLAGS')
#print 'LINK: %s' % env.subst('$LINK')
#print 'AR: %s' % env.subst('$AR')
#print 'CC: %s' % env.subst('$CC')
#print 'CXX: %s' % env.subst('$CXX')
#print 'LIBPATH: %s' % env.subst('$LIBPATH')
#print 'ENV:PATH: %s' % env['ENV']['PATH']
#print 'ENV:INCLUDE: %s' % env['ENV']['INCLUDE']
#print 'ENV:LIB: %s' % env['ENV']['LIB']
#print 'ENV:TEMP: %s' % env['ENV']['TEMP']
env['GTEST_DIR'] = '#/' + GTEST_DIR
env['GTEST_BUILD_TESTS'] = False
Export('env')
# Invokes SConscript with variant_dir being build/<config name>.
# Counter-intuitively, src_dir is relative to the build dir and has
# to be '../..' to point to the scons directory.
VariantDir(env['BUILD_DIR'], '../..', duplicate=0)
gtest_exports = env.SConscript(env['BUILD_DIR'] + '/gtest/scons/SConscript')
Export('gtest_exports')
SConscript('SConscript',
src_dir='../..',
variant_dir=env['BUILD_DIR'],
duplicate=0)
sconstruct_helper = SConscript(GTEST_DIR + '/scons/SConstruct.common')
sconstruct_helper.Initialize(build_root_path='..',
support_multiple_win_builds=False)
win_base = sconstruct_helper.MakeWinBaseEnvironment()
if win_base.get('MSVS_VERSION', None) == '7.1':
sconstruct_helper.EnvCreator.WithExceptions(win_base)
sconstruct_helper.MakeWinDebugEnvironment(win_base, 'win-dbg')
sconstruct_helper.MakeWinOptimizedEnvironment(win_base, 'win-opt')
sconstruct_helper.ConfigureGccEnvironments()
BuildGMockSelectedEnvironments(sconstruct_helper)
Loading…
Cancel
Save