Add the ability to pass custom CXXFLAGS and LDFLAGS that will be prioritized above other compiler and linker flags

This commit is contained in:
Dane Springmeyer 2010-09-18 18:02:15 +00:00
parent 65ef9a3548
commit 523b09701e
17 changed files with 81 additions and 37 deletions

View file

@ -243,6 +243,8 @@ opts.AddVariables(
# Compiler options
('CXX', 'The C++ compiler to use to compile mapnik (defaults to g++).', 'g++'),
('CC', 'The C compiler used for configure checks of C libs (defaults to gcc).', 'gcc'),
('CUSTOM_CXXFLAGS', 'Custom C++ flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir>', ''),
('CUSTOM_LDFLAGS', 'Custom linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir>', ''),
EnumVariable('OPTIMIZATION','Set g++ optimization level','2', ['0','1','2','3','4']),
# Note: setting DEBUG=True will override any custom OPTIMIZATION level
BoolVariable('DEBUG', 'Compile a debug version of Mapnik', 'False'),
@ -339,6 +341,8 @@ pickle_store = [# Scons internal variables
'LIBPATH',
'LIBS',
'LINKFLAGS',
'CUSTOM_LDFLAGS', # user submitted
'CUSTOM_CXXFLAGS', # user submitted
# Mapnik's SConstruct build variables
'PLUGINS',
'ABI_VERSION',
@ -785,11 +789,15 @@ if not preconfigured:
env['CPPPATH'] = ['#include', '#']
env['LIBPATH'] = ['#src']
# set any custom cxxflags to come first
env.Append(CXXFLAGS = env['CUSTOM_CXXFLAGS'])
# Solaris & Sun Studio settings (the `SUNCC` flag will only be
# set if the `CXX` option begins with `CC`)
SOLARIS = env['PLATFORM'] == 'SunOS'
env['SUNCC'] = SOLARIS and env['CXX'].startswith('CC')
# If the Sun Studio C++ compiler (`CC`) is used instead of GCC.
if env['SUNCC']:
env['CC'] = 'cc'

View file

@ -28,7 +28,6 @@ Import('env')
prefix = env['PREFIX']
target_path = env['PYTHON_INSTALL_LOCATION'] + '/mapnik2'
linkflags = ''
libraries = ['mapnik2','png','jpeg']
if env['BOOST_PYTHON_LIB']:
@ -68,12 +67,12 @@ if env['PLATFORM'] == 'Darwin':
# http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/ld.1.html
if env['PYTHON_DYNAMIC_LOOKUP']:
linkflags = '-undefined dynamic_lookup'
python_link_flag = '-undefined dynamic_lookup'
elif env['FRAMEWORK_PYTHON']:
if env['FRAMEWORK_SEARCH_PATH']:
# if the user has supplied a custom root path to search for
# a given Python framework, then use that to direct the linker
linkflags = '-F%s -framework Python -Z' % env['FRAMEWORK_SEARCH_PATH']
python_link_flag = '-F%s -framework Python -Z' % env['FRAMEWORK_SEARCH_PATH']
else:
# otherwise be as explicit as possible for linking to the same Framework
# as the executable we are building with (or is pointed to by the PYTHON variable)
@ -84,21 +83,25 @@ if env['PLATFORM'] == 'Darwin':
# See: http://trac.mapnik.org/ticket/380
link_prefix = env['PYTHON_SYS_PREFIX']
if '.framework' in link_prefix:
linkflags = '-F%s -framework Python -Z' % os.path.dirname(link_prefix.split('.')[0])
python_link_flag = '-F%s -framework Python -Z' % os.path.dirname(link_prefix.split('.')[0])
elif '/System' in link_prefix:
linkflags = '-F/System/Library/Frameworks/ -framework Python -Z'
python_link_flag = '-F/System/Library/Frameworks/ -framework Python -Z'
else:
# should we fall back to -lpython here?
linkflags = '-F/ -framework Python'
python_link_flag = '-F/ -framework Python'
# if we are not linking to a framework then use the *nix standard approach
else:
linkflags = '-lpython%s' % env['PYTHON_VERSION']
# TODO - do we need to pass -L/?
python_link_flag = '-lpython%s' % env['PYTHON_VERSION']
if env['CUSTOM_LDFLAGS']:
linkflags = '%s %s' % (env['CUSTOM_LDFLAGS'], python_link_flag)
else:
linkflags = python_link_flag
paths = '''
"""Configuration paths of Mapnik fonts and input plugins (autogenerated by SCons)."""
"""Configuration paths of Mapnik fonts and input plugins (auto-generated by SCons)."""
import os
@ -149,7 +152,7 @@ py_env.Append(CPPPATH = env['PYTHON_INCLUDES'])
if env['SVN_REVISION']:
sources.remove('mapnik_python.cpp')
env2 = py_env.Clone()
env2.Append(CCFLAGS='-DSVN_REVISION=%s' % env['SVN_REVISION'])
env2.Append(CXXFLAGS='-DSVN_REVISION=%s' % env['SVN_REVISION'])
if env['HAS_CAIRO'] or env['HAS_PYCAIRO']:
if env['HAS_CAIRO']:
env2.ParseConfig('pkg-config --libs --cflags cairomm-1.0')

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
gdal_src = Split(
"""
gdal_datasource.cpp
@ -36,7 +38,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik2')
libraries.append(env['ICU_LIB_NAME'])
gdal_inputdriver = env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
gdal_inputdriver = plugin_env.SharedLibrary('../gdal', source=gdal_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', gdal_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
kismet_src = Split(
"""
kismet_datasource.cpp
@ -37,7 +39,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append(env['ICU_LIB_NAME'])
libraries.append('boost_thread%s' % env['BOOST_APPEND'])
kismet_inputdriver = env.SharedLibrary('../kismet', source=kismet_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
kismet_inputdriver = plugin_env.SharedLibrary('../kismet', source=kismet_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', kismet_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
occi_src = Split(
"""
occi_types.cpp
@ -39,7 +41,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik2')
libraries.append(env['ICU_LIB_NAME'])
occi_inputdriver = env.SharedLibrary('../occi', source=occi_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
occi_inputdriver = plugin_env.SharedLibrary('../occi', source=occi_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', occi_inputdriver)

View file

@ -25,6 +25,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
ogr_src = Split(
"""
ogr_converter.cpp
@ -43,7 +45,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
ogr_inputdriver = env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
ogr_inputdriver = plugin_env.SharedLibrary('../ogr', source=ogr_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', ogr_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
osm_src = Split(
"""
osmparser.cpp
@ -41,7 +43,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik2')
libraries.append(env['ICU_LIB_NAME'])
osm_inputdriver = env.SharedLibrary('../osm', source=osm_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
osm_inputdriver = plugin_env.SharedLibrary('../osm', source=osm_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', osm_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
postgis_src = Split(
"""
postgis.cpp
@ -39,7 +41,7 @@ if env['PLATFORM'] == 'Darwin':
if env['THREADING'] == 'multi':
libraries.append('boost_thread%s' % env['BOOST_APPEND'])
postgis_inputdriver = env.SharedLibrary('../postgis', source=postgis_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
postgis_inputdriver = plugin_env.SharedLibrary('../postgis', source=postgis_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', postgis_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
raster_src = Split(
"""
raster_datasource.cpp
@ -39,7 +41,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
raster_inputdriver = env.SharedLibrary('../raster', source=raster_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
raster_inputdriver = plugin_env.SharedLibrary('../raster', source=raster_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', raster_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
rasterlite_src = Split(
"""
rasterlite_datasource.cpp
@ -36,7 +38,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik2')
libraries.append(env['ICU_LIB_NAME'])
rasterlite_inputdriver = env.SharedLibrary('../rasterlite', source=rasterlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
rasterlite_inputdriver = plugin_env.SharedLibrary('../rasterlite', source=rasterlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', rasterlite_inputdriver)

View file

@ -25,6 +25,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
shape_src = Split(
"""
dbffile.cpp
@ -44,11 +46,10 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
env2 = env.Clone()
if env['SHAPE_MEMORY_MAPPED_FILE']:
env2.Append(CXXFLAGS = '-DSHAPE_MEMORY_MAPPED_FILE')
plugin_env.Append(CXXFLAGS = '-DSHAPE_MEMORY_MAPPED_FILE')
shape_inputdriver = env2.SharedLibrary('../shape', SHLIBSUFFIX='.input', source=shape_src, SHLIBPREFIX='', LIBS = libraries)
shape_inputdriver = plugin_env.SharedLibrary('../shape', SHLIBSUFFIX='.input', source=shape_src, SHLIBPREFIX='', LIBS = libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', shape_inputdriver)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
plugin_env = env.Clone()
sqlite_src = Split(
"""
sqlite_datasource.cpp
@ -38,7 +40,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
sqlite_inputdriver = env.SharedLibrary('../sqlite', source=sqlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
sqlite_inputdriver = plugin_env.SharedLibrary('../sqlite', source=sqlite_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', sqlite_inputdriver)

View file

@ -26,6 +26,8 @@ from subprocess import Popen, PIPE
Import('env')
lib_env = env.Clone()
def call(cmd, silent=True):
stdin, stderr = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()
if not stderr:
@ -33,10 +35,11 @@ def call(cmd, silent=True):
elif not silent:
print stderr
def ldconfig(*args,**kwargs):
call('ldconfig')
mapnik_lib_link_flag = ''
ABI_VERSION = env['ABI_VERSION']
prefix = env['PREFIX']
@ -83,16 +86,16 @@ if env['PLATFORM'] == 'Darwin':
lib_path = '%s/%s' % (lib_dir,mapnik_libname)
else:
lib_path = mapnik_libname
linkflags = '-Wl,-install_name,%s' % lib_path
mapnik_lib_link_flag += ' -Wl,-install_name,%s' % lib_path
_d = {'version':env['MAPNIK_VERSION_STRING']}
linkflags += ' -current_version %(version)s -compatibility_version %(version)s' % _d
mapnik_lib_link_flag += ' -current_version %(version)s -compatibility_version %(version)s' % _d
elif env['PLATFORM'] == 'SunOS':
if env['CXX'].startswith('CC'):
linkflags = '-R. -h %s' % mapnik_libname
mapnik_lib_link_flag += ' -R. -h %s' % mapnik_libname
else:
linkflags = '-Wl,-h,%s' % mapnik_libname
mapnik_lib_link_flag += ' -Wl,-h,%s' % mapnik_libname
else: # Linux and others
linkflags = '-Wl,-rpath-link,. -Wl,-soname,%s' % mapnik_libname
mapnik_lib_link_flag += ' -Wl,-rpath-link,. -Wl,-soname,%s' % mapnik_libname
source = Split(
"""
@ -171,7 +174,7 @@ if True : # agg backend
)
if env['HAS_CAIRO']:
env2 = env.Clone()
env2 = lib_env.Clone()
env2.Append(CXXFLAGS = '-DHAVE_CAIRO')
env2.ParseConfig('pkg-config --libs --cflags cairomm-1.0')
fixup = ['cairo_renderer.cpp','graphics.cpp','image_util.cpp']
@ -193,7 +196,7 @@ elif env['XMLPARSER'] == 'libxml2' and env['HAS_LIBXML2']:
"""
libxml2_loader.cpp
""")
env2 = env.Clone()
env2 = lib_env.Clone()
env2.Append(CXXFLAGS = '-DHAVE_LIBXML2')
fixup = ['load_map.cpp','libxml2_loader.cpp']
for cpp in fixup:
@ -220,9 +223,14 @@ if env['SVG_RENDERER']: # svg backend
svg/process_shield_symbolizer.cpp
svg/process_text_symbolizer.cpp
""")
env.Append(CXXFLAGS = '-DSVG_RENDERER')
lib_env.Append(CXXFLAGS = '-DSVG_RENDERER')
mapnik = env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags)
if env['CUSTOM_LDFLAGS']:
linkflags = '%s %s' % (env['CUSTOM_LDFLAGS'], mapnik_lib_link_flag)
else:
linkflags = mapnik_lib_link_flag
mapnik = lib_env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags)
if env['PLATFORM'] != 'Darwin':
# Symlink command, only works if both files are in same directory

View file

@ -43,11 +43,11 @@ if env['HAS_BOOST_SYSTEM']:
if env['HAS_CAIRO']:
private_libs += ' -lcairomm-1.0 -lcairo'
other_libs = ''.join([' -L%s' % i for i in env['LIBPATH'] if not i.startswith('#')])
other_libs = env['CUSTOM_LDFLAGS'] + ''.join([' -L%s' % i for i in env['LIBPATH'] if not i.startswith('#')])
other_libs += private_libs
# todo - refine this list
other_includes = ''.join([' -I%s' % i for i in env['CPPPATH'] if not i.startswith('#')])
other_includes = env['CUSTOM_CXXFLAGS'] + ''.join([' -I%s' % i for i in env['CPPPATH'] if not i.startswith('#')])
top = '''#!/bin/sh

View file

@ -26,6 +26,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
program_env = env.Clone()
source = Split(
"""
ogrindex.cpp
@ -48,7 +50,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append(env['ICU_LIB_NAME'])
ogrindex = env.Program('ogrindex', source, CPPPATH=headers, LIBS=libraries)
ogrindex = program_env.Program('ogrindex', source, CPPPATH=headers, LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/bin', ogrindex)

View file

@ -24,6 +24,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
program_env = env.Clone()
source = Split(
"""
main.cpp
@ -42,7 +44,7 @@ if env['PLATFORM'] == 'Darwin':
libraries.append(env['ICU_LIB_NAME'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
pgsql2sqlite = env.Program('pgsql2sqlite', source, CPPPATH=headers, LIBS=libraries)
pgsql2sqlite = program_env.Program('pgsql2sqlite', source, CPPPATH=headers, LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
env.Install(install_prefix + '/bin', pgsql2sqlite)
env.Alias('install', install_prefix + '/bin')

View file

@ -26,6 +26,8 @@ Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
program_env = env.Clone()
source = Split(
"""
shapeindex.cpp
@ -47,7 +49,7 @@ if env['HAS_BOOST_SYSTEM']:
libraries.append(boost_system)
shapeindex = env.Program('shapeindex', source, CPPPATH=headers, LIBS=libraries)
shapeindex = program_env.Program('shapeindex', source, CPPPATH=headers, LIBS=libraries, LINKFLAGS=env['CUSTOM_LDFLAGS'])
if 'uninstall' not in COMMAND_LINE_TARGETS:
env.Install(install_prefix + '/bin', shapeindex)