root/branches/Dirk_CPtr/Tutorials/SConstruct

Revision 619, 5.5 kB (checked in by dirk, 2 years ago)

Added support for local libs for individual Tuts
Added Cluster tuts (thanks to Patrick hartling!)

  • Property svn:eol-style set to native
Line 
1 #!python
2 #
3 # Base scons build file
4 #
5
6 # Import everything under the sun
7 import sys
8 import os
9 pj = os.path.join
10
11
12 import SCons.Environment     # Get the environment crap
13 #import SCons
14
15 # Extend paths for scons-addons and scons-build if needed
16 # - this allows a development version of scons-addons to be
17 #   in the standard python path and used instead.
18 try:
19    import SConsAddons.Util
20    print "Using SConsAddons from: ", os.path.dirname(SConsAddons.Util.__file__)
21 except:
22    sys.path.insert(0,pj('../Tools','scons-addons','src'))
23    print "Using SConsAddons from: ../Tools/scons-addons/src"
24
25 import SConsAddons.Options as sca_opts   # Get the modular options stuff
26 import SConsAddons.Options.OpenSG2
27 import SConsAddons.Options.Boost
28 from SConsAddons.EnvironmentBuilder import EnvironmentBuilder
29 import SConsAddons.Util as sca_util      # Get the utils
30
31 # Setup base scons options and settings
32 EnsureSConsVersion(0,96)
33 SetOption('max_drift',30)           # 30 second drift on MD5 Files
34 SetOption('implicit_cache',1)
35 SConsignFile('.sconsign.'+sca_util.GetPlatform())    # Store all .sconsign stuff in single file
36
37 GetPlatform = sca_util.GetPlatform
38
39 ################################
40 # Create builder
41 ################################
42
43 if GetPlatform() == "win32":
44    opt_env = Environment()
45    # If you want to explicitly set the version MSVS version to use.
46    #opt_env = Environment(MSVS_VERSION='7.1')
47 else:
48    opt_env = Environment(ENV = os.environ)
49
50 # Default variants
51 default_types    = ['optimized', 'debug']
52 if GetPlatform() == 'win32':
53    default_types.append("hybrid")
54
55 # ---------- Options ------------ #
56 # This section sets up all option objects that need to be tested
57 # and then used later.
58 options_cache_filename = 'options.cache'
59 opts = sca_opts.Options(files = [options_cache_filename, 'options.custom'], args=ARGUMENTS)
60
61 opts.AddOption(sca_opts.SeparatorOption("\nBuild Variants"))
62 opts.Add(sca_opts.EnumOption('type','Types of run-times to build.(comma separated list)',
63                              default_types[0], default_types))
64
65 # OpenSG options.
66 opensg2_options = SConsAddons.Options.OpenSG2.OpenSG2("opensg", "2.0", required=True)
67 opensg2_options.verbose = True
68 boost_options = sca_opts.Boost.Boost("boost", "1.31.0", libs = [],
69                                      required = True , useVersion = True, useDebug=True, autoLink=True)
70
71
72 opts.AddOption(sca_opts.SeparatorOption("\nPackage Options"))
73 opts.AddOption(opensg2_options)
74 opts.AddOption(boost_options)
75
76 help_text = """---- Tutorials Build ----
77
78 %s
79
80 This file will be loaded each time.  Note: Options are cached in the file: %s
81 """ %(opts.GenerateHelpText(opt_env),options_cache_filename)
82 Help(help_text)
83
84 # ----- Project Setup ------------ #
85 # setup all modules and apps that need to be
86 # built as part of this project
87 if not sca_util.hasHelpFlag():
88    opts.Process(opt_env)
89    opts.Save(options_cache_filename, opt_env)
90
91    # Debug option settings
92    if 1:
93       print "---- OpenSG settings ----"
94       opensg2_options.dumpSettings()
95       print "---- Boost settings ----"
96       boost_options.dumpSettings()
97
98    # Create a variant.
99    combo = {'type':opt_env['type'], 'archs':'32'}
100
101    # -- Setup Environment builder --- #
102    env_bldr = EnvironmentBuilder()
103    env_bldr.enableWarnings(EnvironmentBuilder.MINIMAL)
104
105    # Process modifications for variant combo
106    if combo["type"] == "debug":
107       env_bldr.enableDebug()
108       env_bldr.setMsvcRuntime(EnvironmentBuilder.MSVC_MT_DBG_DLL_RT)
109    elif combo["type"] == "optimized":
110       env_bldr.enableOpt(EnvironmentBuilder.STANDARD)
111       env_bldr.setMsvcRuntime(EnvironmentBuilder.MSVC_MT_DLL_RT)
112    elif combo["type"] == "hybrid":
113       env_bldr.enableDebug()
114       env_bldr.setMsvcRuntime(EnvironmentBuilder.MSVC_MT_DLL_RT)
115    
116    base_env = env_bldr.applyToEnvironment(opt_env.Copy(), variant=combo)
117
118    if GetPlatform() == "win32":
119       base_env.Append(CPPDEFINES = ['BOOST_ALL_DYN_LINK',])
120       base_env.Append(CPPFLAGS = ["/wd4996",])
121
122       if combo["type"] == "hybrid":
123          base_env.Append(CPPDEFINES = ['_USE_RELEASE_RUNTIME',])
124          base_env.Append(LINKFLAGS = ['/NODEFAULTLIB:msvcprtd',])
125          base_env.Append(LINKFLAGS = ['/NODEFAULTLIB:msvcrtd',])
126          base_env.Append(LIBS = ['msvcprt',])
127          #base_env.Append(LIBS = ['msvcrt',])
128
129    # Suffix to add to the end of apps to install
130    runtime_suffix = ""
131    if combo["type"] == "debug":
132       runtime_suffix = "_d"
133    elif combo["type"] == "hybrid":
134       runtime_suffix = "_h"
135
136    # Add OpenSG libs.
137    libs=['State', 'System', 'Window', 'FileIO', 'Text', 'WIN32', 'GLUT',
138          'Group', 'Util', 'ImageFileIO', 'Base', 'RenderTraversal', 'Drawable']
139    opensg2_options.apply(base_env, libs=libs)
140    boost_options.apply(base_env, useDebug=('debug' == combo['type']))
141
142    build_app = True
143
144    if not opensg2_options.isAvailable():
145       print "OpenSG not available: Skipping viewer."
146       build_app = False
147    if not boost_options.isAvailable():
148       print "Boost not available: Skipping viewer."
149       build_app = False
150
151    if build_app:
152       # Get all the source files from the local directory tree
153       files = os.listdir('.')
154       tutorials = [f for f in files if f.endswith('.cpp')]
155
156       for file in tutorials:
157          name = file.split('.')[0]
158          local_env = base_env.Copy()
159          mylibs = local_env['LIBS']
160          for l in open(file).readlines():
161             if l.startswith("// Libs:"):
162                 mylibs += ["OSG"+m for m in l[8:].split()]
163          
164          print file, mylibs
165          # Build the test program and install into tree
166          loader = local_env.Program(name+runtime_suffix, file, LIBS = mylibs)
167
168 Default(".")
Note: See TracBrowser for help on using the browser.