view engine/SConscript @ 564:7d88eddd2ec7

Modified the addColored and addOutlined methods in the InstanceRenderer class to fix a memory leak. The new code attempts to insert the information in the proper map and if it already exists it will explicitly update the reference to the existing information. The new code no longer relies on the bracket operator of the std::map which was implicitly calling the equals operator of the ColoringInfo and OutlineInfo and causing the memory leak. fixes[ticket:472]
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 26 Jun 2010 00:42:14 +0000
parents 92433f507feb
children a21915a97237
line wrap: on
line source

# -*- coding: utf-8 -*-

# ####################################################################
#  Copyright (C) 2005-2009 by the FIFE team
#  http://www.fifengine.de
#  This file is part of FIFE.
#
#  FIFE is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the
#  Free Software Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
# ####################################################################

import os,sys
import utils.scons.scons_utils as utils
from utils.util_scripts.path import path as upath
import utils.scons.scons_builders as builders

Import('env', 'opts')

_sep = os.path.sep
src_path = upath(opts['SRC'])
engine_path = opts['SRC']
core_path = os.path.join('engine', 'core')
extensionpath = upath(os.path.join(opts['SRC'], 'python', 'fife', 'extensions'))

#**************************************************************************
#Compile the list of source code to be used
#**************************************************************************

allfiles = list(src_path.walkfiles())
allfiles_base = list()
for f in allfiles:
	allfiles_base.append(utils.relpath(f, opts['SRC']))

extpyfiles = list(extensionpath.walkfiles('*.py'))
extensionfiles = list()
relextensionfiles = list()
for f in extpyfiles:
	extensionfiles.append(utils.relpath(f, opts['SRC']))
	relextensionfiles.append(utils.relpath(f, os.path.join(opts['SRC'], 'python', 'fife')))
	
headerfiles = [f for f in allfiles_base if utils.is_headerfile(f)]
implfiles = [f for f in allfiles_base if utils.is_implfile(f)]
swigfiles = [f for f in allfiles_base if utils.is_swigfile(f)]
intfiles = utils.filter_by_dir(['swigwrappers'], swigfiles)
compilefiles = utils.filter_by_dir(['swigwrappers'], implfiles)

if sys.platform == 'win32':
	dllpath = upath(opts['DLLPATH'])
	dllfilelist = list(dllpath.walkfiles('*.dll'))
	dllfiles = list()
	for f in dllfilelist:
		dllfiles.append(utils.relpath(f,opts['DLLPATH'])) 
	
	



#**************************************************************************
#python
#**************************************************************************

#generate swig interface file
utils.gen_swig_interface(os.path.join(engine_path, 'swigwrappers', 'python', 'fife.i.templ'), 
		   intfiles,
		   os.path.join(engine_path, 'swigwrappers', 'python'))

pyfiles = list(compilefiles)
pyfiles.append([os.path.join('swigwrappers', 'python' ,'fife_wrap.cc')])

#**************************************************************************
#Definition of scons builders for project files
#**************************************************************************

msvc_project_builder = Builder(action = builders.generate_msvc_project, suffix = '.vcproj')
env.Append(BUILDERS = {'MSVCProject': msvc_project_builder})

msvc_project_builder9 = Builder(action = builders.generate_msvc_project9, suffix = '.vcproj')
env.Append(BUILDERS = {'MSVCProject9': msvc_project_builder9})

codeblocks_project_builder_win32 = Builder(action = builders.generate_codeblocks_project_win32, suffix = '.cbp')
env.Append(BUILDERS = {'CodeblocksProjectWin32': codeblocks_project_builder_win32})

codeblocks_project_builder_linux = Builder(action = builders.generate_codeblocks_project_linux, suffix = '.cbp')
env.Append(BUILDERS = {'CodeblocksProjectLinux': codeblocks_project_builder_linux})

python_extensions_builder = Builder(action = "$SWIG -o $TARGET ${_SWIGOUTDIR} ${_SWIGINCFLAGS} $SWIGFLAGS $SOURCES")
env.Append(BUILDERS = {'PythonExtensions': python_extensions_builder})


#**************************************************************************
#project files target
#**************************************************************************

projectfiles = compilefiles + headerfiles
#projectfiles.append('swigwrappers/python/fife_wrap.cc')

msvcproj = env.MSVCProject(os.path.join('..', '..','..', builders.msvcbuildpath, 'fife'), projectfiles)
msvcproj9 = env.MSVCProject9(os.path.join('..', '..','..', builders.msvcbuildpath9, 'fife'), projectfiles)
cbproj_win32 = env.CodeblocksProjectWin32(os.path.join('..', '..','..', builders.cbbuildpath_win32, 'fife'), projectfiles)
cbproj_linux = env.CodeblocksProjectLinux(os.path.join('..', '..','..', builders.cbbuildpath_linux, 'fife'), projectfiles)


#**************************************************************************
#shared library target
#**************************************************************************

