main.scons revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1# -*- Python -*- 2# This is the main file of the hammer/scons build for magicflute. 3# 4# All the helper functions are defined in: 5# - site_scons/talk.py 6# Use 'import talk' in any .scons file to get access to it. 7# Add any new helper functions to it; unittest are available 8# in talk_unittest.py. 9# 10# Each 'component' that is built is defined in a .scons file. 11# See talk.Components(...) for further info on file naming convention. 12# 13# To add a new platform clone and modify the root_env object. Remember to add 14# the new environment object to the envs list otherwise it will not be included 15# in the build. 16# 17# 18# For more documentation and information check: 19# https://sites.google.com/a/google.com/wavelet/Home/Magic-Flute--RTC-Engine- 20# 21import talk 22import os 23 24#------------------------------------------------------------------------------- 25# The build files/directories to 'build'. 26# If the name is the name of a directory then that directory shall contain a 27# .scons file with the same name as the directory itself: 28# Ex: The directory magicflute contains a file called magicflute.scons 29# 30components = talk.Components("libjingle.scons") 31 32#------------------------------------------------------------------------------- 33# Build environments 34# 35 36# The list of build environments. 37envs = [] 38 39# The root of all builds. 40root_env = Environment( 41 tools = [ 42 'component_bits', 43 'component_setup', 44 'replace_strings', 45 'talk_noops', 46 ], 47 BUILD_SCONSCRIPTS = components, 48 DESTINATION_ROOT = '$MAIN_DIR/build', 49 CPPPATH = [ 50 '$OBJ_ROOT', # generated headers are relative to here 51 '$MAIN_DIR/..', # TODO(dape): how can we use GOOGLECLIENT instead? 52 '$GOOGLE3', # google3 headers are relative to here 53 ], 54 CPPDEFINES = [ 55 # Temp flag while porting to hammer. 56 'HAMMER_TIME=1', 57 'LOGGING=1', 58 59 # Feature selection 60 'FEATURE_ENABLE_SSL', 61 'FEATURE_ENABLE_VOICEMAIL', 62 'FEATURE_ENABLE_PSTN', 63 'HAVE_GIPS', 64 'HAVE_LMI', 65 'HAVE_SRTP', 66 ] 67) 68 69#------------------------------------------------------------------------------- 70# W I N D O W S 71# 72win_env = root_env.Clone( 73 tools = [ 74 'atlmfc_vc80', 75 'code_signing', 76 'component_targets_msvs', 77 'directx_9_0_c', 78 #'grid_builder', 79 'midl', 80 'target_platform_windows', 81 ], 82 # Don't use default vc80 midl.exe. It doesn't understand vista_sdk idl files. 83 MIDL = '$PLATFORM_SDK_VISTA_6_0_DIR/Bin/midl.exe ', 84 WIX_DIR = '$GOOGLECLIENT/third_party/wix/v3_0_2925/files', 85 # Flags for debug and optimization are added to CCFLAGS instead 86 CCPDBFLAGS = '', 87 CCFLAGS_DEBUG = '', 88 CCFLAGS_OPTIMIZED = '', 89) 90 91win_env.Append( 92 COMPONENT_LIBRARY_PUBLISH = True, # Put dlls in output dir too 93 CCFLAGS = [ 94 '/Fd${TARGET}.pdb', # pdb per object allows --jobs= 95 '/WX', # warnings are errors 96 '/Zc:forScope', # handle 'for (int i = 0 ...)' right 97 '/EHs-c-', # disable C++ EH 98 '/GR-', # disable RTTI 99 '/wd4996', # ignore POSIX deprecated warnings 100 101 # promote certain level 4 warnings 102 '/w14701', # potentially uninitialized var 103 '/w14702', # unreachable code 104 '/w14706', # assignment within a conditional 105 '/w14709', # comma operator within array index 106 '/w14063', # case 'identifier' is not a valid value for switch of enum 107 '/w14064', # switch of incomplete enum 'enumeration' 108 '/w14057', # 'identifier1' indirection to slightly different base 109 # types from 'identifier2' 110 '/w14263', # member function does not override any base class virtual 111 # member function 112 '/w14266', # no override available for virtual memberfunction from base 113 # 'type'; function is hidden 114 '/w14296', # expression is always false 115 '/w14355', # 'this' : used in base member initializer list 116 ], 117 CPPDEFINES = [ 118 '_ATL_CSTRING_EXPLICIT_CONSTRUCTORS', 119 # TODO(dape): encapsulate all string operations that are not based 120 # on std::string/std::wstring and make sure we use the safest versions 121 # available on all platforms. 122 '_CRT_SECURE_NO_WARNINGS', 123 '_SCL_SECURE_NO_WARNINGS', 124 '_USE_32BIT_TIME_T', 125 '_UNICODE', 126 'UNICODE', 127 '_HAS_EXCEPTIONS=0', 128 'WIN32', 129 # TODO(dape): remove this from logging.cc and enable here instead. 130 #'WIN32_LEAN_AND_MEAN', 131 132 'WINVER=0x0500', 133 '_WIN32_WINNT=0x0501', 134 '_WIN32_IE=0x0501', 135 # The Vista platform SDK 6.0 needs at least 136 # this NTDDI version or else the headers 137 # that LMI includes from it won't compile. 138 'NTDDI_VERSION=NTDDI_WINXP', 139 ], 140 CPPPATH = [ 141 '$THIRD_PARTY/wtl_71/include', 142 '$PLATFORM_SDK_VISTA_6_0_DIR/Include', 143 ], 144 LIBPATH = [ 145 '$PLATFORM_SDK_VISTA_6_0_DIR/Lib' 146 ], 147 LINKFLAGS = [ 148 '-manifest' # TODO(thaloun): Why do we need this? 149 ], 150 MIDLFLAGS = [ 151 '/win32', 152 '/I$PLATFORM_SDK_VISTA_6_0_DIR/include' 153 ] 154) 155 156# TODO(dape): Figure out what this does; found it in 157# omaha/main.scons. This fixes the problem with redefinition 158# of OS_WINDOWS symbol. 159win_env.FilterOut(CPPDEFINES = ['OS_WINDOWS=OS_WINDOWS']) 160 161# Set up digital signing 162DeclareBit('test_signing', 'Sign binaries with the test certificate') 163win_env.SetBitFromOption('test_signing', False) 164if win_env.Bit('test_signing'): 165 win_env.Replace( 166 CERTIFICATE_PATH = win_env.File( 167 '$GOOGLECLIENT/tools/test_key/testkey.pfx').abspath, 168 CERTIFICATE_PASSWORD = 'test', 169 ) 170AddTargetGroup('signed_binaries', 'digitally signed binaries can be built') 171 172win_dbg_env = win_env.Clone( 173 BUILD_TYPE = 'dbg', 174 BUILD_TYPE_DESCRIPTION = 'Windows debug build', 175 BUILD_GROUPS = ['default', 'all'], 176 tools = ['target_debug'], 177) 178 179win_dbg_env.Prepend( 180 CCFLAGS=[ 181 '/ZI', # enable debugging 182 '/Od', # disable optimizations 183 '/MTd', # link with LIBCMTD.LIB debug lib 184 '/RTC1', # enable runtime checks 185 ], 186) 187 188envs.append(win_dbg_env) 189 190win_opt_env = win_env.Clone( 191 BUILD_TYPE = 'opt', 192 BUILD_TYPE_DESCRIPTION = 'Windows opt build', 193 BUILD_GROUPS = ['all'], 194 tools = ['target_optimized'], 195) 196 197win_opt_env.Prepend( 198 CCFLAGS=[ 199 '/Zi', # enable debugging 200 '/O1', # optimize for size 201 '/MT', # link with LIBCMT.LIB (multi-threaded, static linked crt) 202 '/GS', # enable security checks 203 ], 204) 205 206envs.append(win_opt_env) 207 208 209#------------------------------------------------------------------------------- 210# P O S I X 211# 212posix_env = root_env.Clone() 213posix_env.Append( 214 CPPDEFINES = [ 215 'HASHNAMESPACE=__gnu_cxx', 216 'HASH_NAMESPACE=__gnu_cxx', 217 'POSIX', 218 'DISABLE_DYNAMIC_CAST', 219 'HAVE_OPENSSL_SSL_H=1', 220 ], 221 CCFLAGS = [ 222 '-m32', 223 '-Wall', 224 '-Werror', 225 '-Wno-switch', 226 '-fno-exceptions', 227 ], 228 CXXFLAGS = [ 229 '-Wno-non-virtual-dtor', 230 '-Wno-ctor-dtor-privacy', 231 '-fno-rtti', 232 ], 233 LINKFLAGS = [ 234 '-m32', 235 ], 236) 237 238#------------------------------------------------------------------------------- 239# M A C OSX 240# 241mac_env = posix_env.Clone( 242 tools = [ 243 'target_platform_mac', 244 #'talk_mac', 245 #'fill_plist', 246 ], 247) 248mac_env.Append( 249 CPPDEFINES = [ 250 'OSX', 251 'MAC_OS_X_VERSION_MIN_REQUIRED=1040', 252 ], 253 CCFLAGS = [ 254 '-arch', 'i386', 255 '-isysroot', '/Developer/SDKs/MacOSX10.5.sdk', 256 '-fasm-blocks', 257 ], 258 LINKFLAGS = [ 259 '-Wl,-search_paths_first', 260 # This flag makes all members of a static library be included in the 261 # final exe - that increases the size of the exe, but without it 262 # Obj-C categories aren't properly included in the exe. 263 # TODO(thaloun): consider only defining for libs that actually have objc. 264 '-ObjC', 265 '-arch', 'i386', 266 ], 267 FRAMEWORKS = [ 268 'CoreServices', 269 'Carbon', 270 'Security', 271 'SystemConfiguration', 272 'OpenGL', 273 ] 274) 275 276mac_dbg_env = mac_env.Clone( 277 BUILD_TYPE = 'dbg', 278 BUILD_TYPE_DESCRIPTION = 'Mac debug build', 279 BUILD_GROUPS = ['default', 'all'], 280 tools = ['target_debug'] 281) 282mac_dbg_env.Append( 283 CPPDEFINES = [ 284 'FLAVOR_DBG', 285 'ENABLE_DEBUG', 286 ], 287 CCFLAGS = [ 288 '-O0', 289 ] 290) 291envs.append(mac_dbg_env) 292 293mac_opt_env = mac_env.Clone( 294 BUILD_TYPE = 'opt', 295 BUILD_TYPE_DESCRIPTION = 'Mac opt build', 296 BUILD_GROUPS = ['all'], 297 tools = ['target_optimized'] 298) 299mac_opt_env.Append( 300 CCFLAGS = [ 301 # TODO(thaloun): Figure out how mk can compile without 302 # this flag, then remove. Confirmed asserts are preprocessed 303 # out. Maybe it's a different version of gcc? 304 '-Wno-unused-variable', 305 ], 306) 307envs.append(mac_opt_env) 308 309#------------------------------------------------------------------------------- 310# L I N U X 311# 312linux_env = posix_env.Clone( 313 tools = ['target_platform_linux'], 314) 315 316linux_env.Append( 317 CPPDEFINES = [ 318 'LINUX', 319 'HAVE_GLIB', 320 # TODO() Enable once we figure out multiple defines with gips lib 321 # Also consider other linux flags: 64bit, no-strict-aliasing, wrap, etc 322 ], 323 LINKFLAGS = [ 324 # TODO(tschmelcher) consider enabling gc-sections. Perhaps only in opt. 325 #'-Wl,--gc-sections', 326 '-Wl,--start-group', 327 ], 328 _LIBFLAGS = ['-Wl,--end-group'], 329) 330 331linux_dbg_env = linux_env.Clone( 332 BUILD_TYPE = 'dbg', 333 BUILD_TYPE_DESCRIPTION = 'Linux debug build', 334 BUILD_GROUPS = ['default', 'all'], 335 tools = ['target_debug'] 336) 337envs.append(linux_dbg_env) 338 339linux_opt_env = linux_env.Clone( 340 BUILD_TYPE = 'opt', 341 BUILD_TYPE_DESCRIPTION = 'Linux optimized build', 342 BUILD_GROUPS = ['all'], 343 tools = ['target_optimized'] 344) 345envs.append(linux_opt_env) 346 347#------------------------------------------------------------------------------- 348# L I N U X -- C H R O M E -- O S 349# 350linux_chromeos_env = linux_env.Clone( 351 AR = os.environ.get("AR"), 352 AS = os.environ.get("AS"), 353 LD = os.environ.get("LD"), 354 NM = os.environ.get("NM"), 355 RANLIB = os.environ.get("RANLIB"), 356 CC = str(os.environ.get("CC")) + 357 ' --sysroot=' + str(os.environ.get("SYSROOT")), 358 CXX = str(os.environ.get("CXX")) + 359 ' --sysroot=' + str(os.environ.get("SYSROOT")), 360) 361 362linux_chromeos_env.Append( 363 CPPDEFINES = [ 364 'CHROMEOS', 365 '__MMX__', 366 '__SSE__', 367 '__SSE2__', 368 'USE_TALK_SOUND', 369 ], 370 371 CPPPATH = [ 372 os.environ.get("CPPPATH"), 373 ], 374 375 LIBPATH = [ 376 os.environ.get("LIBPATH"), 377 ], 378 379 CCFLAGS = [ 380 os.environ.get("CCFLAGS"), 381 # ChromeOS devices for sure has MMX, SSE, and SSE2. 382 # So turning on -mmmx, -msse, and -msse2 without CPU detection should be 383 # safe. 384 '-mmmx', 385 '-msse', 386 '-msse2', 387 ], 388 389 CXXFLAGS = [ 390 os.environ.get("CXXFLAGS"), 391 ], 392 393 RPATH = [ 394 os.environ.get("RPATH"), 395 ], 396) 397 398DeclareBit('linux_chromeos', 'Chrome OS ebuild') 399linux_chromeos_env.SetBits('linux_chromeos') 400 401linux_chromeos_dbg_env = linux_chromeos_env.Clone( 402 BUILD_TYPE = 'chromeos-dbg', 403 BUILD_TYPE_DESCRIPTION = 'Chrome OS debug build', 404 BUILD_GROUPS = ['chromeos'], 405 tools = ['target_debug'] 406) 407envs.append(linux_chromeos_dbg_env) 408 409linux_chromeos_opt_env = linux_chromeos_env.Clone( 410 BUILD_TYPE = 'chromeos-opt', 411 BUILD_TYPE_DESCRIPTION = 'Chrome OS optimized build', 412 BUILD_GROUPS = ['chromeos'], 413 tools = ['target_optimized'] 414) 415envs.append(linux_chromeos_opt_env) 416 417 418# TODO(): Clone linux envs for 64bit. See 'variant' documentation. 419 420# Parse child .scons files 421BuildEnvironments(envs) 422 423# Explicitly set which targets to build when not stated on commandline 424Default(None) 425# Build the following, which excludes unit test output (ie running them) 426# To run unittests, specify the test to run, or run_all_tests. See -h option. 427Default(['all_libraries', 'all_programs', 'all_test_programs']) 428 429# .sln creation code lifted from googleclient/bar/main.scons. Must be after 430# the call to BuildEnvironments for all_foo aliases to be defined. 431# Run 'hammer --mode=all --vsproj' to generate 432DeclareBit('vsproj', 'Generate Visual Studio projects and solution files.') 433win_env.SetBitFromOption('vsproj', False) 434 435if win_env.Bit('vsproj'): 436 vs_env = win_env.Clone() 437 vs_env.Append( 438 COMPONENT_VS_SOURCE_SUFFIXES = [ 439 '.def', 440 '.grd', 441 '.html', 442 '.idl', 443 '.mk', 444 '.txt', 445 '.py', 446 '.scons', 447 '.wxs.template', 448 ] 449 ) 450 451 # Source project 452 p = vs_env.ComponentVSDirProject( 453 'flute_source', 454 ['$MAIN_DIR', '$GOOGLE3', '$THIRD_PARTY'], 455 COMPONENT_VS_SOURCE_FOLDERS = [ 456 # Files are assigned to first matching folder. Folder names of None 457 # are filters. 458 (None, '$DESTINATION_ROOT'), 459 ('flute', '$MAIN_DIR'), 460 ('google3', '$GOOGLE3'), 461 ('third_party', '$THIRD_PARTY'), 462 ], 463 # Force source project to main dir, so that Visual Studio can find the 464 # source files corresponding to build errors. 465 COMPONENT_VS_PROJECT_DIR = '$MAIN_DIR', 466 ) 467 vs_env.AlwaysBuild(p) 468 469 # Solution and target projects 470 s = vs_env.ComponentVSSolution( 471 '../../flute', 472 ['all_libraries', 'all_programs', 'all_test_programs'], 473 projects = [p], 474 ) 475 476 print '***Unfortunately the vsproj creator isn\'t smart enough to ' 477 print '***automatically get the correct output locations. It is very easy' 478 print '***though to change it in the properties pane to the following' 479 print '***($SolutionDir)/build/<foo>/staging/<bar>.exe' 480 Default(None) 481 Default([s]) 482 483