Posted: Thu Dec 23, 2004 10:51 am
@tisba
Just tried pyOgre last day and was imrpressed. Can you also make bindings for OgreOde?
Just tried pyOgre last day and was imrpressed. Can you also make bindings for OgreOde?
Support and community hang-out spot for Ogre3D
https://forums.ogre3d.org/
Code: Select all
import os
import os.path
import sys
import SCons.Tool
import glob
selected_variant = 'release'
#selected_variant = 'debug'
# Ensure build directory exist (SConsignFile fail otherwise!)
if not os.path.exists( Dir('#build').abspath ):
os.mkdir( Dir('#build').abspath )
# Store all dependencies signature in a database
SConsignFile( 'build/.sconsign.dbm' )
# scan for configuration options
if ARGUMENTS.has_key( 'gccxml_path' ):
gccxml_path = ARGUMENTS['gccxml_path']
replace_map = { 'gccxml_path' : gccxml_path }
config_in = file( str(File('#tools/gccxml.config.in')), 'r' )
config_out = file( str(File('#tools/gccxml.config')), 'w' )
config_out.write( config_in.read() % replace_map )
config_out.close()
config_in.close()
print '%s initialized.' % File('#tools/gccxml.config')
config_file = file( str(File('#config')), 'w' )
config_file.write( gccxml_path )
config_file.close()
print 'gccxml path stored in %s' % str(File('#config'))
# Utility fonction
class FilterTargetByExt:
def __init__( self, ext ):
self.ext = ext
def __call__( self, target ):
return os.path.splitext( str(target) )[1] == self.ext
# Tools
def python_tool( env ):
"""Set path to python 2.3 include and libraries."""
python_root = sys.prefix
include_path = os.path.join( python_root, 'include' )
libs_path = os.path.join( python_root, 'libs' )
env.Append( CPPPATH=[ include_path ],
LIBPATH=[ libs_path ] )
def boost_python_tool( env ):
"""Set libary name for boost.python for linking. Assumes include in #include."""
if env['BUILD_VARIANT'] == 'debug':
env.Append( LIBS=['boost_python-vc71-mt-gd-1_32.lib'] ) #debug
env.Append( DEPLOY_DLL=['boost_python-vc71-mt-gd-1_32.dll'] )
else:
env.Append( LIBS=['boost_python-vc71-mt-1_32.lib'] ) #release
env.Append( DEPLOY_DLL=['boost_python-vc71-mt-1_32.dll'] )
# CPPDEFINES=['BOOST_PYTHON_NO_TEMPLATE_EXPORT']
def ogre_main_tool( env ):
"""Set library name to link with OgreMain library."""
if env['BUILD_VARIANT'] == 'debug':
env.Append( LIBS=['OgreMain_d.lib'] )
env.Append( DEPLOY_DLL=['OgreMain_d.dll'] )
else:
env.Append( LIBS=['OgreMain.lib'] )
env.Append( DEPLOY_DLL=['OgreMain.dll'] )
# Pyste Builder:
# Pyste() generate .cpp from .pyste & Ogre headers
# PysteMain() generate main.cpp from the list of .pyste sources
def pyste_emitter( target, source, env ):
target = []
for pyste_source in source:
target_filename = os.path.splitext( os.path.basename( str(pyste_source) ) )[0] + '.cpp'
target_path = env.File( env.subst('#$PYSTE_OUT/' + target_filename ) )
target.append( target_path )
return ( target, source )
def pyste_main_emitter( target, source, env ):
target = env.File( env.subst('#$PYSTE_OUT/main.cpp' ) )
env.Ignore( target, source )
return (target, source)
def pyste_tool( env ):
env.Append( PYTHON_BIN=[sys.executable] )
env.Append( PYSTE_CACHE_DIR=['#cache'] )
# env.Append( ENV={'GCCXML' : 1,
# 'GCCXML_CONFIG' : env['GCCXML_CONFIG_PATH'] } ) # migth not be needed on platform with native gcc
env['PYSTE_DEFINES'] = []
pyste_builder = Builder( action = '$PYSTECOM',
suffix = '.cpp',
src_suffix = '.pyste',
emitter = pyste_emitter )
pyste_main_builder = Builder( action = '$PYSTEMAINCOM', emitter = pyste_main_emitter )
env.Append( BUILDERS = { 'Pyste' : pyste_builder,
'PysteMain' : pyste_main_builder } )
env['_PYSTE_INCFLAGS'] = '$( ${_concat("-I ", PYSTE_INCLUDES, "", __env__, RDirs)} $)'
env['_PYSTE_DEFFLAGS'] = '$( ${_concat("-D ", PYSTE_DEFINES, "", __env__ )} $)'
env['PYSTE_FLAGS'] = '$_PYSTE_INCFLAGS $_PYSTE_DEFFLAGS --gccxml-path=/home/jpfarias/work/bin/gccxml ' + \
'--cache-dir=${PYSTE_CACHE_DIR} ' + \
'-D GCC_3_1 --multiple --module=${PYSTE_MODULE} --out=${PYSTE_OUT} ' + \
'--pyste-ns=$PYSTE_NAMESPACE'
# env['PYSTE_FLAGS'] += ' --debug'
env['PYSTECOM'] = '$PYTHON_BIN $PYSTE_PATH $PYSTE_FLAGS ${SOURCES}'
env['PYSTEMAINCOM'] = '$PYTHON_BIN $PYSTE_PATH $PYSTE_FLAGS --generate-main ${SOURCES}'
# Environment set up
gccxml_config_path = os.path.join( str(Dir('#tools')), 'gccxml.config' )
env = Environment( MSVS_VERSION='7.1',
GCCXML_CONFIG_PATH=gccxml_config_path,
BUILD_VARIANT=selected_variant,
tools=['default', python_tool, boost_python_tool, pyste_tool, ogre_main_tool] )
env.SetOption('implicit_cache', 1)
env['GCCXML_DIR'] = file( str(File('#config')), 'r' ).read() # must run scons gccxml_path=c:\wut\prg\GCC_XML to configure
env['GCCXML_PATH'] = r'$GCCXML_DIR/gccxml'
env['PYTHON_BIN'] = sys.executable
env['PYSTE_PATH'] = env.File('#tools/pyste.py')
env['PYSTE_INCLUDES'] = [ '#src/pyogre', '#include', '#include/ogre', '#include/ogre/dependencies', '/usr/include', '/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/include/g++-v3/ext' ]
#for include in str(env['ENV']['INCLUDE']).split(os.pathsep): # work-around Scons \n bug inn system INCLUDE
# env.Append( PYSTE_INCLUDES=str(include).strip() )
env['PYSTE_NAMESPACE'] = 'py'
env['PYSTE_OUT'] = 'build/$PYSTE_MODULE' # yuk, rely on the fact that 'current is top-level'. Subst won't replace # and env.Dir expand 'now'.
env['PYSTE_CACHE_DIR'] = '$PYSTE_OUT/cache'
env.Append( CPPPATH=[ '#include', '#include/ogre', '#include/ogre/dependencies' ] )
if env['BUILD_VARIANT'] == 'debug':
#compiler specific flags
env.Append( CXXFLAGS='/Od /GX /MDd /GR /W3 /nologo /TP /wd4267 /wd4541'.split() )
env.Append( CPPDEFINES=[ "WIN32", "_DEBUG", "_WINDOWS", "_USRDLL", "_CONSOLE", "_MT", "_DLL", "_WINDLL", "_MBCS" ] )
# copied from Scons/Tool/msvc.py to be able to change /Zi to /Zd
env['CCPDBDEBUGFLAGS'] = '/Zi'
env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "$CCPDBDEBUGFLAGS /Fd%s"%File(PDB)) or ""}'])
env.Append( LINKFLAGS='/INCREMENTAL' ) # enable incremental linking (should be only in debug build)
env.Append( LIBPATH='#libs/vc71/debug' )
else:
env.Append( CXXFLAGS="""-O2 -I/usr/include/python2.3
-DGCC_3_1 -Wall -fomit-frame-pointer""".split() )
env.Append( CPPDEFINES=['EXT_HASH', 'GCC_3_1' ] )
env.Append( LIBPATH='#libs/vc71/release' )
##### Helper function to build python module
def BuildPythonModule( env,
source_dir,
module_name,
target_dir,
excluded_pyste = None ):
env.Append( CPPPATH=[ source_dir ] )
env.Append( PYSTE_INCLUDES=[ source_dir ] )
target_name = module_name + '_'
env['PYSTE_MODULE'] = target_name
if env['BUILD_VARIANT'] == 'debug':
env['PDB'] = target_name + '.pdb'
# .pyste => .cpp
pyste_sources = glob.glob1( str(env.Dir(source_dir)), '*.pyste' )
pyste_generated = []
for source in pyste_sources[:]:
if excluded_pyste is None or str(source) not in excluded_pyste:
pyste_generated.append( env.Pyste( source ) )
else:
pyste_sources.remove( str(source) )
pyste_generated.append( env.PysteMain( pyste_sources ) )
# generated .cpp => .obj in build dir
pyste_generated_objs = []
for cpp in pyste_generated:
cpp_without_extension = os.path.splitext( os.path.basename( str(cpp[0]) ) )[0]
pyste_generated_objs.append( env.SharedObject( target = env.File(cpp_without_extension + ".obj"),
source = cpp ) )
shared_lib = env.SharedLibrary( target_name, pyste_generated_objs )
env.Precious( shared_lib ) # using incremental link, preserve library
env.InstallAs( target_dir + '/' + target_name + '.pyd', filter( FilterTargetByExt('.dll'), shared_lib ) )
msvs_project_sources = glob.glob1( str(env.Dir(source_dir)), '*.h' )
for source in pyste_generated:
msvs_project_sources.append( str(source) )
#print msvs_project_sources
misc_project_files = []
for path in [ '#building.txt', '#readme.txt', '#todo.txt', '#SConstruct', '#NEWS' ]:
misc_project_files.append( env.File( env.subst( path ) ).abspath )
#print dir(env)
#env.MSVSProject( target = module_name + '.vcproj',
# variant = 'Debug',
# buildtarget = shared_lib,
# srcs = msvs_project_sources,
# incs = pyste_sources,
# misc = misc_project_files )
# install ogre & python dlls
ogre_dir_dlls = env['DEPLOY_DLL']
ogre_dir_dlls.extend( """
devil.dll
ilu.dll
ilut.dll
SDL.dll
""".split() )
plugins_dir_dlls = """
Plugin_BSPSceneManager.dll
Plugin_CgProgramManager.dll
Plugin_FileSystem.dll
Plugin_GuiElements.dll
Plugin_NatureSceneManager.dll
Plugin_OctreeSceneManager.dll
Plugin_ParticleFX.dll
RenderSystem_Direct3D7.dll
RenderSystem_Direct3D9.dll
RenderSystem_GL.dll
""".split()
demo_dir_dlls = """
OgrePlatform.dll
ReferenceAppLayer.dll
""".split()
def InstallDlls( env, dlls, target_dir ):
prefix_dir = '#bin/' + env['BUILD_VARIANT'] + '/'
prefixed_dlls = []
for dll in dlls:
prefixed_dlls.append( env.File( env.subst(prefix_dir + dll ) ) )
env.Install( target_dir, prefixed_dlls )
InstallDlls( env, ogre_dir_dlls, '#python/ogre' )
InstallDlls( env, demo_dir_dlls, '#python/ogre/demo' )
InstallDlls( env, plugins_dir_dlls, '#python/ogre/demo/plugins' )
Export( 'env FilterTargetByExt BuildPythonModule' )
variant_dir = 'vc71/' + env['BUILD_VARIANT']
SConscript( 'src/pyogre/SConscript',
build_dir= '#build/%s/pyogre' % variant_dir, duplicate=0 )
#SConscript( 'src/testoverload/SConscript',
# build_dir='#build/%s/testoverload' % variant_dir, duplicate=0 )
#SConscript( 'src/testvirtualdefarg/SConscript',
# build_dir='#build/%s/testvirtualdefarg' % variant_dir, duplicate=0 )
#SConscript( 'src/testpointerlist/SConscript',
# build_dir='#build/%s/testpointerlist' % variant_dir, duplicate=0 )
You need boost 1.32. The change I made to pyste to fix the virtual function default argument bug requires new-style polymorphism. It's a new feature of boost.python 1.32. It also speeds up the execution since you only go through python interpreter when the virtual function is actually overridden in python...jpfarias wrote:Which version of boost and pyste did u used to build the windows binaries?
I'm using 1.31.0 on linux and it appears that there are some constructs not supported on my boost that are generated by your tools/pyste.py script...
--
JP