vladlosev | b006f16 | 2009-11-18 00:44:26 +0000 | [diff] [blame] | 1 | # -*- 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 | |
| 34 | You should be able to call this file from more or less any SConscript |
| 35 | file. |
| 36 | |
| 37 | You can optionally set a variable on the construction environment to |
| 38 | have the unit test executables copied to your output directory. The |
| 39 | variable should be env['EXE_OUTPUT']. |
| 40 | |
| 41 | Another optional variable is env['LIB_OUTPUT']. If set, the generated |
| 42 | libraries are copied to the folder indicated by the variable. |
| 43 | |
| 44 | If you place the Google Mock sources within your own project's source |
| 45 | directory, you should be able to call this SConscript file simply as |
| 46 | follows: |
| 47 | |
| 48 | # -- cut here -- |
| 49 | # Build gmock library; first tell it where to copy executables. |
| 50 | env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode' # example, optional |
| 51 | env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib' |
| 52 | env.SConscript('whateverpath/gmock/scons/SConscript') |
| 53 | # -- cut here -- |
| 54 | |
| 55 | If on the other hand you place the Google Mock sources in a directory |
| 56 | outside of your project's source tree, you would use a snippet similar |
| 57 | to 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. |
| 70 | gmock_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. |
| 75 | gmock_dir.addRepository(env.Dir('../../gmock')) |
| 76 | |
| 77 | # Tell the Google Mock SCons file where to copy executables. |
| 78 | env['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' |
| 83 | env.SConscript(env.File('scons/SConscript', gmock_dir)) |
| 84 | |
| 85 | # -- cut here -- |
| 86 | """ |
| 87 | |
| 88 | |
| 89 | __author__ = 'joi@google.com (Joi Sigurdsson)' |
| 90 | |
| 91 | |
| 92 | import os |
| 93 | |
| 94 | ############################################################ |
| 95 | # Environments for building the targets, sorted by name. |
| 96 | |
| 97 | Import('env', 'gtest_exports') |
| 98 | |
| 99 | GTEST_DIR = env['GTEST_DIR'] |
| 100 | |
| 101 | GtestObject = gtest_exports['GtestObject'] |
| 102 | GtestBinary = gtest_exports['GtestBinary'] |
| 103 | GtestTest = gtest_exports['GtestTest'] |
| 104 | |
| 105 | gtest_common_exports = SConscript(GTEST_DIR + '/scons/SConscript.common') |
| 106 | EnvCreator = gtest_common_exports['EnvCreator'] |
| 107 | |
zhanyong.wan | 32de5f5 | 2009-12-23 00:13:23 +0000 | [diff] [blame] | 108 | env = env.Clone() |
| 109 | if 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.wan | 32de5f5 | 2009-12-23 00:13:23 +0000 | [diff] [blame] | 113 | ]) |
vladlosev | b006f16 | 2009-11-18 00:44:26 +0000 | [diff] [blame] | 114 | |
| 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. |
| 122 | env.Prepend(CPPPATH = ['..', '../include', GTEST_DIR + '/include']) |
| 123 | |
| 124 | env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple) |
| 125 | env_with_exceptions = EnvCreator.Create(env, EnvCreator.WithExceptions) |
| 126 | env_without_rtti = EnvCreator.Create(env, EnvCreator.NoRtti) |
| 127 | |
| 128 | ############################################################ |
| 129 | # Helpers for creating build targets. |
| 130 | |
| 131 | def 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 | |
| 154 | gtest = gtest_exports['gtest'] |
| 155 | gtest_ex = gtest_exports['gtest_ex'] |
| 156 | gtest_no_rtti = gtest_exports['gtest_no_rtti'] |
| 157 | gtest_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. |
| 162 | gmock, gmock_main = GmockStaticLibraries(env) |
| 163 | gmock_ex, gmock_main_ex = GmockStaticLibraries(env_with_exceptions) |
| 164 | gmock_no_rtti, gmock_main_no_rtti = GmockStaticLibraries(env_without_rtti) |
| 165 | gmock_use_own_tuple, gmock_main_use_own_tuple = GmockStaticLibraries( |
| 166 | env_use_own_tuple) |
| 167 | |
| 168 | # Install the libraries if needed. |
| 169 | if '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. |
| 178 | GtestTest(env, 'gmock-actions_test', [gtest, gmock_main]) |
| 179 | GtestTest(env, 'gmock-cardinalities_test', [gtest, gmock_main]) |
| 180 | GtestTest(env, 'gmock-generated-actions_test', [gtest, gmock_main]) |
| 181 | GtestTest(env, 'gmock-generated-function-mockers_test', [gtest, gmock_main]) |
| 182 | GtestTest(env, 'gmock-generated-internal-utils_test', [gtest, gmock_main]) |
| 183 | GtestTest(env, 'gmock-generated-matchers_test', [gtest, gmock_main]) |
| 184 | GtestTest(env, 'gmock-internal-utils_test', [gtest, gmock_main]) |
| 185 | GtestTest(env, 'gmock-matchers_test', [gtest, gmock_main]) |
| 186 | GtestTest(env, 'gmock-more-actions_test', [gtest, gmock_main]) |
| 187 | GtestTest(env, 'gmock-nice-strict_test', [gtest, gmock_main]) |
| 188 | GtestTest(env, 'gmock-port_test', [gtest, gmock_main]) |
| 189 | GtestTest(env, 'gmock-printers_test', [gtest, gmock_main]) |
| 190 | GtestTest(env, 'gmock-spec-builders_test', [gtest, gmock_main]) |
| 191 | GtestTest(env, 'gmock_leak_test_', [gtest, gmock_main]) |
| 192 | GtestTest(env, 'gmock_link_test', [gtest, gmock_main], |
| 193 | ['../test/gmock_link2_test.cc']) |
| 194 | GtestTest(env, 'gmock_output_test_', [gtest, gmock]) |
| 195 | #GtestTest(env, 'gmock_stress_test', [gtest, gmock]) |
| 196 | GtestTest(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]) |
vladlosev | b006f16 | 2009-11-18 00:44:26 +0000 | [diff] [blame] | 200 | |
| 201 | ############################################################ |
| 202 | # Tests targets using custom environments. |
| 203 | GtestBinary(env_with_exceptions, |
| 204 | 'gmock-more-actions-ex_test', |
| 205 | [gtest_ex, gmock_main_ex], |
| 206 | ['../test/gmock-more-actions_test.cc']) |
| 207 | |
| 208 | GtestBinary(env_without_rtti, |
| 209 | 'gmock_no_rtti_test', |
| 210 | [gtest_no_rtti, gmock_main_no_rtti], |
| 211 | ['../test/gmock-spec-builders_test.cc']) |
| 212 | |
| 213 | GtestBinary(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']) |