Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
14 KiB

  1. # -*- Python -*-
  2. # Copyright 2008 Google Inc. All Rights Reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following disclaimer
  12. # in the documentation and/or other materials provided with the
  13. # distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived from
  16. # this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. """Builds the Google Test (gtest) lib. This has been tested on Windows,
  30. Linux, Mac OS X, and Cygwin. The compilation settings from your project
  31. will be used, with some specific flags required for gtest added.
  32. You should be able to call this file from more or less any SConscript
  33. file.
  34. You can optionally set a variable on the construction environment to
  35. have the unit test executables copied to your output directory. The
  36. variable should be env['EXE_OUTPUT'].
  37. Another optional variable is env['LIB_OUTPUT']. If set, the generated
  38. libraries are copied to the folder indicated by the variable.
  39. If you place the gtest sources within your own project's source
  40. directory, you should be able to call this SConscript file simply as
  41. follows:
  42. # -- cut here --
  43. # Build gtest library; first tell it where to copy executables.
  44. env['EXE_OUTPUT'] = '#/mybuilddir/mybuildmode' # example, optional
  45. env['LIB_OUTPUT'] = '#/mybuilddir/mybuildmode/lib'
  46. env.SConscript('whateverpath/gtest/scons/SConscript')
  47. # -- cut here --
  48. If on the other hand you place the gtest sources in a directory
  49. outside of your project's source tree, you would use a snippet similar
  50. to the following:
  51. # -- cut here --
  52. # The following assumes that $BUILD_DIR refers to the root of the
  53. # directory for your current build mode, e.g. "#/mybuilddir/mybuildmode"
  54. # Build gtest library; as it is outside of our source root, we need to
  55. # tell SCons that the directory it will refer to as
  56. # e.g. $BUILD_DIR/gtest is actually on disk in original form as
  57. # ../../gtest (relative to your project root directory). Recall that
  58. # SCons by default copies all source files into the build directory
  59. # before building.
  60. gtest_dir = env.Dir('$BUILD_DIR/gtest')
  61. # Modify this part to point to gtest relative to the current
  62. # SConscript or SConstruct file's directory. The ../.. path would
  63. # be different per project, to locate the base directory for gtest.
  64. gtest_dir.addRepository(env.Dir('../../gtest'))
  65. # Tell the gtest SCons file where to copy executables.
  66. env['EXE_OUTPUT'] = '$BUILD_DIR' # example, optional
  67. # Call the gtest SConscript to build gtest.lib and unit tests. The
  68. # location of the library should end up as
  69. # '$BUILD_DIR/gtest/scons/gtest.lib'
  70. env.SConscript(env.File('scons/SConscript', gtest_dir))
  71. # -- cut here --
  72. """
  73. __author__ = '[email protected] (Joi Sigurdsson)'
  74. import os
  75. ############################################################
  76. # Environments for building the targets, sorted by name.
  77. Import('env', 'EnvCreator')
  78. env = EnvCreator.Create(env)
  79. # Note: The relative paths in SConscript files are relative to the location
  80. # of the SConscript file itself. To make a path relative to the location of
  81. # the main SConstruct file, prepend the path with the # sign.
  82. #
  83. # But if a project uses variant builds without source duplication, the above
  84. # rule gets muddied a bit. In that case the paths must be counted from the
  85. # location of the copy of the SConscript file in scons/build/<config>/scons.
  86. #
  87. # Include paths to gtest headers are relative to either the gtest
  88. # directory or the 'include' subdirectory of it, and this SConscript
  89. # file is one directory deeper than the gtest directory.
  90. env.Prepend(CPPPATH = ['..', '../include'])
  91. env_use_own_tuple = EnvCreator.Create(env, EnvCreator.UseOwnTuple)
  92. env_less_optimized = EnvCreator.Create(env, EnvCreator.LessOptimized)
  93. env_with_threads = EnvCreator.Create(env, EnvCreator.WithThreads)
  94. # The following environments are used to compile gtest_unittest.cc, which
  95. # triggers a warning in all but the most recent GCC versions when compiling
  96. # the EXPECT_EQ(NULL, ptr) statement.
  97. env_warning_ok = EnvCreator.Create(env, EnvCreator.WarningOk)
  98. env_with_exceptions = EnvCreator.Create(env_warning_ok,
  99. EnvCreator.WithExceptions)
  100. env_without_rtti = EnvCreator.Create(env_warning_ok, EnvCreator.NoRtti)
  101. ############################################################
  102. # Helpers for creating build targets.
  103. # Caches object file targets built by GtestObject to allow passing the
  104. # same source file with the same environment twice into the function as a
  105. # convenience.
  106. _all_objects = {}
  107. def GtestObject(build_env, source):
  108. """Returns a target to build an object file from the given .cc source file."""
  109. object_name = os.path.basename(source).rstrip('.cc') + build_env['OBJ_SUFFIX']
  110. if object_name not in _all_objects:
  111. _all_objects[object_name] = build_env.Object(target=object_name,
  112. source=source)
  113. return _all_objects[object_name]
  114. def GtestStaticLibraries(build_env):
  115. """Builds static libraries for gtest and gtest_main in build_env.
  116. Args:
  117. build_env: An environment in which to build libraries.
  118. Returns:
  119. A pair (gtest library, gtest_main library) built in the given environment.
  120. """
  121. gtest_object = GtestObject(build_env, '../src/gtest-all.cc')
  122. gtest_main_object = GtestObject(build_env, '../src/gtest_main.cc')
  123. return (build_env.StaticLibrary(target='gtest' + build_env['OBJ_SUFFIX'],
  124. source=[gtest_object]),
  125. build_env.StaticLibrary(target='gtest_main' + build_env['OBJ_SUFFIX'],
  126. source=[gtest_object, gtest_main_object]))
  127. def GtestBinary(build_env, target, gtest_libs, sources):
  128. """Creates a target to build a binary (either test or sample).
  129. Args:
  130. build_env: The SCons construction environment to use to build.
  131. target: The basename of the target's main source file, also used as the
  132. target name.
  133. gtest_libs: The gtest library or the list of libraries to link.
  134. sources: A list of source files in the target.
  135. """
  136. srcs = [] # The object targets corresponding to sources.
  137. for src in sources:
  138. if type(src) is str:
  139. srcs.append(GtestObject(build_env, src))
  140. else:
  141. srcs.append(src)
  142. if not gtest_libs:
  143. gtest_libs = []
  144. elif type(gtest_libs) != type(list()):
  145. gtest_libs = [gtest_libs]
  146. binary = build_env.Program(target=target, source=srcs, LIBS=gtest_libs)
  147. if 'EXE_OUTPUT' in build_env.Dictionary():
  148. build_env.Install('$EXE_OUTPUT', source=[binary])
  149. def GtestTest(build_env, target, gtest_libs, additional_sources=None):
  150. """Creates a target to build the given test.
  151. Args:
  152. build_env: The SCons construction environment to use to build.
  153. target: The basename of the target test .cc file.
  154. gtest_libs: The gtest library or the list of libraries to use.
  155. additional_sources: A list of additional source files in the target.
  156. """
  157. GtestBinary(build_env, target, gtest_libs,
  158. ['../test/%s.cc' % target] + (additional_sources or []))
  159. def GtestSample(build_env, target, additional_sources=None):
  160. """Creates a target to build the given sample.
  161. Args:
  162. build_env: The SCons construction environment to use to build.
  163. target: The basename of the target sample .cc file.
  164. gtest_libs: The gtest library or the list of libraries to use.
  165. additional_sources: A list of additional source files in the target.
  166. """
  167. GtestBinary(build_env, target, gtest_main,
  168. ['../samples/%s.cc' % target] + (additional_sources or []))
  169. ############################################################
  170. # Object and library targets.
  171. # gtest.lib to be used by most apps (if you have your own main function).
  172. # gtest_main.lib can be used if you just want a basic main function; it is also
  173. # used by some tests for Google Test itself.
  174. gtest, gtest_main = GtestStaticLibraries(env)
  175. gtest_ex, gtest_main_ex = GtestStaticLibraries(env_with_exceptions)
  176. gtest_no_rtti, gtest_main_no_rtti = GtestStaticLibraries(env_without_rtti)
  177. gtest_use_own_tuple, gtest_use_own_tuple_main = GtestStaticLibraries(
  178. env_use_own_tuple)
  179. # Install the libraries if needed.
  180. if 'LIB_OUTPUT' in env.Dictionary():
  181. env.Install('$LIB_OUTPUT', source=[gtest, gtest_main,
  182. gtest_ex, gtest_main_ex,
  183. gtest_no_rtti, gtest_main_no_rtti,
  184. gtest_use_own_tuple,
  185. gtest_use_own_tuple_main])
  186. ############################################################
  187. # Test targets using the standard environment.
  188. GtestTest(env, 'gtest-filepath_test', gtest_main)
  189. GtestTest(env, 'gtest-message_test', gtest_main)
  190. GtestTest(env, 'gtest-options_test', gtest_main)
  191. GtestTest(env, 'gtest_environment_test', gtest)
  192. GtestTest(env, 'gtest_main_unittest', gtest_main)
  193. GtestTest(env, 'gtest_no_test_unittest', gtest)
  194. GtestTest(env, 'gtest_pred_impl_unittest', gtest_main)
  195. GtestTest(env, 'gtest_prod_test', gtest_main,
  196. additional_sources=['../test/production.cc'])
  197. GtestTest(env, 'gtest_repeat_test', gtest)
  198. GtestTest(env, 'gtest_sole_header_test', gtest_main)
  199. GtestTest(env, 'gtest-test-part_test', gtest_main)
  200. GtestTest(env, 'gtest-typed-test_test', gtest_main,
  201. additional_sources=['../test/gtest-typed-test2_test.cc'])
  202. GtestTest(env, 'gtest-param-test_test', gtest,
  203. additional_sources=['../test/gtest-param-test2_test.cc'])
  204. GtestTest(env, 'gtest_color_test_', gtest)
  205. GtestTest(env, 'gtest-linked_ptr_test', gtest_main)
  206. GtestTest(env, 'gtest-port_test', gtest_main)
  207. GtestTest(env, 'gtest_break_on_failure_unittest_', gtest)
  208. GtestTest(env, 'gtest_filter_unittest_', gtest)
  209. GtestTest(env, 'gtest_help_test_', gtest_main)
  210. GtestTest(env, 'gtest_list_tests_unittest_', gtest)
  211. GtestTest(env, 'gtest_throw_on_failure_test_', gtest)
  212. GtestTest(env, 'gtest_xml_outfile1_test_', gtest_main)
  213. GtestTest(env, 'gtest_xml_outfile2_test_', gtest_main)
  214. GtestTest(env, 'gtest_xml_output_unittest_', gtest)
  215. GtestTest(env, 'gtest-unittest-api_test', gtest)
  216. GtestTest(env, 'gtest-listener_test', gtest)
  217. GtestTest(env, 'gtest_shuffle_test_', gtest)
  218. ############################################################
  219. # Tests targets using custom environments.
  220. GtestTest(env_warning_ok, 'gtest_unittest', gtest_main)
  221. GtestTest(env_with_exceptions, 'gtest_output_test_', gtest_ex)
  222. GtestTest(env_with_exceptions, 'gtest_throw_on_failure_ex_test', gtest_ex)
  223. GtestTest(env_with_threads, 'gtest-death-test_test', gtest_main)
  224. GtestTest(env_less_optimized, 'gtest_env_var_test_', gtest)
  225. GtestTest(env_less_optimized, 'gtest_uninitialized_test_', gtest)
  226. GtestTest(env_use_own_tuple, 'gtest-tuple_test', gtest_use_own_tuple_main)
  227. GtestBinary(env_use_own_tuple,
  228. 'gtest_use_own_tuple_test',
  229. gtest_use_own_tuple_main,
  230. ['../test/gtest-param-test_test.cc',
  231. '../test/gtest-param-test2_test.cc'])
  232. GtestBinary(env_with_exceptions, 'gtest_ex_unittest', gtest_main_ex,
  233. ['../test/gtest_unittest.cc'])
  234. GtestBinary(env_without_rtti, 'gtest_no_rtti_test', gtest_main_no_rtti,
  235. ['../test/gtest_unittest.cc'])
  236. ############################################################
  237. # Sample targets.
  238. # Use the GTEST_BUILD_SAMPLES build variable to control building of samples.
  239. # In your SConstruct file, add
  240. # vars = Variables()
  241. # vars.Add(BoolVariable('GTEST_BUILD_SAMPLES', 'Build samples', False))
  242. # my_environment = Environment(variables = vars, ...)
  243. # Then, in the command line use GTEST_BUILD_SAMPLES=true to enable them.
  244. if env.get('GTEST_BUILD_SAMPLES', False):
  245. GtestSample(env, 'sample1_unittest',
  246. additional_sources=['../samples/sample1.cc'])
  247. GtestSample(env, 'sample2_unittest',
  248. additional_sources=['../samples/sample2.cc'])
  249. GtestSample(env, 'sample3_unittest')
  250. GtestSample(env, 'sample4_unittest',
  251. additional_sources=['../samples/sample4.cc'])
  252. GtestSample(env, 'sample5_unittest',
  253. additional_sources=['../samples/sample1.cc'])
  254. GtestSample(env, 'sample6_unittest')
  255. GtestSample(env, 'sample7_unittest')
  256. GtestSample(env, 'sample8_unittest')
  257. GtestSample(env, 'sample9_unittest')
  258. GtestSample(env, 'sample10_unittest')
  259. # These exports are used by Google Mock.
  260. gtest_exports = {'gtest': gtest,
  261. 'gtest_ex': gtest_ex,
  262. 'gtest_no_rtti': gtest_no_rtti,
  263. 'gtest_use_own_tuple': gtest_use_own_tuple,
  264. 'EnvCreator': EnvCreator,
  265. 'GtestObject': GtestObject,
  266. 'GtestBinary': GtestBinary,
  267. 'GtestTest': GtestTest}
  268. # Makes the gtest_exports dictionary available to the invoking SConstruct.
  269. Return('gtest_exports')