diff options
Diffstat (limited to 'scons')
-rw-r--r-- | scons/SConscript | 362 | ||||
-rw-r--r-- | scons/SConscript.common | 156 | ||||
-rw-r--r-- | scons/SConstruct | 59 | ||||
-rw-r--r-- | scons/SConstruct.common | 261 |
4 files changed, 0 insertions, 838 deletions
diff --git a/scons/SConscript b/scons/SConscript deleted file mode 100644 index 1e19df7..0000000 --- a/scons/SConscript +++ /dev/null @@ -1,362 +0,0 @@ -# -*- 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 Test (gtest) lib. This has been tested on Windows, -Linux, Mac OS X, and Cygwin. 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 os - -############################################################ -# Environments for building the targets, sorted by name. - -Import('env') -env = env.Clone() - -BUILD_TESTS = env.get('GTEST_BUILD_TESTS', False) -common_exports = SConscript('SConscript.common') -EnvCreator = common_exports['EnvCreator'] - -# 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. -# -# But if a project uses variant builds without source duplication (see -# http://www.scons.org/wiki/VariantDir%28%29 for more information), the -# above rule gets muddied a bit. In that case the paths must be counted from -# the location of the copy of the SConscript file in -# scons/build/<config>/gtest/scons. -# -# Include paths to gtest headers are relative to either the gtest -# directory or the 'include' subdirectory of it, and this SConscript -# file is one directory deeper than the gtest directory. -env.Prepend(CPPPATH = ['..', '../include']) - -env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple) -env_less_optimized = EnvCreator.Create(env, EnvCreator.LessOptimized) -env_with_threads = EnvCreator.Create(env, EnvCreator.WithThreads) -# The following environments are used to compile gtest_unittest.cc, which -# triggers a warning in all but the most recent GCC versions when compiling -# the EXPECT_EQ(NULL, ptr) statement. -env_warning_ok = EnvCreator.Create(env, EnvCreator.WarningOk) -env_with_exceptions = EnvCreator.Create(env_warning_ok, - EnvCreator.WithExceptions) -env_without_rtti = EnvCreator.Create(env_warning_ok, EnvCreator.NoRtti) - -env_with_exceptions_and_threads = EnvCreator.Create(env_with_threads, - EnvCreator.WithExceptions) -env_with_exceptions_and_threads['OBJ_SUFFIX'] = '_with_exceptions_and_threads' - -############################################################ -# Helpers for creating build targets. - -# Caches object file targets built by GtestObject to allow passing the -# same source file with the same environment twice into the function as a -# convenience. -_all_objects = {} - - -def GetObjSuffix(env): - return env.get('OBJ_SUFFIX', '') - -def GtestObject(build_env, source): - """Returns a target to build an object file from the given .cc source file.""" - - object_name = os.path.basename(source).rstrip('.cc') + GetObjSuffix(build_env) - if object_name not in _all_objects: - _all_objects[object_name] = build_env.Object(target=object_name, - source=source) - return _all_objects[object_name] - - -def GtestStaticLibraries(build_env): - """Builds static libraries for gtest and gtest_main in build_env. - - Args: - build_env: An environment in which to build libraries. - - Returns: - A pair (gtest library, gtest_main library) built in the given environment. - """ - - gtest_object = GtestObject(build_env, '../src/gtest-all.cc') - gtest_main_object = GtestObject(build_env, '../src/gtest_main.cc') - - return (build_env.StaticLibrary(target='gtest' + GetObjSuffix(build_env), - source=[gtest_object]), - build_env.StaticLibrary(target='gtest_main' + GetObjSuffix(build_env), - source=[gtest_object, gtest_main_object])) - - -def GtestBinary(build_env, target, gtest_libs, sources): - """Creates a target to build a binary (either test or sample). - - Args: - build_env: The SCons construction environment to use to build. - target: The basename of the target's main source file, also used as the - target name. - gtest_libs: The gtest library or the list of libraries to link. - sources: A list of source files in the target. - """ - srcs = [] # The object targets corresponding to sources. - for src in sources: - if type(src) is str: - srcs.append(GtestObject(build_env, src)) - else: - srcs.append(src) - - if not gtest_libs: - gtest_libs = [] - elif type(gtest_libs) != type(list()): - gtest_libs = [gtest_libs] - binary = build_env.Program(target=target, source=srcs, LIBS=gtest_libs) - if 'EXE_OUTPUT' in build_env.Dictionary(): - build_env.Install('$EXE_OUTPUT', source=[binary]) - - -def GtestTest(build_env, target, gtest_libs, additional_sources=None): - """Creates a target to build the given test. - - Args: - build_env: The SCons construction environment to use to build. - target: The basename of the target test .cc file. - gtest_libs: The gtest library or the list of libraries to use. - additional_sources: A list of additional source files in the target. - """ - - GtestBinary(build_env, target, gtest_libs, - ['../test/%s.cc' % target] + (additional_sources or [])) - - -def GtestSample(build_env, target, additional_sources=None): - """Creates a target to build the given sample. - - Args: - build_env: The SCons construction environment to use to build. - target: The basename of the target sample .cc file. - gtest_libs: The gtest library or the list of libraries to use. - additional_sources: A list of additional source files in the target. - """ - GtestBinary(build_env, target, gtest_main, - ['../samples/%s.cc' % target] + (additional_sources or [])) - - -############################################################ -# Object and library targets. - -# gtest.lib to be used by most apps (if you have your own main function). -# gtest_main.lib can be used if you just want a basic main function; it is also -# used by some tests for Google Test itself. -gtest, gtest_main = GtestStaticLibraries(env) -gtest_ex, gtest_main_ex = GtestStaticLibraries(env_with_exceptions) -gtest_no_rtti, gtest_main_no_rtti = GtestStaticLibraries(env_without_rtti) -gtest_use_own_tuple, gtest_main_use_own_tuple = GtestStaticLibraries( - env_use_own_tuple) -gtest_with_threads, gtest_main_with_threads = GtestStaticLibraries( - env_with_threads) -gtest_ex_with_threads, gtest_main_ex_with_threads = GtestStaticLibraries( - env_with_exceptions_and_threads) - -# Install the libraries if needed. -if 'LIB_OUTPUT' in env.Dictionary(): - env.Install('$LIB_OUTPUT', source=[gtest, gtest_main]) - -if BUILD_TESTS: - ############################################################ - # Test targets using the standard environment. - GtestTest(env, 'gtest-filepath_test', gtest_main) - GtestTest(env, 'gtest-message_test', gtest_main) - GtestTest(env, 'gtest-options_test', gtest_main) - GtestTest(env, 'gtest_environment_test', gtest) - GtestTest(env, 'gtest_main_unittest', gtest_main) - GtestTest(env, 'gtest_no_test_unittest', gtest) - GtestTest(env, 'gtest_pred_impl_unittest', gtest_main) - GtestTest(env, 'gtest_prod_test', gtest_main, - additional_sources=['../test/production.cc']) - GtestTest(env, 'gtest_repeat_test', gtest) - GtestTest(env, 'gtest_sole_header_test', gtest_main) - GtestTest(env, 'gtest-test-part_test', gtest_main) - GtestTest(env, 'gtest-typed-test_test', gtest_main, - additional_sources=['../test/gtest-typed-test2_test.cc']) - GtestTest(env, 'gtest-param-test_test', gtest, - additional_sources=['../test/gtest-param-test2_test.cc']) - GtestTest(env, 'gtest_color_test_', gtest) - GtestTest(env, 'gtest-linked_ptr_test', gtest_main) - GtestTest(env, 'gtest_break_on_failure_unittest_', gtest) - GtestTest(env, 'gtest_filter_unittest_', gtest) - GtestTest(env, 'gtest_help_test_', gtest_main) - GtestTest(env, 'gtest_list_tests_unittest_', gtest) - GtestTest(env, 'gtest_throw_on_failure_test_', gtest) - GtestTest(env, 'gtest_xml_outfile1_test_', gtest_main) - GtestTest(env, 'gtest_xml_outfile2_test_', gtest_main) - GtestTest(env, 'gtest_xml_output_unittest_', gtest) - GtestTest(env, 'gtest-unittest-api_test', gtest) - GtestTest(env, 'gtest-listener_test', gtest) - GtestTest(env, 'gtest_shuffle_test_', gtest) - - ############################################################ - # Tests targets using custom environments. - GtestTest(env_warning_ok, 'gtest_unittest', gtest_main) - GtestTest(env_with_exceptions_and_threads, 'gtest_output_test_', - gtest_ex_with_threads) - GtestTest(env_with_exceptions, 'gtest_throw_on_failure_ex_test', gtest_ex) - GtestTest(env_with_threads, 'gtest-death-test_test', gtest_main_with_threads) - GtestTest(env_with_threads, 'gtest-port_test', gtest_main_with_threads) - GtestTest(env_with_threads, 'gtest_stress_test', gtest_with_threads) - GtestTest(env_less_optimized, 'gtest_env_var_test_', gtest) - GtestTest(env_less_optimized, 'gtest_uninitialized_test_', gtest) - GtestTest(env_use_own_tuple, 'gtest-tuple_test', gtest_main_use_own_tuple) - GtestBinary(env_use_own_tuple, - 'gtest_use_own_tuple_test', - gtest_main_use_own_tuple, - ['../test/gtest-param-test_test.cc', - '../test/gtest-param-test2_test.cc']) - GtestBinary(env_with_exceptions, 'gtest_ex_unittest', gtest_main_ex, - ['../test/gtest_unittest.cc']) - GtestBinary(env_without_rtti, 'gtest_no_rtti_test', gtest_main_no_rtti, - ['../test/gtest_unittest.cc']) - - # Tests that gtest works when built as a DLL on Windows. - # We don't need to actually run this test. - # Note: this is not supported under VC 7.1. - if env['PLATFORM'] == 'win32' and env.get('GTEST_BUILD_DLL_TEST', None): - test_env = EnvCreator.Create(env, EnvCreator.DllBuild) - dll_env = test_env.Clone() - dll_env.Append(LINKFLAGS=['-DEF:../msvc/gtest.def']) - - gtest_dll = dll_env.SharedLibrary( - target='gtest_dll', - source=[dll_env.SharedObject('gtest_all_dll', - '../src/gtest-all.cc'), - dll_env.SharedObject('gtest_main_dll', - '../src/gtest_main.cc')]) - # TODO(vladl@google.com): Get rid of the .data[1] hack. Find a proper - # way to depend on a shared library without knowing its path in advance. - test_env.Program('gtest_dll_test_', - ['../test/gtest_dll_test_.cc', gtest_dll.data[1]]) - -############################################################ -# Sample targets. - -# Use the GTEST_BUILD_SAMPLES build variable to control building of samples. -# In your SConstruct file, add -# vars = Variables() -# vars.Add(BoolVariable('GTEST_BUILD_SAMPLES', 'Build samples', False)) -# my_environment = Environment(variables = vars, ...) -# Then, in the command line use GTEST_BUILD_SAMPLES=true to enable them. -if env.get('GTEST_BUILD_SAMPLES', False): - GtestSample(env, 'sample1_unittest', - additional_sources=['../samples/sample1.cc']) - GtestSample(env, 'sample2_unittest', - additional_sources=['../samples/sample2.cc']) - GtestSample(env, 'sample3_unittest') - GtestSample(env, 'sample4_unittest', - additional_sources=['../samples/sample4.cc']) - GtestSample(env, 'sample5_unittest', - additional_sources=['../samples/sample1.cc']) - GtestSample(env, 'sample6_unittest') - GtestSample(env, 'sample7_unittest') - GtestSample(env, 'sample8_unittest') - GtestSample(env, 'sample9_unittest') - GtestSample(env, 'sample10_unittest') - -gtest_exports = {'gtest': gtest, - 'gtest_main': gtest_main, - 'gtest_ex': gtest_ex, - 'gtest_main_ex': gtest_main_ex, - 'gtest_no_rtti': gtest_no_rtti, - 'gtest_main_no_rtti': gtest_main_no_rtti, - 'gtest_use_own_tuple': gtest_use_own_tuple, - 'gtest_main_use_own_tuple': gtest_main_use_own_tuple, - # These exports are used by Google Mock. - 'GtestObject': GtestObject, - 'GtestBinary': GtestBinary, - 'GtestTest': GtestTest} - -# Makes the gtest_exports dictionary available to the invoking SConstruct. -Return('gtest_exports') diff --git a/scons/SConscript.common b/scons/SConscript.common deleted file mode 100644 index adefa58..0000000 --- a/scons/SConscript.common +++ /dev/null @@ -1,156 +0,0 @@ -# -*- 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: vladl@google.com (Vlad Losev) -# -# Shared SCons utilities for building Google Test's own tests. -# - -EnsurePythonVersion(2, 3) - - -class EnvCreator: - """Creates new customized environments from a base one.""" - - def _Remove(cls, env, attribute, value): - """Removes the given attribute value from the environment.""" - - attribute_values = env[attribute] - if value in attribute_values: - attribute_values.remove(value) - _Remove = classmethod(_Remove) - - def Create(cls, base_env, modifier=None): - # User should NOT create more than one environment with the same - # modifier (including None). - env = base_env.Clone() - if modifier: - modifier(env) - return env; - Create = classmethod(Create) - - # Each of the following methods modifies the environment for a particular - # purpose and can be used by clients for creating new environments. Each - # one needs to set the OBJ_SUFFIX variable to a unique suffix to - # differentiate targets built with that environment. Otherwise, SCons may - # complain about same target built with different settings. - - def UseOwnTuple(cls, env): - """Instructs Google Test to use its internal implementation of tuple.""" - - env['OBJ_SUFFIX'] = '_use_own_tuple' - env.Append(CPPDEFINES = 'GTEST_USE_OWN_TR1_TUPLE=1') - UseOwnTuple = classmethod(UseOwnTuple) - - def WarningOk(cls, env): - """Does not treat warnings as errors. - - Necessary for compiling gtest_unittest.cc, which triggers a gcc - warning when testing EXPECT_EQ(NULL, ptr).""" - - env['OBJ_SUFFIX'] = '_warning_ok' - if env['PLATFORM'] == 'win32': - cls._Remove(env, 'CCFLAGS', '-WX') - else: - cls._Remove(env, 'CCFLAGS', '-Werror') - WarningOk = classmethod(WarningOk) - - def WithExceptions(cls, env): - """Re-enables exceptions.""" - - env['OBJ_SUFFIX'] = '_ex' - if env['PLATFORM'] == 'win32': - env.Append(CCFLAGS=['/EHsc']) - env.Append(CPPDEFINES='_HAS_EXCEPTIONS=1') - cls._Remove(env, 'CPPDEFINES', '_HAS_EXCEPTIONS=0') - else: - env.Append(CCFLAGS='-fexceptions') - cls._Remove(env, 'CCFLAGS', '-fno-exceptions') - WithExceptions = classmethod(WithExceptions) - - def LessOptimized(cls, env): - """Disables certain optimizations on Windows. - - We need to disable some optimization flags for some tests on - Windows; otherwise the redirection of stdout does not work - (apparently because of a compiler bug).""" - - env['OBJ_SUFFIX'] = '_less_optimized' - if env['PLATFORM'] == 'win32': - for flag in ['/O1', '/Os', '/Og', '/Oy']: - cls._Remove(env, 'LINKFLAGS', flag) - LessOptimized = classmethod(LessOptimized) - - def WithThreads(cls, env): - """Allows use of threads. - - Currently only enables pthreads under GCC.""" - - env['OBJ_SUFFIX'] = '_with_threads' - if env['PLATFORM'] != 'win32': - # Assuming POSIX-like environment with GCC. - # TODO(vladl@google.com): sniff presence of pthread_atfork instead of - # selecting on a platform. - env.Append(CCFLAGS=['-pthread']) - env.Append(LINKFLAGS=['-pthread']) - env.Append(CPPDEFINES='GTEST_HAS_PTHREAD=1') - WithThreads = classmethod(WithThreads) - - def NoRtti(cls, env): - """Disables RTTI support.""" - - env['OBJ_SUFFIX'] = '_no_rtti' - if env['PLATFORM'] == 'win32': - env.Append(CCFLAGS=['/GR-']) - else: - env.Append(CCFLAGS=['-fno-rtti']) - env.Append(CPPDEFINES='GTEST_HAS_RTTI=0') - NoRtti = classmethod(NoRtti) - - def DllBuild(cls, env): - """Enables building gtets as a DLL.""" - - env['OBJ_SUFFIX'] = '_dll' - # -MT(d) instructs MSVC to link to the static version of the C++ - # runtime library; -MD(d) tells it to link to the DLL version. - flags = env['CCFLAGS'] - if '-MTd' in flags: - flags.remove('-MTd') - flags.append('-MDd') - elif '-MT' in flags: - flags.remove('-MT') - flags.append('-MD') - - # Disables the "non dll-interface class 'stdext::exception' used as - # base for dll-interface class" warning triggered by the STL code. - env.Append(CCFLAGS=['/wd4275']) - DllBuild = classmethod(DllBuild) - -sconscript_exports = {'EnvCreator': EnvCreator} -Return('sconscript_exports') diff --git a/scons/SConstruct b/scons/SConstruct deleted file mode 100644 index 5c0b038..0000000 --- a/scons/SConstruct +++ /dev/null @@ -1,59 +0,0 @@ -# -*- 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) -# -# Base build file for Google Test 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-opt8 build the given build type. - -EnsurePythonVersion(2, 3) - -sconstruct_helper = SConscript('SConstruct.common') - -sconstruct_helper.Initialize(build_root_path='..', - support_multiple_win_builds=False) - -win_base = sconstruct_helper.MakeWinBaseEnvironment() -win_base['GTEST_BUILD_DLL_TEST'] = True - -sconstruct_helper.MakeWinDebugEnvironment(win_base, 'win-dbg8') -sconstruct_helper.MakeWinOptimizedEnvironment(win_base, 'win-opt8') - -sconstruct_helper.ConfigureGccEnvironments() - -sconstruct_helper.BuildSelectedEnvironments() diff --git a/scons/SConstruct.common b/scons/SConstruct.common deleted file mode 100644 index 6b10033..0000000 --- a/scons/SConstruct.common +++ /dev/null @@ -1,261 +0,0 @@ -# -*- 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) -# -# Shared SCons utilities for building Google Test inside and outside of -# Google's environment. -# - -EnsurePythonVersion(2, 3) - - -BUILD_DIR_PREFIX = 'build' - - -class SConstructHelper: - def __init__(self): - # A dictionary to look up an environment by its name. - self.env_dict = {} - - def _Remove(self, env, attribute, value): - """Removes the given attribute value from the environment.""" - - attribute_values = env[attribute] - if value in attribute_values: - attribute_values.remove(value) - - def Initialize(self, build_root_path, support_multiple_win_builds=False): - test_env = Environment() - platform = test_env['PLATFORM'] - if platform == 'win32': - available_build_types = ['win-dbg8', 'win-opt8'] - elif platform == 'darwin': # MacOSX - available_build_types = ['mac-dbg', 'mac-opt'] - else: - available_build_types = ['dbg', 'opt'] # Assuming POSIX-like environment - # with GCC by default. - - vars = Variables() - vars.Add(ListVariable('BUILD', 'Build type', available_build_types[0], - available_build_types)) - vars.Add(BoolVariable('GTEST_BUILD_SAMPLES', 'Build samples', False)) - vars.Add(BoolVariable('GTEST_BUILD_TESTS', 'Build tests', True)) - - # Create base environment. - self.env_base = Environment(variables=vars, - BUILD_MODE={'BUILD' : '"${BUILD}"'}) - - # Leave around a variable pointing at the build root so that SConscript - # files from outside our project root can find their bearings. Trick - # borrowed from Hammer in Software Construction Toolkit - # (http://code.google.com/p/swtoolkit/); if/when we switch to using the - # Hammer idioms instead of just Hammer's version of SCons, we should be - # able to remove this line. - self.env_base['SOURCE_ROOT'] = self.env_base.Dir(build_root_path) - - # And another that definitely always points to the project root. - self.env_base['PROJECT_ROOT'] = self.env_base.Dir('.').abspath - - self.env_base['OBJ_SUFFIX'] = '' # Default suffix for object files. - - # Enable scons -h - Help(vars.GenerateHelpText(self.env_base)) - - def EnableExceptions(self, env): - if env['PLATFORM'] == 'win32': - env.Append(CCFLAGS=['/EHsc']) - env.Append(CPPDEFINES='_HAS_EXCEPTIONS=1') - self._Remove(env, 'CPPDEFINES', '_HAS_EXCEPTIONS=0') - else: - env.Append(CCFLAGS='-fexceptions') - self._Remove(env, 'CCFLAGS', '-fno-exceptions') - - def MakeWinBaseEnvironment(self): - win_base = self.env_base.Clone( - platform='win32', - CCFLAGS=['-GS', # Enable buffer security check - '-W4', # Warning level - - # Disables warnings that are either uninteresting or - # hard to fix. - - '-WX', # Treat warning as errors - #'-GR-', # Disable runtime type information - '-RTCs', # Enable stack-frame run-time error checks - '-RTCu', # Report when variable used without init. - #'-EHs', # enable C++ EH (no SEH exceptions) - '-nologo', # Suppress logo line - '-J', # All chars unsigned - #'-Wp64', # Detect 64-bit portability issues. This - # flag has been deprecated by VS 2008. - '-Zi', # Produce debug information in PDB files. - ], - CCPDBFLAGS='', - CPPDEFINES=['_UNICODE', 'UNICODE', - 'WIN32', '_WIN32', - 'STRICT', - 'WIN32_LEAN_AND_MEAN', - '_HAS_EXCEPTIONS=0', - ], - LIBPATH=['#/$MAIN_DIR/lib'], - LINKFLAGS=['-MACHINE:x86', # Enable safe SEH (not supp. on x64) - '-DEBUG', # Generate debug info - '-NOLOGO', # Suppress logo line - ], - # All strings in string tables zero terminated. - RCFLAGS=['-n']) - - return win_base - - def SetBuildNameAndDir(self, env, name): - env['BUILD_NAME'] = name; - env['BUILD_DIR'] = '%s/%s' % (BUILD_DIR_PREFIX, name) - self.env_dict[name] = env - - def MakeWinDebugEnvironment(self, base_environment, name): - """Takes an MSVC base environment and adds debug settings.""" - debug_env = base_environment.Clone() - self.SetBuildNameAndDir(debug_env, name) - debug_env.Append( - CCFLAGS = ['-Od', # Disable optimizations - '-MTd', # Multithreaded, static link (debug) - # Path for PDB files - '-Fd%s\\' % debug_env.Dir(debug_env['BUILD_DIR']), - ], - CPPDEFINES = ['DEBUG', - '_DEBUG', - ], - LIBPATH = [], - LINKFLAGS = ['-INCREMENTAL:yes', - '/OPT:NOICF', - ] - ) - return debug_env - - def MakeWinOptimizedEnvironment(self, base_environment, name): - """Takes an MSVC base environment and adds release settings.""" - optimized_env = base_environment.Clone() - self.SetBuildNameAndDir(optimized_env, name) - optimized_env.Append( - CCFLAGS = ['-GL', # Enable link-time code generation (/GL) - '-GF', # Enable String Pooling (/GF) - '-MT', # Multithreaded, static link - # Path for PDB files - '-Fd%s\\' % optimized_env.Dir(optimized_env['BUILD_DIR']), - - # Favor small code (this is /O1 minus /Og) - '-Os', - '-Oy', - '-Ob2', - '-Gs', - '-GF', - '-Gy', - ], - CPPDEFINES = ['NDEBUG', - '_NDEBUG', - ], - LIBPATH = [], - ARFLAGS = ['-LTCG'], # Link-time Code Generation - LINKFLAGS = ['-LTCG', # Link-time Code Generation - '-OPT:REF', # Optimize by reference. - '-OPT:ICF=32', # Optimize by identical COMDAT folding - '-OPT:NOWIN98', # Optimize by not aligning section for - # Win98 - '-INCREMENTAL:NO', # No incremental linking as we don't - # want padding bytes in release build. - ], - ) - return optimized_env - - def AddGccFlagsTo(self, env, optimized): - env.Append(CCFLAGS=['-fno-exceptions', - '-Wall', - '-Werror', - '-Wshadow', - '-DGTEST_HAS_PTHREAD=1' - ]) - env.Append(LINKFLAGS=['-pthread']) - if optimized: - env.Append(CCFLAGS=['-O2'], CPPDEFINES=['NDEBUG', '_NDEBUG']) - else: - env.Append(CCFLAGS=['-g'], CPPDEFINES=['DEBUG', '_DEBUG']) - - def ConfigureGccEnvironments(self): - # Mac environments. - mac_base = self.env_base.Clone(platform='darwin') - - mac_dbg = mac_base.Clone() - self.AddGccFlagsTo(mac_dbg, optimized=False) - self.SetBuildNameAndDir(mac_dbg, 'mac-dbg') - - mac_opt = mac_base.Clone() - self.AddGccFlagsTo(mac_opt, optimized=True) - self.SetBuildNameAndDir(mac_opt, 'mac-opt') - - # Generic GCC environments. - gcc_dbg = self.env_base.Clone() - self.AddGccFlagsTo(gcc_dbg, optimized=False) - self.SetBuildNameAndDir(gcc_dbg, 'dbg') - - gcc_opt = self.env_base.Clone() - self.AddGccFlagsTo(gcc_opt, optimized=True) - self.SetBuildNameAndDir(gcc_opt, 'opt') - - def BuildSelectedEnvironments(self): - # Build using whichever environments the 'BUILD' option selected - for build_name in self.env_base['BUILD']: - print 'BUILDING %s' % build_name - env = self.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'] - - 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'], src_dir='../..', duplicate=0); - SConscript(env['BUILD_DIR'] + '/gtest/scons/SConscript') - - -sconstruct_helper = SConstructHelper() -Return('sconstruct_helper') |