if sys.platform == 'win32':
	sharedlib = env.SharedLibrary(target = 'fife',
								  source = compilefiles,
								  OBJPREFIX='shared_',
								  SHLIBEMITTER = '')
else:
	sharedlib = env.SharedLibrary(target = 'fife',
								  source = compilefiles)

#**************************************************************************
#python library target
#**************************************************************************
if sys.platform == 'win32':
	dest_suffix = '.pyd'
else:
	dest_suffix = '.so'
	
pythonlib = env.SharedLibrary(target = 'fife',
							  source = pyfiles,
							  OBJPREFIX='py_',
							  SHLIBPREFIX='_',
							  SHLIBSUFFIX=dest_suffix,
							  SHLIBEMITTER = '')

pythonext = env.PythonExtensions(target = [os.path.join('swigwrappers', 'python' ,'fife_wrap.cc'), os.path.join('python', 'fife', 'fife.py')],
							  source = os.path.join('swigwrappers', 'python' ,'fife.i'),
							  SWIGFLAGS=['-python','-c++','-w511'],
							  SWIGPATH='core',
							  SWIGOUTDIR=Dir('#/engine/python/fife').srcnode().path)
							  

copy_dest = os.path.join(opts['PYLIB_COPY_DEST'], '_fife' + dest_suffix)
copy_cmd = env.Command(copy_dest, pythonlib, [Copy('$TARGET', '$SOURCE')])
copy_cmd2 = env.Command(os.path.join(opts['WRAP_COPY_DEST'], 'fife_wrap.h'),
				os.path.join('swigwrappers','python','fife_wrap.h'),
				[Copy('$TARGET', '$SOURCE')])
copy_cmd3 = env.Command(os.path.join(opts['WRAP_COPY_DEST'], 'fife_wrap.cc'),
				os.path.join('swigwrappers','python','fife_wrap.cc'),
				[Copy('$TARGET', '$SOURCE')])

#**************************************************************************
#static library target
#**************************************************************************

staticlib = env.StaticLibrary(target = 'fife',
							  source = compilefiles,
							  LINKFLAGS=['-Wl'])

#**************************************************************************
#Install targets
#**************************************************************************

#TODO: This is not complete.  Because of the current linux rpath issue this
#will not work as expected.
install_static = env.Install(os.path.join(opts['PREFIX'], 'lib'), staticlib)
install_shared = env.Install(os.path.join(opts['PREFIX'], 'lib'), sharedlib)

headerdestlist = utils.gen_dest_files(os.path.join(opts['PREFIX'], 'include', 'fife'), headerfiles)
install_headers = env.InstallAs(headerdestlist, headerfiles)

pypath = os.path.join(opts['PYTHON_PREFIX'], 'fife') 
extdestfilelist = utils.gen_dest_files(pypath, relextensionfiles)

install_python_lib = env.Install(pypath, pythonlib)
install_python_module = env.Install(pypath, ['#/engine/python/fife/fife.py','#/engine/python/fife/__init__.py'])
install_python_extensions = env.InstallAs(extdestfilelist, extensionfiles)

if sys.platform == 'win32':
	dlldestfilelist = utils.gen_dest_files(pypath, dllfiles)
	dlldestfilelist2 = utils.gen_dest_files(os.path.join(engine_path, 'python', 'fife'), dllfiles)
	
	install_dlls = env.InstallAs(dlldestfilelist, dllfilelist)
	install_dlls2 = env.InstallAs(dlldestfilelist2, dllfilelist)

#**************************************************************************
#Alias definitions
#**************************************************************************

alias_msvc = Alias('msvc',msvcproj)
alias_msvc9 = Alias('msvc9',msvcproj9)
alias_cbwin32 = Alias('cbwin32',cbproj_win32)
alias_cblinux = Alias('cblinux',cbproj_linux)
Alias('projects',[alias_msvc, alias_msvc9, alias_cbwin32, alias_cblinux])

alias_shared = Alias('fife-shared', sharedlib)
alias_static = Alias('fife-static', staticlib)
alias_swig = Alias('fife-swig', [pythonext, copy_cmd2, copy_cmd3])

if sys.platform == 'win32':
	alias_python = Alias('fife-python', [pythonlib, copy_cmd, alias_swig, install_dlls2])
else:
	alias_python = Alias('fife-python', [pythonlib, copy_cmd, alias_swig])
	
Alias('fife', [alias_shared, alias_static, alias_python])
alias_install_shared = Alias('install-shared', install_shared)
alias_install_static = Alias('install-static', install_static)

if sys.platform == 'win32':
	alias_install_python = Alias('install-python', [alias_python, install_python_lib, install_python_module, install_python_extensions, install_dlls])
else:
	alias_install_python = Alias('install-python', [alias_python, install_python_lib, install_python_module, install_python_extensions])
	
alias_install_dev = Alias('install-dev', [alias_install_shared, alias_install_static, install_headers])
Alias('install-all', [alias_install_python, alias_install_dev])