osrm-backend/SConstruct

172 lines
6.3 KiB
Python
Raw Normal View History

2010-07-21 11:03:26 -04:00
#Sconstruct
import os
2011-01-09 11:55:05 -05:00
import os.path
2010-07-21 11:03:26 -04:00
import sys
from subprocess import call
def CheckBoost(context, version):
# Boost versions are in format major.minor.subminor
v_arr = version.split(".")
version_n = 0
if len(v_arr) > 0:
version_n += int(v_arr[0])*100000
if len(v_arr) > 1:
version_n += int(v_arr[1])*100
if len(v_arr) > 2:
version_n += int(v_arr[2])
context.Message('Checking for Boost version >= %s... ' % (version))
ret = context.TryRun("""
#include <boost/version.hpp>
int main()
{
return BOOST_VERSION >= %d ? 0 : 1;
}
""" % version_n, '.cpp')[0]
context.Result(ret)
return ret
def CheckProtobuf(context, version):
# Protobuf versions are in format major.minor.subminor
v_arr = version.split(".")
version_n = 0
if len(v_arr) > 0:
version_n += int(v_arr[0])*1000000
if len(v_arr) > 1:
version_n += int(v_arr[1])*1000
if len(v_arr) > 2:
version_n += int(v_arr[2])
context.Message('Checking for Protobuffer version >= %s... ' % (version))
ret = context.TryRun("""
#include <google/protobuf/stubs/common.h>
int main() {
return (GOOGLE_PROTOBUF_VERSION >= %d) ? 0 : 1;
}
""" % version_n, '.cpp')[0]
context.Result(ret)
return ret
2010-07-21 11:03:26 -04:00
AddOption('--cxx', dest='cxx', type='string', nargs=1, action='store', metavar='STRING', help='C++ Compiler')
2010-07-24 10:11:20 -04:00
AddOption('--stxxlroot', dest='stxxlroot', type='string', nargs=1, action='store', metavar='STRING', help='root directory of STXXL')
2010-07-23 08:34:15 -04:00
AddOption('--verbosity', dest='verbosity', type='string', nargs=1, action='store', metavar='STRING', help='make Scons talking')
AddOption('--buildconfiguration', dest='buildconfiguration', type='string', nargs=1, action='store', metavar='STRING', help='debug or release')
2011-05-07 03:36:17 -04:00
env = Environment(ENV = {'PATH' : os.environ['PATH']} ,COMPILER = GetOption('cxx'))
2010-07-23 08:34:15 -04:00
if GetOption('cxx') is None:
#default Compiler
print 'Using default C++ Compiler: ', env['CXX']
else:
print 'Using user supplied C++ Compiler: ', env['CXX']
env.Replace(CXX = GetOption('cxx'))
2010-07-24 10:11:20 -04:00
if GetOption('stxxlroot') is not None:
env.Append(CPPPATH = GetOption('stxxlroot')+'/include')
env.Append(LIBPATH = GetOption('stxxlroot')+'/lib')
print 'STXXLROOT = ', GetOption('stxxlroot')
2010-07-21 11:03:26 -04:00
if sys.platform == 'win32':
2010-07-23 08:34:15 -04:00
#SCons really wants to use Microsoft compiler
print "Compiling is not yet supported on Windows"
2010-07-21 11:03:26 -04:00
Exit(-1)
else: #Mac OS X
if sys.platform == 'darwin':
print "Compiling is experimental on Mac"
env.Append(CPPPATH = ['/opt/local/include/', '/opt/local/include/libxml2'])
env.Append(LIBPATH = ['/opt/local/lib'])
else:
env.Append(CPPPATH = ['/usr/include', '/usr/include/include', '/usr/include/libxml2/'])
if GetOption('buildconfiguration') == 'debug':
env.Append(CCFLAGS = ' -Wall -g3')
else:
env.Append(CCFLAGS = ' -O3 -DNDEBUG -march=native')
2010-07-23 08:34:15 -04:00
#print "Compiling with: ", env['CXX']
conf = Configure(env, custom_tests = { 'CheckBoost' : CheckBoost, 'CheckProtobuf' : CheckProtobuf })
2010-07-21 11:03:26 -04:00
if not conf.CheckHeader('omp.h'):
print "Compiler does not support OpenMP. Exiting"
2011-05-07 03:36:17 -04:00
if sys.platform == 'darwin':
print "Continuing because we are on Mac. This might be fatal."
else:
Exit(-1)
2010-07-21 11:03:26 -04:00
if not conf.CheckLibWithHeader('xml2', 'libxml/xmlreader.h', 'CXX'):
print "libxml2 library or header not found. Exiting"
Exit(-1)
if not conf.CheckLibWithHeader('z', 'zlib.h', 'CXX'):
2011-02-06 14:27:44 -05:00
print "zlib library or header not found. Exiting"
Exit(-1)
2010-07-21 11:03:26 -04:00
if not conf.CheckCXXHeader('stxxl.h'):
print "Could not locate stxxl header. Exiting"
Exit(-1)
if not conf.CheckCXXHeader('google/sparse_hash_map'):
print "Could not find Google Sparsehash library. Exiting"
Exit(-1)
if not conf.CheckCXXHeader('boost/asio.hpp'):
print "boost/asio.hpp not found. Exiting"
Exit(-1)
if not conf.CheckLibWithHeader('bz2', 'bzlib.h', 'CXX'):
print "bz2 library not found. Exiting"
Exit(-1)
if not conf.CheckLibWithHeader('boost_thread', 'boost/thread.hpp', 'CXX'):
if not conf.CheckLibWithHeader('boost_thread-mt', 'boost/thread.hpp', 'CXX'):
2010-07-21 11:03:26 -04:00
print "boost thread library not found. Exiting"
Exit(-1)
2010-07-24 10:00:00 -04:00
else:
print "using boost -mt"
2010-07-24 10:00:00 -04:00
env.Append(CCFLAGS = ' -lboost_thread-mt')
env.Append(LINKFLAGS = ' -lboost_thread-mt')
2010-07-21 11:03:26 -04:00
if not conf.CheckCXXHeader('boost/thread.hpp'):
print "boost thread header not found. Exiting"
Exit(-1)
2011-03-30 16:03:16 -04:00
if not conf.CheckLib('boost_system', language="C++"):
print "boost_system library not found. Exiting"
Exit(-1)
2010-07-21 11:03:26 -04:00
if not conf.CheckCXXHeader('boost/bind.hpp'):
print "boost/bind.hpp not found. Exiting"
Exit(-1)
if not conf.CheckCXXHeader('boost/thread.hpp'):
print "boost/thread.hpp not found. Exiting"
Exit(-1)
if not conf.CheckCXXHeader('boost/noncopyable.hpp'):
print "boost/noncopyable.hpp not found. Exiting"
Exit(-1)
if not conf.CheckCXXHeader('boost/shared_ptr.hpp'):
print "boost/shared_ptr.hpp not found. Exiting"
Exit(-1)
if not conf.CheckLibWithHeader('stxxl', 'stxxl.h', 'CXX'):
2010-07-21 11:03:26 -04:00
print "stxxl library not found. Exiting"
Exit(-1)
if not conf.CheckLibWithHeader('protobuf', 'google/protobuf/descriptor.h', 'CXX'):
print "Google Protobuffer library not found. Exiting"
Exit(-1)
#if os.sysconf('SC_NPROCESSORS_ONLN') > 1:
# env.Append(CCFLAGS = ' -D_GLIBCXX_PARALLEL');
if not (conf.CheckBoost('1.37')):
print 'Boost version >= 1.37 needed'
Exit(-1);
#check for protobuf 2.3.0, else rebuild proto files
if not (conf.CheckProtobuf('2.3.0')):
print 'libprotobuf version >= 2.3.0 needed'
2011-04-20 09:20:27 -04:00
Exit(-1);
if not (env.Detect('protoc')):
print 'protobuffer compiler not found'
Exit(-1);
2010-07-21 11:03:26 -04:00
protobld = Builder(action = 'protoc -I=DataStructures/pbf-proto --cpp_out=DataStructures/pbf-proto $SOURCE')
env.Append(BUILDERS = {'Protobuf' : protobld})
env.Protobuf('DataStructures/pbf-proto/fileformat.proto')
env.Protobuf('DataStructures/pbf-proto/osmformat.proto')
2010-07-21 11:03:26 -04:00
env.Append(CCFLAGS = ' -fopenmp')
env.Append(LINKFLAGS = ' -fopenmp')
env.StaticObject("DataStructures/pbf-proto/fileformat.pb.cc")
env.StaticObject("DataStructures/pbf-proto/osmformat.pb.cc")
env.Program("extractor.cpp")
env.Program("createHierarchy.cpp")
2011-01-09 11:55:05 -05:00
if os.path.exists("many-to-many.cpp"):
env.Program("many-to-many.cpp")
2011-03-29 10:27:44 -04:00
env.Append(CCFLAGS = ' -lboost_regex -lboost_iostreams -lbz2 -lz -lprotobuf')
env.Append(LINKFLAGS = '-lboost_system DataStructures/pbf-proto/fileformat.pb.o DataStructures/pbf-proto/osmformat.pb.o')
2010-07-21 11:03:26 -04:00
env.Program("routed.cpp")
env = conf.Finish()