| 1 | # |
|---|
| 2 | # |
|---|
| 3 | import os |
|---|
| 4 | import sys |
|---|
| 5 | import re |
|---|
| 6 | import SCons |
|---|
| 7 | |
|---|
| 8 | #------------------------------------ |
|---|
| 9 | # Check python and scons version |
|---|
| 10 | #------------------------------------ |
|---|
| 11 | |
|---|
| 12 | EnsurePythonVersion(2,3) |
|---|
| 13 | EnsureSConsVersion(0, 96, 92) |
|---|
| 14 | |
|---|
| 15 | #------------------------------------ |
|---|
| 16 | # Option |
|---|
| 17 | #------------------------------------ |
|---|
| 18 | |
|---|
| 19 | opt = Options('options.cache') |
|---|
| 20 | |
|---|
| 21 | if sys.platform == 'win32': |
|---|
| 22 | default_path='C:\\\\developpement\\\\dependencies' |
|---|
| 23 | else: |
|---|
| 24 | default_path='/usr' |
|---|
| 25 | |
|---|
| 26 | opt.AddOptions( |
|---|
| 27 | ('CXX', 'C++ compiler'), |
|---|
| 28 | |
|---|
| 29 | PathOption('build', 'build dir' , 'build', PathOption.PathIsDirCreate), |
|---|
| 30 | PathOption('prefix', 'install dir', default_path, PathOption.PathIsDir), |
|---|
| 31 | |
|---|
| 32 | BoolOption('debug', 'debug information', 1), |
|---|
| 33 | |
|---|
| 34 | PathOption('prefix_xerces', 'xerces-c prefix', default_path, PathOption.PathIsDir), |
|---|
| 35 | PathOption('prefix_log', 'DFLog prefix', default_path, PathOption.PathIsDir), |
|---|
| 36 | PathOption('prefix_boost', 'boost-c prefix', default_path, PathOption.PathIsDir), |
|---|
| 37 | ('boost_version', 'Boost version used', '1.37.0'), |
|---|
| 38 | PathOption('prefix_openal', 'OPENAL prefix', default_path, PathOption.PathIsDir), |
|---|
| 39 | PathOption('prefix_ogre', 'OGRE prefix', default_path, PathOption.PathIsDir), |
|---|
| 40 | PathOption('prefix_qt', 'QT prefix', default_path, PathOption.PathIsDir) |
|---|
| 41 | ) |
|---|
| 42 | |
|---|
| 43 | #------------------------------------ |
|---|
| 44 | # Set Up Environement |
|---|
| 45 | #------------------------------------ |
|---|
| 46 | |
|---|
| 47 | if sys.platform == 'win32': |
|---|
| 48 | env = Environment(ENV=os.environ, options=opt, tools = ['default', 'revision', 'version', 'custom_tests', 'writeConfigH', 'qt'], toolpath = ['scons']) |
|---|
| 49 | else: |
|---|
| 50 | env = Environment(ENV=os.environ, options=opt, tools = ['default', 'revision', 'version', 'custom_tests', 'writeConfigH'], toolpath = ['scons']) |
|---|
| 51 | |
|---|
| 52 | # |
|---|
| 53 | # |
|---|
| 54 | env['build'] = Dir(env['build']).abspath |
|---|
| 55 | |
|---|
| 56 | # |
|---|
| 57 | # |
|---|
| 58 | SConsignFile(os.path.join(env['build'],".sconsign.dblite")) |
|---|
| 59 | |
|---|
| 60 | #------------------------------------ |
|---|
| 61 | # Help |
|---|
| 62 | #------------------------------------ |
|---|
| 63 | |
|---|
| 64 | is_help = '-h' in sys.argv[1:] |
|---|
| 65 | |
|---|
| 66 | Help("""Targets list : |
|---|
| 67 | - To compile : |
|---|
| 68 | |
|---|
| 69 | - To check : |
|---|
| 70 | |
|---|
| 71 | - To create doc : |
|---|
| 72 | |
|---|
| 73 | - To install : |
|---|
| 74 | |
|---|
| 75 | Options to compile gameforge : |
|---|
| 76 | """ + opt.GenerateHelpText(env)) |
|---|
| 77 | |
|---|
| 78 | # |
|---|
| 79 | # Create configure object |
|---|
| 80 | config_h = [['PREFIX_DIR', '"%s"'%env['prefix']]] |
|---|
| 81 | |
|---|
| 82 | # |
|---|
| 83 | # Version |
|---|
| 84 | VERSION = env['VERSION'] |
|---|
| 85 | config_h.append(['__PACKAGE_VERSION__', '"%s"'%VERSION]) |
|---|
| 86 | |
|---|
| 87 | # |
|---|
| 88 | # Revision |
|---|
| 89 | REVISION = env['REVISION'] |
|---|
| 90 | config_h.append(['__PACKAGE_REVISION__', '"%s"'%REVISION]) |
|---|
| 91 | |
|---|
| 92 | # |
|---|
| 93 | # Define |
|---|
| 94 | defines = {'VERSION' : VERSION} |
|---|
| 95 | |
|---|
| 96 | # |
|---|
| 97 | # Install dir |
|---|
| 98 | top_install_dir = Dir(env['prefix']).abspath |
|---|
| 99 | |
|---|
| 100 | if sys.platform == 'win32': |
|---|
| 101 | bin_install_dir = top_install_dir |
|---|
| 102 | lib_install_dir = top_install_dir |
|---|
| 103 | data_install_dir = '../data/' |
|---|
| 104 | log_install_dir = '../log/' |
|---|
| 105 | else: |
|---|
| 106 | bin_install_dir = os.path.join(top_install_dir, 'bin') |
|---|
| 107 | lib_install_dir = top_install_dir |
|---|
| 108 | data_install_dir = '../data/' |
|---|
| 109 | log_install_dir = '../log/' |
|---|
| 110 | |
|---|
| 111 | #if sys.platform == 'win32': |
|---|
| 112 | # bin_install_dir = top_install_dir |
|---|
| 113 | # lib_install_dir = top_install_dir |
|---|
| 114 | # data_install_dir = os.path.join(top_install_dir, 'share') |
|---|
| 115 | #else: |
|---|
| 116 | # bin_install_dir = os.path.join(top_install_dir, 'bin') |
|---|
| 117 | # lib_install_dir = os.path.join(top_install_dir, 'lib') |
|---|
| 118 | # data_install_dir = os.path.join(top_install_dir, 'share', 'gameforge') |
|---|
| 119 | |
|---|
| 120 | #------------------------------------ |
|---|
| 121 | # CPP and LIB path |
|---|
| 122 | #------------------------------------ |
|---|
| 123 | |
|---|
| 124 | top_dir = Dir('.').abspath |
|---|
| 125 | |
|---|
| 126 | cpp_path = [ |
|---|
| 127 | "#/include", |
|---|
| 128 | env["build"], |
|---|
| 129 | os.path.join(env['prefix_xerces'], 'include'), |
|---|
| 130 | os.path.join(env['prefix_log'], 'include'), |
|---|
| 131 | os.path.join(env['prefix_ogre'], 'include', 'OGRE'), |
|---|
| 132 | os.path.join(env['prefix_openal'], 'include', 'AL') |
|---|
| 133 | ] |
|---|
| 134 | |
|---|
| 135 | lib_path = [ |
|---|
| 136 | os.path.join(env['prefix_xerces'], 'lib'), |
|---|
| 137 | os.path.join(env['prefix_ogre'], 'lib'), |
|---|
| 138 | os.path.join(env['prefix_openal'], 'lib'), |
|---|
| 139 | os.path.join(env['prefix_qt'], 'lib') |
|---|
| 140 | ] |
|---|
| 141 | |
|---|
| 142 | if sys.platform == 'win32': |
|---|
| 143 | env.AppendUnique(CPPPATH = [os.path.join(env['prefix_boost'], 'include', 'boost'), |
|---|
| 144 | os.path.join(env['prefix_qt'], 'include', 'qt4')]) |
|---|
| 145 | |
|---|
| 146 | #env.AppendUnique(CPPPATH = [os.path.join(env['prefix_newton'], 'include', 'NEWTON')]) |
|---|
| 147 | ##env.AppendUnique(LIBPATH = [os.path.join(env['prefix_newton'], 'lib')]) |
|---|
| 148 | else: |
|---|
| 149 | env.AppendUnique(CPPPATH = [os.path.join(env['prefix_boost'], 'include', 'boost-1_37'), |
|---|
| 150 | os.path.join(env['prefix_qt'], 'include')]) |
|---|
| 151 | #env.AppendUnique(CPPPATH = [env['prefix_newton']]) |
|---|
| 152 | #env.AppendUnique(LIBPATH = [env['prefix_newton']]) |
|---|
| 153 | |
|---|
| 154 | for path in cpp_path: |
|---|
| 155 | env.AppendUnique(CPPPATH = [path]) |
|---|
| 156 | |
|---|
| 157 | for path in lib_path: |
|---|
| 158 | env.AppendUnique(LIBPATH = [path]) |
|---|
| 159 | |
|---|
| 160 | #------------------------------------ |
|---|
| 161 | # Compiler |
|---|
| 162 | CXX = env.subst(env['CXX']) |
|---|
| 163 | bin_CXX = os.path.split(CXX)[-1] |
|---|
| 164 | |
|---|
| 165 | if bin_CXX.find('g++') != -1: |
|---|
| 166 | env.Append(CXXFLAGS = ['-Wall']) |
|---|
| 167 | if env['debug']: |
|---|
| 168 | env.Append(CXXFLAGS = ['-g']) |
|---|
| 169 | |
|---|
| 170 | else: |
|---|
| 171 | env.Append(CXXFLAGS = ['-O3','-funroll-loops','-ffast-math','-fomit-frame-pointer','-fno-strength-reduce']) |
|---|
| 172 | |
|---|
| 173 | elif bin_CXX.find('cl') != -1: |
|---|
| 174 | env.Append(CXXFLAGS = ['/nologo', '/DWIN32', '/D_CONSOLE', '/D_AFXDLL', '/D_MBCS', '/EHsc', '/MD', '/W3', '/O2', '/GS']) |
|---|
| 175 | env.Append(LINKFLAGS = ['/DEBUG', '/INCREMENTAL:NO', '/SUBSYSTEM:CONSOLE']) |
|---|
| 176 | |
|---|
| 177 | else: |
|---|
| 178 | print "'%s' isn't a compiler supported !"%CXX |
|---|
| 179 | Exit(1) |
|---|
| 180 | |
|---|
| 181 | # |
|---|
| 182 | ## Do not display deprecated messsage |
|---|
| 183 | env.Append(CXXFLAGS = ['-Wno-deprecated']) |
|---|
| 184 | |
|---|
| 185 | #------------------------------------ |
|---|
| 186 | # Platform |
|---|
| 187 | if sys.platform == 'linux2': |
|---|
| 188 | config_h.append(['__TARGET_LINUX__','']) |
|---|
| 189 | |
|---|
| 190 | elif sys.platform == 'win32': |
|---|
| 191 | config_h.append(['__TARGET_WINDOWS__', '']) |
|---|
| 192 | |
|---|
| 193 | #------------------------------------ |
|---|
| 194 | # Debug mod |
|---|
| 195 | if not env['debug']: |
|---|
| 196 | env.Append(CPPDEFINES = ['NDEBUG']) |
|---|
| 197 | |
|---|
| 198 | # |
|---|
| 199 | # Orgre define |
|---|
| 200 | env.Append(CPPDEFINES = ['EXT_HASH']) |
|---|
| 201 | |
|---|
| 202 | # |
|---|
| 203 | # Qt defines and envionnment |
|---|
| 204 | |
|---|
| 205 | if sys.platform == 'win32': |
|---|
| 206 | env.Append(CPPDEFINES = ['QT_DLL', 'QT_NO_DEBUG', 'QT_GUI_LIB', 'QT_CORE_LIB', 'QT_THREAD_SUPPORT']) |
|---|
| 207 | env['QT_LIB'] = 'qtmain' |
|---|
| 208 | else: |
|---|
| 209 | env.Append(CPPDEFINES = ['QT_NO_DEBUG', 'QT_GUI_LIB', 'QT_CORE_LIB', 'QT_THREAD_SUPPORT', 'QT_SHARED']) |
|---|
| 210 | |
|---|
| 211 | env['QT_AUTOSCAN'] = 1 |
|---|
| 212 | #env['MOC_DIR'] = '*.moc' |
|---|
| 213 | #env['RCC_DIR'] = '*.rcc' |
|---|
| 214 | #env['UI_DIR'] = '*.ui' |
|---|
| 215 | #env['RESOURCES'] = 'application.qrc' |
|---|
| 216 | |
|---|
| 217 | #env['QTDIR'] = '/usr/local/Trolltech/QtEmbedded-4.4.3-generic' |
|---|
| 218 | |
|---|
| 219 | # |
|---|
| 220 | # |
|---|
| 221 | conf = Configure(env, conf_dir=os.path.join(env['build'],'.sconf_temp'), log_file=os.path.join(env['build'],'config.log')) |
|---|
| 222 | env.UpdateCustomTest(conf) |
|---|
| 223 | |
|---|
| 224 | # |
|---|
| 225 | # Check QT lib name |
|---|
| 226 | |
|---|
| 227 | if sys.platform == 'win32': |
|---|
| 228 | qt_header = ['QtCore4', 'QtGui4', 'QtUiTools', 'Qt3Support4', 'QtDesigner4', 'QtHelp4', 'QtDesignerComponents4'] |
|---|
| 229 | else: |
|---|
| 230 | qt_header = ['QtCore', 'QtGui', 'QtUiTools', 'Qt3Support', 'QtDesigner', 'QtHelp', 'QtDesignerComponents'] |
|---|
| 231 | |
|---|
| 232 | for hd in qt_header: |
|---|
| 233 | if not conf.CheckLibWithHeader(hd, 'QtGui/QApplication', 'c++', 'QApplication qapp();'): |
|---|
| 234 | print "Not found Qt4 library" |
|---|
| 235 | Exit(1) |
|---|
| 236 | |
|---|
| 237 | # |
|---|
| 238 | # Check Xerces lib name |
|---|
| 239 | xerces = {} |
|---|
| 240 | if sys.platform == 'linux2': |
|---|
| 241 | xerces['LIB'] = "xerces-c" |
|---|
| 242 | elif sys.platform == 'win32': |
|---|
| 243 | xerces['LIB'] = "xerces-c_3" |
|---|
| 244 | else: |
|---|
| 245 | print "'%s' isn't a platform supported !"%sys.platform |
|---|
| 246 | Exit(1) |
|---|
| 247 | |
|---|
| 248 | # |
|---|
| 249 | # Check Xerces lib, headers and version |
|---|
| 250 | if not conf.CheckLib(xerces['LIB'], language="C++"): |
|---|
| 251 | print 'Did not find %s library (lib%s.a lib%s.lib) !'%(xerces['LIB'], xerces['LIB'], xerces['LIB']) |
|---|
| 252 | Exit(1) |
|---|
| 253 | |
|---|
| 254 | if not conf.CheckCXXHeader('xercesc/util/XercesVersion.hpp'): |
|---|
| 255 | print "Did not find header 'xercesc/util/XercesVersion.hpp' !" |
|---|
| 256 | Exit(1) |
|---|
| 257 | |
|---|
| 258 | # We check with the operator if the xerces version installed |
|---|
| 259 | # is upper or equal to the version we specify here |
|---|
| 260 | if not conf.CheckXercesVersion("2.5.0", ">="): |
|---|
| 261 | print "Xerces version failed !" |
|---|
| 262 | Exit(1) |
|---|
| 263 | |
|---|
| 264 | # |
|---|
| 265 | # Boost |
|---|
| 266 | for h in ['boost/shared_ptr.hpp', 'boost/weak_ptr.hpp', 'boost/date_time/posix_time/posix_time.hpp', 'boost/variant.hpp', 'boost/thread/mutex.hpp']: |
|---|
| 267 | if not conf.CheckCXXHeader(h): |
|---|
| 268 | print "Did not find header '%s' !"%h |
|---|
| 269 | Exit(1) |
|---|
| 270 | |
|---|
| 271 | if not conf.CheckBoostVersion(env['boost_version']): |
|---|
| 272 | print "Boost version failed !" |
|---|
| 273 | Exit(1) |
|---|
| 274 | |
|---|
| 275 | if sys.platform == 'win32': |
|---|
| 276 | boost_compiler = ('vc', 'vc90') |
|---|
| 277 | else: |
|---|
| 278 | boost_compiler = ('gcc', 'gcc43') |
|---|
| 279 | |
|---|
| 280 | boost_version = env['boost_version'].replace('.', '_').replace('_0', '') |
|---|
| 281 | |
|---|
| 282 | boost_lib = [ |
|---|
| 283 | ['boost_date_time', ['boost_date_time-mt'] + ['boost_date_time-%s-mt'%(compiler) for compiler in boost_compiler]+ |
|---|
| 284 | ['boost_date_time-%s-mt-%s'%(compiler, boost_version) for compiler in boost_compiler]], |
|---|
| 285 | ['boost_thread', ['boost_thread-mt'] + ['boost_thread-%s-mt'%(compiler) for compiler in boost_compiler]+ |
|---|
| 286 | ['boost_thread-%s-mt-%s'%(compiler, boost_version) for compiler in boost_compiler]], |
|---|
| 287 | ['boost_program_options', ['boost_program_options-mt'] + ['boost_program_options-%s-mt'%(compiler) for compiler in boost_compiler]+ |
|---|
| 288 | ['boost_program_options-%s-mt-%s'%(compiler, boost_version) for compiler in boost_compiler]] |
|---|
| 289 | ] |
|---|
| 290 | |
|---|
| 291 | for libs in boost_lib: |
|---|
| 292 | |
|---|
| 293 | found = False |
|---|
| 294 | |
|---|
| 295 | for lib in libs[1]: |
|---|
| 296 | if conf.CheckLib(lib, language="C++"): |
|---|
| 297 | found = True |
|---|
| 298 | break |
|---|
| 299 | |
|---|
| 300 | if not found: |
|---|
| 301 | print "Did not find boost date library %s..."%libs[0] |
|---|
| 302 | Exit(1) |
|---|
| 303 | |
|---|
| 304 | # |
|---|
| 305 | # Ogre |
|---|
| 306 | if not conf.CheckCXXHeader('Ogre.h'): |
|---|
| 307 | print "Did not find header Ogre.h" |
|---|
| 308 | Exit(1) |
|---|
| 309 | |
|---|
| 310 | if not conf.CheckLib('OgreMain', language="C++"): |
|---|
| 311 | print "Not found ogre library OgreMain.lib" |
|---|
| 312 | Exit(1) |
|---|
| 313 | |
|---|
| 314 | # |
|---|
| 315 | # OPENAL Librairie |
|---|
| 316 | # Check OpenAL lib and headers , |
|---|
| 317 | for hd in ['al.h', 'alc.h', 'alut.h']: |
|---|
| 318 | if not conf.CheckCXXHeader(hd): |
|---|
| 319 | print "Did not find OpenAL header '%s' !"%hd |
|---|
| 320 | Exit(1) |
|---|
| 321 | |
|---|
| 322 | if sys.platform == 'win32': |
|---|
| 323 | lib_openal = ['OpenAL32', 'alut'] |
|---|
| 324 | else: |
|---|
| 325 | lib_openal = ['openal', 'alut'] |
|---|
| 326 | |
|---|
| 327 | # 'alut' |
|---|
| 328 | for lib in lib_openal: |
|---|
| 329 | if not conf.CheckLib(lib, language="C++"): |
|---|
| 330 | print "Not found OpenAL library : %s..."%lib |
|---|
| 331 | Exit(1) |
|---|
| 332 | |
|---|
| 333 | # |
|---|
| 334 | # Write config.h |
|---|
| 335 | env.WriteConfigH(os.path.join(env['build'], 'config.h'), config_h) |
|---|
| 336 | conf.env.AppendUnique(CPPDEFINES = ['HAVE_CONFIG_H']) |
|---|
| 337 | conf.env.AppendUnique(CPPPATH = [env['build']]) |
|---|
| 338 | |
|---|
| 339 | # |
|---|
| 340 | # Save option |
|---|
| 341 | opt.Save('options.cache', env) |
|---|
| 342 | |
|---|
| 343 | # |
|---|
| 344 | # End configure |
|---|
| 345 | env = conf.Finish() |
|---|
| 346 | |
|---|
| 347 | # |
|---|
| 348 | # Update tools |
|---|
| 349 | for t in ['unitTest', 'subInFile']: |
|---|
| 350 | env.Tool(t) |
|---|
| 351 | |
|---|
| 352 | # |
|---|
| 353 | # |
|---|
| 354 | if bin_CXX.find('cl') != -1: |
|---|
| 355 | # |
|---|
| 356 | # sub system console use to check header, lib |
|---|
| 357 | # windows use to build app, unit test |
|---|
| 358 | env["LINKFLAGS"].remove('/SUBSYSTEM:CONSOLE') |
|---|
| 359 | env.Append(LINKFLAGS = ['/SUBSYSTEM:WINDOWS']) |
|---|
| 360 | |
|---|
| 361 | # |
|---|
| 362 | # SConscript |
|---|
| 363 | SConscript( |
|---|
| 364 | os.path.join('src','SConscript'), |
|---|
| 365 | exports=['env', 'top_dir', 'bin_install_dir', 'lib_install_dir', 'data_install_dir'], |
|---|
| 366 | build_dir=os.path.join(env['build'], 'src'), |
|---|
| 367 | duplicate=0) |
|---|
| 368 | |
|---|
| 369 | #SConscript( |
|---|
| 370 | # os.path.join('tests','SConscript'), |
|---|
| 371 | # exports=['env', 'top_dir', 'bin_install_dir', 'lib_install_dir', 'data_install_dir'], |
|---|
| 372 | # build_dir=os.path.join(env['build'], 'tests'), |
|---|
| 373 | # duplicate=0) |
|---|