1 # Copyright 2012 Google Inc. All Rights Reserved. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # main.scons for google-tv-pairing-protocol cpp library 16 17 import os 18 import platform 19 import sys 20 21 GTEST_INCLUDES = ['%s/include' % os.environ['GTEST_DIR']] 22 Export('GTEST_INCLUDES') 23 GMOCK_INCLUDES = ['%s/include' % os.environ['GMOCK_DIR']] 24 Export('GMOCK_INCLUDES') 25 OPENSSL_INCLUDES = ['%s/include' % os.environ['OPENSSL_DIR']] 26 Export('OPENSSL_INCLUDES') 27 28 GTEST_LIBS = ['%s/lib/.libs' % os.environ['GTEST_DIR']] 29 Export('GTEST_LIBS') 30 GMOCK_LIBS = ['%s/lib/.libs' % os.environ['GMOCK_DIR']] 31 Export('GMOCK_LIBS') 32 OPENSSL_LIBS = [os.environ['OPENSSL_DIR']] 33 Export('OPENSSL_LIBS') 34 35 build_environments = [] 36 37 root_env = Environment( 38 tools = ['component_setup'], 39 BUILD_SCONSCRIPTS = [ 40 'src/polo', 41 'tests/polo', 42 ], 43 CPPPATH=['$MAIN_DIR/src'], 44 ) 45 46 # Detect 64-bit build platform 47 DeclareBit('arch_64', 'Target platform is 64-bit') 48 DeclareBit('64bit', 'Target environment is 64-bit') 49 if platform.architecture()[0] == '64bit': 50 root_env.SetBits('arch_64') 51 52 # Setup the linux environment 53 linux_env = root_env.Clone(tools = ['target_platform_linux']) 54 55 linux_env.Append( 56 LINKFLAGS = ['-static', '-pthread'], 57 CCFLAGS = ['-fPIC'], 58 ) 59 60 linux_32_env = linux_env.Clone() 61 linux_32_env.Append( 62 CCFLAGS = ['-m32'], 63 LINKFLAGS = ['-m32'], 64 LIBPATH = [ 65 #'/usr/lib32', 66 ] 67 ) 68 69 linux_dbg_32_env = linux_32_env.Clone( 70 BUILD_TYPE = 'dbg', 71 BUILD_TYPE_DESCRIPTION = 'Linux 32-bit Debug Build', 72 tools = ['target_debug'], 73 ) 74 build_environments.append(linux_dbg_32_env) 75 76 77 linux_opt_32_env = linux_32_env.Clone( 78 BUILD_TYPE = 'opt', 79 BUILD_TYPE_DESCRIPTION = 'Linux 32-bit Release Build', 80 tools = ['target_optimized'] 81 ) 82 linux_opt_32_env.Append( 83 CCFLAGS = ['-O2'], 84 LINKFLAGS = ['--strip-all', '-s'], 85 ) 86 build_environments.append(linux_opt_32_env) 87 88 # Add 64-bit linux environment if supported by build platform 89 if linux_env.Bit('arch_64'): 90 linux_64_env = linux_env.Clone() 91 linux_64_env.Append( 92 CCFLAGS = ['-m64'], 93 LINKFLAGS = ['-m64'], 94 LIBPATH = [ 95 #'/usr/lib64', 96 ] 97 ) 98 99 linux_dbg_64_env = linux_64_env.Clone( 100 BUILD_TYPE = 'dbg64', 101 BUILD_TYPE_DESCRIPTION = 'Linux 64-bit Debug Build', 102 BUILD_GROUPS = ['default'], 103 tools = ['target_debug'], 104 ) 105 linux_dbg_64_env.SetBits('64bit') 106 build_environments.append(linux_dbg_64_env) 107 108 linux_opt_64_env = linux_64_env.Clone( 109 BUILD_TYPE = 'opt64', 110 BUILD_TYPE_DESCRIPTION = 'Linux 64-bit Release Build', 111 tools = ['target_optimized'] 112 ) 113 linux_opt_64_env.Append( 114 CCFLAGS = ['-O2'], 115 LINKFLAGS = ['--strip-all'], 116 ) 117 linux_opt_64_env.SetBits('64bit') 118 build_environments.append(linux_opt_64_env) 119 120 # Mac OSX Build Environment 121 mac_env = root_env.Clone(tools = ['target_platform_mac']) 122 mac_env.Append( 123 CCFLAGS = [ 124 '-arch', 'i386', 125 '-fPIC', 126 ], 127 CPPDEFINES = [ 128 'OSX', 129 'XP_MACOSX', 130 ], 131 FRAMEWORKS = [ 132 'CoreFoundation', 133 'IOKit', 134 ], 135 LIBS = [ 136 'pthread', 137 ], 138 LINKFLAGS = [ 139 '-arch', 'i386', 140 '-Wl,-search_paths_first', 141 ], 142 ) 143 144 mac_opt_env = mac_env.Clone( 145 BUILD_TYPE = 'opt', 146 BUILD_TYPE_DESCRIPTIONS = 'Mac Release Build', 147 ) 148 149 mac_opt_env.Append( 150 CCFLAGS = [ 151 '-O2', 152 ], 153 LINKFLAGS = ['--string-all', '-s'], 154 tools = ['target_optimized'], 155 ) 156 build_environments.append(mac_opt_env) 157 158 mac_dbg_env = mac_env.Clone( 159 BUILD_TYPE = 'dbg', 160 BUILD_TYPE_DESCRIPTION = 'Mac Debug Build', 161 ) 162 163 mac_dbg_env.Append( 164 CCFLAGS = ['-O0'], 165 tools = ['target_debug'], 166 ) 167 build_environments.append(mac_dbg_env) 168 169 170 # Windows Build Environment 171 win_env = root_env.Clone(tools = ['target_platform_windows']) 172 173 win_env.Append( 174 CCFLAGS = [ 175 '/EHsc', 176 ], 177 CPPDEFINES = [ 178 'OS_WINDOWS', 179 'WIN32', 180 '_WINDOWS', 181 '_WIN32_WINNT=0x0501', 182 'WINVER=0x0501', 183 'WIN32_LEAN_AND_MEAN', 184 'GOOGLE_GLOG_DLL_DECL=', 185 'NOGDI', 186 'BOOST_ALL_NO_LIB', 187 'BOOST_THREAD_BUILD_LIB', 188 '_X86_', 189 'X86', 190 ], 191 ) 192 193 # We need perl and nasm to be in the path. 194 if sys.platform == 'win32': 195 win_env['ENV']['PATH'] = os.environ['PRESCONS_PATH'] 196 win_env['ENV']['INCLUDE'] = os.environ['INCLUDE'] 197 win_env['ENV']['LIB'] = os.environ['LIB'] 198 199 win_opt_env = win_env.Clone( 200 BUILD_TYPE = 'opt', 201 BUILD_TYPE_DESCRIPTION = 'Windows Release Build', 202 ) 203 204 win_opt_env.Append( 205 CCFLAGS = [ 206 '/O1', 207 '/GS', 208 '/GL', 209 '/MT', 210 ], 211 CPPDEFINES = [ 212 'NDEBUG', 213 ], 214 ARFLAGS = [ 215 '/LTCG', 216 ], 217 LINKFLAGS = [ 218 '/incremental:no', 219 '/LTCG', 220 '/opt:icf=32', 221 '/opt:ref', 222 ] 223 ) 224 build_environments.append(win_opt_env) 225 226 win_dbg_env = win_env.Clone( 227 BUILD_TYPE = 'dbg', 228 BUILD_TYPE_DESCRIPTION = 'Windows Debug Build', 229 BUILD_GROUPS = ['default'], 230 ) 231 232 win_dbg_env.Append( 233 CCFLAGS = [ 234 '/Fd$OBJ_ROOT/vc80.pdb', 235 '/MTd', 236 '/Od', 237 '/Z7', 238 ], 239 CPPDEFINES = [ 240 'DEBUG', 241 '_DEBUG', 242 ], 243 ) 244 build_environments.append(win_dbg_env) 245 246 BuildEnvironments(build_environments) 247