root/trunk/SConstruct

Revision 724, 11.7 kB (checked in by tom, 3 weeks ago)

Add an INTERNAL_LIBAGG build option that can be used to make mapnik
build against the system libagg instead of mapnik's copy.

  • Property svn:keywords set to Id
Line 
1#
2# This file is part of Mapnik (c++ mapping toolkit)
3#
4# Copyright (C) 2006 Artem Pavlenko, Jean-Francois Doyon
5#
6# Mapnik is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# This library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this library; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id$
21
22
23import os, sys, platform
24
25if platform.uname()[4] == 'x86_64':
26    LIBDIR_SCHEMA='lib64'
27elif platform.uname()[4] == 'ppc64':
28    LIBDIR_SCHEMA='lib64'
29else:
30    LIBDIR_SCHEMA='lib'
31
32#### SCons build options and initial setup ####
33
34# All of the following options may be modified at the command-line, for example:
35# `python scons/scons PREFIX=/opt`
36opts = Options('config.py')
37opts.Add('CXX', 'The C++ compiler to use (defaults to g++).', 'g++')
38opts.Add('PREFIX', 'The install path "prefix"', '/usr/local')
39opts.Add(PathOption('BOOST_INCLUDES', 'Search path for boost include files', '/usr/include'))
40opts.Add(PathOption('BOOST_LIBS', 'Search path for boost library files', '/usr/' + LIBDIR_SCHEMA))
41opts.Add('BOOST_TOOLKIT','Specify boost toolkit e.g. gcc41.','',False)
42opts.Add(('FREETYPE_CONFIG', 'The path to the freetype-config executable.', 'freetype-config'))
43opts.Add(('XML2_CONFIG', 'The path to the xml2-config executable.', 'xml2-config'))
44opts.Add(PathOption('ICU_INCLUDES', 'Search path for ICU include files', '/usr/include'))
45opts.Add(PathOption('ICU_LIBS','Search path for ICU include files','/usr/' + LIBDIR_SCHEMA))
46opts.Add(PathOption('PNG_INCLUDES', 'Search path for libpng include files', '/usr/include'))
47opts.Add(PathOption('PNG_LIBS','Search path for libpng include files','/usr/' + LIBDIR_SCHEMA))
48opts.Add(PathOption('JPEG_INCLUDES', 'Search path for libjpeg include files', '/usr/include'))
49opts.Add(PathOption('JPEG_LIBS', 'Search path for libjpeg library files', '/usr/' + LIBDIR_SCHEMA))
50opts.Add(PathOption('TIFF_INCLUDES', 'Search path for libtiff include files', '/usr/include'))
51opts.Add(PathOption('TIFF_LIBS', 'Search path for libtiff library files', '/usr/' + LIBDIR_SCHEMA))
52opts.Add(PathOption('PGSQL_INCLUDES', 'Search path for PostgreSQL include files', '/usr/include'))
53opts.Add(PathOption('PGSQL_LIBS', 'Search path for PostgreSQL library files', '/usr/' + LIBDIR_SCHEMA))
54opts.Add(PathOption('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/local/include'))
55opts.Add(PathOption('PROJ_LIBS', 'Search path for PROJ.4 library files', '/usr/local/' + LIBDIR_SCHEMA))
56opts.Add(PathOption('GDAL_INCLUDES', 'Search path for GDAL include files', '/usr/include'))
57opts.Add(PathOption('GDAL_LIBS', 'Search path for GDAL library files', '/usr/' + LIBDIR_SCHEMA))
58opts.Add(PathOption('PYTHON','Python executable', sys.executable))
59opts.Add(ListOption('INPUT_PLUGINS','Input drivers to include','all',['postgis','shape','raster','gdal']))
60opts.Add(ListOption('BINDINGS','Language bindings to build','all',['python']))
61opts.Add(BoolOption('DEBUG', 'Compile a debug version of mapnik', 'False'))
62opts.Add('DESTDIR', 'The root directory to install into. Useful mainly for binary package building', '/')
63opts.Add(EnumOption('THREADING','Set threading support','multi', ['multi','single']))
64opts.Add(EnumOption('XMLPARSER','Set xml parser ','tinyxml', ['tinyxml','spirit','libxml2']))
65opts.Add(BoolOption('INTERNAL_LIBAGG', 'Use provided libagg', 'True'))
66
67env = Environment(ENV=os.environ, options=opts)
68
69def color_print(color,text):
70    # 1 - red
71    # 2 - green
72    # 3 - yellow
73    # 4 - blue
74    print "\033[9%sm%s\033[0m" % (color,text)
75
76env['LIBDIR_SCHEMA'] = LIBDIR_SCHEMA
77env['PLATFORM'] = platform.uname()[0]
78color_print (4,"Building on %s ..." % env['PLATFORM'])
79Help(opts.GenerateHelpText(env))
80
81thread_suffix = '-mt'
82
83if env['PLATFORM'] == 'FreeBSD':
84    thread_suffix = ''
85    env.Append(LIBS = 'pthread')
86
87conf = Configure(env)
88
89#### Libraries and headers dependency checks ####
90
91# Helper function for uniquely appending paths to a SCons path listing.
92def uniq_add(env, key, val):
93    if not val in env[key]: env[key].append(val)
94
95# Libraries and headers dependency checks
96env['CPPPATH'] = ['#tinyxml', '#include', '#']
97env['LIBPATH'] = ['#src']
98
99# Solaris & Sun Studio settings (the `SUNCC` flag will only be
100# set if the `CXX` option begins with `CC`)
101SOLARIS = env['PLATFORM'] == 'SunOS'
102SUNCC = SOLARIS and env['CXX'].startswith('CC')
103
104# For Solaris include paths (e.g., for freetype2, ltdl, etc.).
105if SOLARIS:
106    blastwave_dir = '/opt/csw/%s'
107    uniq_add(env, 'CPPPATH', blastwave_dir % 'include')
108    uniq_add(env, 'LIBPATH', blastwave_dir % LIBDIR_SCHEMA)
109
110# If the Sun Studio C++ compiler (`CC`) is used instead of GCC.
111if SUNCC:
112    env['CC'] = 'cc'
113    # To be compatible w/Boost everything needs to be compiled
114    # with the `-library=stlport4` flag (which needs to come
115    # before the `-o` flag).
116    env['CXX'] = 'CC -library=stlport4'
117    if env['THREADING'] == 'multi':
118        env['CXXFLAGS'] = ['-mt']
119
120# Decide which libagg to use
121if env['INTERNAL_LIBAGG']:
122    env.Prepend(CPPPATH = '#agg/include');
123    env.Prepend(LIBPATH = '#agg');
124else:
125    env.ParseConfig('pkg-config --libs --cflags libagg')
126
127# Adding the prerequisite library directories to the include path for
128# compiling and the library path for linking, respectively.
129for prereq in ('BOOST', 'PNG', 'JPEG', 'TIFF', 'PGSQL', 'PROJ', 'GDAL',):
130    inc_path = env['%s_INCLUDES' % prereq]
131    lib_path = env['%s_LIBS' % prereq]
132    uniq_add(env, 'CPPPATH', inc_path)
133    uniq_add(env, 'LIBPATH', lib_path)
134   
135env.ParseConfig(env['FREETYPE_CONFIG'] + ' --libs --cflags')
136   
137if env.Execute('pkg-config --exists cairomm-1.0') == 0:
138    env.ParseConfig('pkg-config --libs --cflags cairomm-1.0')
139    env.Append(CXXFLAGS = '-DHAVE_CAIRO');
140
141if env['XMLPARSER'] == 'tinyxml':
142    env.Append(CXXFLAGS = '-DBOOST_PROPERTY_TREE_XML_PARSER_TINYXML -DTIXML_USE_STL')
143elif env['XMLPARSER'] == 'libxml2':
144    env.ParseConfig(env['XML2_CONFIG'] + ' --libs --cflags')
145    env.Append(CXXFLAGS = '-DHAVE_LIBXML2');
146   
147C_LIBSHEADERS = [
148    ['m', 'math.h', True],
149    ['ltdl', 'ltdl.h', True],
150    ['png', 'png.h', True],
151    ['tiff', 'tiff.h', True],
152    ['z', 'zlib.h', True],
153    ['jpeg', ['stdio.h', 'jpeglib.h'], True],
154    ['proj', 'proj_api.h', True],
155    ['pq', 'libpq-fe.h', False]
156]
157
158CXX_LIBSHEADERS = [
159    ['icuuc','unicode/unistr.h',True],
160    ['icudata','unicode/utypes.h' , True],
161    ['gdal', 'gdal_priv.h',False]
162]
163
164BOOST_LIBSHEADERS = [
165    ['system', 'boost/system/system_error.hpp', False],
166    ['filesystem', 'boost/filesystem/operations.hpp', True],
167    ['regex', 'boost/regex.hpp', True],
168    ['iostreams','boost/iostreams/device/mapped_file.hpp',True],
169    ['program_options', 'boost/program_options.hpp', False]
170]
171
172if env['THREADING'] == 'multi':
173    BOOST_LIBSHEADERS.append(['thread', 'boost/thread/mutex.hpp', True])
174   
175for libinfo in C_LIBSHEADERS:
176    if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], 'C') and libinfo[2]:
177        color_print (1,'Could not find header or shared library for %s, exiting!' % libinfo[0])
178        Exit(1)
179
180for libinfo in CXX_LIBSHEADERS:
181    if not conf.CheckLibWithHeader(libinfo[0], libinfo[1], 'C++') and libinfo[2]:
182        color_print(1,'Could not find header or shared library for %s, exiting!' % libinfo[0])
183        Exit(1)
184
185if len(env['BOOST_TOOLKIT']):
186    env['BOOST_APPEND'] = '-%s' % env['BOOST_TOOLKIT']
187else:
188    env['BOOST_APPEND']=''
189   
190for count, libinfo in enumerate(BOOST_LIBSHEADERS):
191    if  env['THREADING'] == 'multi' :
192        if not conf.CheckLibWithHeader('boost_%s%s%s' % (libinfo[0],thread_suffix,env['BOOST_APPEND']), libinfo[1], 'C++') and libinfo[2] :
193            color_print(1,'Could not find header or shared library for boost %s, exiting!' % libinfo[0])
194            Exit(1)
195    elif not conf.CheckLibWithHeader('boost_%s%s' % (libinfo[0], env['BOOST_APPEND']), libinfo[1], 'C++') :
196        color_print(1,'Could not find header or shared library for boost %s, exiting!' % libinfo[0])
197        Exit(1)   
198 
199Export('env')
200
201inputplugins = [ driver.strip() for driver in Split(env['INPUT_PLUGINS'])]
202
203bindings = [ binding.strip() for binding in Split(env['BINDINGS'])]
204
205#### Build instructions & settings ####
206
207# Build agg first, doesn't need anything special
208if env['INTERNAL_LIBAGG']:
209    SConscript('agg/SConscript')
210
211# Build the core library
212SConscript('src/SConscript')
213
214# Build shapeindex and remove its dependency from the LIBS
215if 'boost_program_options%s%s' % (env['BOOST_APPEND'],thread_suffix) in env['LIBS']:
216    SConscript('utils/shapeindex/SConscript')
217    env['LIBS'].remove('boost_program_options%s%s' % (env['BOOST_APPEND'],thread_suffix))
218
219# Build the input plug-ins
220if 'postgis' in inputplugins and 'pq' in env['LIBS']:
221    SConscript('plugins/input/postgis/SConscript')
222    env['LIBS'].remove('pq')
223
224if 'shape' in inputplugins:
225    SConscript('plugins/input/shape/SConscript')
226
227if 'raster' in inputplugins:
228    SConscript('plugins/input/raster/SConscript')
229
230if 'gdal' in inputplugins and 'gdal' in env['LIBS']:
231    SConscript('plugins/input/gdal/SConscript')
232
233if 'gigabase' in inputplugins and 'gigabase_r' in env['LIBS']:
234    SConscript('plugins/input/gigabase/SConscript')
235
236# Build the Python bindings.
237if 'python' in env['BINDINGS']:
238    if not os.access(env['PYTHON'], os.X_OK):
239        color_print(1,"Cannot run python interpreter at '%s', make sure that you have the permissions to execute it." % env['PYTHON'])
240        Exit(1)
241
242    env['PYTHON_PREFIX'] = os.popen("%s -c 'import sys; print sys.prefix'" % env['PYTHON']).read().strip()
243    env['PYTHON_VERSION'] = os.popen("%s -c 'import sys; print sys.version'" % env['PYTHON']).read()[0:3]
244
245    color_print(4,'Bindings Python version... %s' % env['PYTHON_VERSION'])
246
247    majver, minver = env['PYTHON_VERSION'].split('.')
248
249    if (int(majver), int(minver)) < (2, 2):
250        color_print(1,"Python version 2.2 or greater required")
251        Exit(1)
252
253    color_print(4,'Python %s prefix... %s' % (env['PYTHON_VERSION'], env['PYTHON_PREFIX']))
254
255    SConscript('bindings/python/SConscript')
256   
257env = conf.Finish()
258
259# Common C++ flags.
260if env['THREADING'] == 'multi' :
261    common_cxx_flags = '-D%s -DBOOST_SPIRIT_THREADSAFE -DMAPNIK_THREADSAFE ' % env['PLATFORM'].upper()
262else :
263    common_cxx_flags = '-D%s ' % env['PLATFORM'].upper()
264   
265# Mac OSX (Darwin) special settings
266if env['PLATFORM'] == 'Darwin':
267    pthread = ''
268    # Getting the macintosh version number, sticking as a compiler macro
269    # for Leopard -- needed because different workarounds are needed than
270    # for Tiger.
271    if platform.mac_ver()[0].startswith('10.5'):
272        common_cxx_flags += '-DOSX_LEOPARD '
273else:
274    pthread = '-pthread'
275
276# Common debugging flags.
277debug_flags  = '-g -DDEBUG -DMAPNIK_DEBUG'
278ndebug_flags = '-DNDEBUG'
279
280# Customizing the C++ compiler flags depending on:
281#  (1) the C++ compiler used; and
282#  (2) whether debug binaries are requested.
283if SUNCC:
284    if env['DEBUG']:
285        env.Append(CXXFLAGS = common_cxx_flags + debug_flags)
286    else:
287        env.Append(CXXFLAGS = common_cxx_flags + '-O %s' % ndebug_flags)
288else:
289    # Common flags for GCC.
290    gcc_cxx_flags = '-ansi -Wall %s -ftemplate-depth-100 %s' % (pthread, common_cxx_flags)
291
292    if env['DEBUG']:
293        env.Append(CXXFLAGS = gcc_cxx_flags + '-O0 -fno-inline %s' % debug_flags)
294    else:
295        env.Append(CXXFLAGS = gcc_cxx_flags + '-O2 -finline-functions -Wno-inline %s' % ndebug_flags)
296
297
298SConscript('fonts/SConscript')
299
Note: See TracBrowser for help on using the browser.