181 lines
7.1 KiB
Python
181 lines
7.1 KiB
Python
|
#!/usr/bin/python2.4
|
||
|
#
|
||
|
# 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 Test (gtest) lib; this is for Windows projects
|
||
|
using SCons and can probably be easily extended for cross-platform
|
||
|
SCons builds. The compilation settings from your project will be used,
|
||
|
with some specific flags required for gtest added.
|
||
|
|
||
|
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 gtest sources within your own project's source
|
||
|
directory, you should be able to call this SConscript file simply as
|
||
|
follows:
|
||
|
|
||
|
# -- cut here --
|
||
|
# Build gtest library; first tell it where to copy executables.
|
||
|
env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode' # example, optional
|
||
|
env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib'
|
||
|
env.SConscript('whateverpath/gtest/scons/SConscript')
|
||
|
# -- cut here --
|
||
|
|
||
|
If on the other hand you place the gtest 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 gtest 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/gtest is actually on disk in original form as
|
||
|
# ../../gtest (relative to your project root directory). Recall that
|
||
|
# SCons by default copies all source files into the build directory
|
||
|
# before building.
|
||
|
gtest_dir = env.Dir('$BUILD_DIR/gtest')
|
||
|
|
||
|
# Modify this part to point to gtest relative to the current
|
||
|
# SConscript or SConstruct file's directory. The ../.. path would
|
||
|
# be different per project, to locate the base directory for gtest.
|
||
|
gtest_dir.addRepository(env.Dir('../../gtest'))
|
||
|
|
||
|
# Tell the gtest SCons file where to copy executables.
|
||
|
env['EXE_OUTPUT'] = '$BUILD_DIR' # example, optional
|
||
|
|
||
|
# Call the gtest SConscript to build gtest.lib and unit tests. The
|
||
|
# location of the library should end up as
|
||
|
# '$BUILD_DIR/gtest/scons/gtest.lib'
|
||
|
env.SConscript(env.File('scons/SConscript', gtest_dir))
|
||
|
|
||
|
# -- cut here --
|
||
|
"""
|
||
|
|
||
|
|
||
|
__author__ = 'joi@google.com (Joi Sigurdsson)'
|
||
|
|
||
|
|
||
|
Import('env')
|
||
|
env = env.Clone()
|
||
|
|
||
|
# Include paths to gtest headers are relative to a directory two above
|
||
|
# the gtest directory itself, and this SConscript file is one
|
||
|
# directory deeper than the gtest directory.
|
||
|
env.Prepend(CPPPATH = ['../../..'])
|
||
|
|
||
|
# TODO(joi@google.com) Fix the code that causes this warning so that
|
||
|
# we see all warnings from the compiler about possible 64-bit porting
|
||
|
# issues.
|
||
|
env.Append(CCFLAGS=['-wd4267'])
|
||
|
|
||
|
# Sources shared by base library and library that includes main.
|
||
|
gtest_sources = ['../src/gtest-all.cc']
|
||
|
|
||
|
# gtest.lib to be used by most apps (if you have your own main
|
||
|
# function)
|
||
|
gtest = env.StaticLibrary(target='gtest',
|
||
|
source=gtest_sources)
|
||
|
|
||
|
# gtest_main.lib can be used if you just want a basic main function;
|
||
|
# it is also used by the tests for Google Test itself.
|
||
|
gtest_main = env.StaticLibrary(target='gtest_main',
|
||
|
source=gtest_sources + ['../src/gtest_main.cc'])
|
||
|
|
||
|
# Install the libraries if needed.
|
||
|
if 'LIB_OUTPUT' in env.Dictionary():
|
||
|
env.Install('$LIB_OUTPUT', source=[gtest, gtest_main])
|
||
|
|
||
|
|
||
|
def GtestUnitTest(env, target, gtest_lib, additional_sources=None):
|
||
|
"""Helper to create gtest unit tests.
|
||
|
|
||
|
Args:
|
||
|
env: The SCons construction environment to use to build.
|
||
|
target: The basename of the target unit test .cc file.
|
||
|
gtest_lib: The gtest lib to use.
|
||
|
"""
|
||
|
source = [env.File('%s.cc' % target, env.Dir('../test'))]
|
||
|
if additional_sources:
|
||
|
source += additional_sources
|
||
|
unit_test = env.Program(target=target,
|
||
|
source=source,
|
||
|
LIBS=[gtest_lib, 'kernel32.lib', 'user32.lib'])
|
||
|
if 'EXE_OUTPUT' in env.Dictionary():
|
||
|
env.Install('$EXE_OUTPUT', source=[unit_test])
|
||
|
|
||
|
|
||
|
GtestUnitTest(env, 'gtest-filepath_test', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest-message_test', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest-options_test', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest_environment_test', gtest)
|
||
|
GtestUnitTest(env, 'gtest_main_unittest', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest_no_test_unittest', gtest)
|
||
|
GtestUnitTest(env, 'gtest_pred_impl_unittest', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest_prod_test', gtest_main,
|
||
|
additional_sources=['../test/production.cc'])
|
||
|
GtestUnitTest(env, 'gtest_repeat_test', gtest)
|
||
|
GtestUnitTest(env, 'gtest_sole_header_test', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest-test-part_test', gtest_main)
|
||
|
GtestUnitTest(env, 'gtest-typed-test_test', gtest_main,
|
||
|
additional_sources=['../test/gtest-typed-test2_test.cc'])
|
||
|
GtestUnitTest(env, 'gtest_unittest', gtest)
|
||
|
GtestUnitTest(env, 'gtest_output_test_', gtest)
|
||
|
GtestUnitTest(env, 'gtest_color_test_', gtest)
|
||
|
|
||
|
# TODO(wan@google.com) Add these unit tests:
|
||
|
# - gtest_break_on_failure_unittest_
|
||
|
# - gtest_filter_unittest_
|
||
|
# - gtest_list_tests_unittest_
|
||
|
# - gtest_xml_outfile1_test_
|
||
|
# - gtest_xml_outfile2_test_
|
||
|
# - gtest_xml_output_unittest_
|
||
|
|
||
|
# We need to disable some optimization flags for a couple of tests,
|
||
|
# otherwise the redirection of stdout does not work (apparently
|
||
|
# because of a compiler bug).
|
||
|
special_env = env.Clone()
|
||
|
linker_flags = special_env['LINKFLAGS']
|
||
|
for flag in ["/O1", "/Os", "/Og", "/Oy"]:
|
||
|
if flag in linker_flags:
|
||
|
linker_flags.remove(flag)
|
||
|
GtestUnitTest(special_env, 'gtest_env_var_test_', gtest)
|
||
|
GtestUnitTest(special_env, 'gtest_uninitialized_test_', gtest)
|