akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | VERSION='0.1' |
| 4 | APPNAME='nsync' |
| 5 | |
| 6 | from waflib import Configure, Build, Logs |
| 7 | |
| 8 | def options(opt): |
| 9 | opt.load('compiler_c compiler_cxx boost doxygen gnu_dirs protoc') |
| 10 | # opt.load('ndnx', tooldir=["waf-tools"]) |
| 11 | |
| 12 | syncopt = opt.add_option_group ("ChronoSync Options") |
| 13 | |
| 14 | syncopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''') |
| 15 | syncopt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx''') |
| 16 | syncopt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''') |
| 17 | |
| 18 | def configure(conf): |
| 19 | conf.load('compiler_c compiler_cxx gnu_dirs boost') |
| 20 | |
| 21 | if conf.options.debug: |
| 22 | conf.define ('_DEBUG', 1) |
| 23 | conf.add_supported_cxxflags (cxxflags = ['-O0', |
| 24 | '-Wall', |
| 25 | '-Wno-unused-variable', |
| 26 | '-g3', |
| 27 | '-Wno-unused-private-field', # only clang supports |
| 28 | '-fcolor-diagnostics', # only clang supports |
| 29 | '-Qunused-arguments' # only clang supports |
| 30 | ]) |
| 31 | else: |
| 32 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g']) |
| 33 | |
| 34 | conf.check_cfg(package='libndn-cpp-dev', args=['--cflags', '--libs'], uselib_store='NDNCPP', mandatory=True) |
| 35 | |
| 36 | conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True) |
| 37 | |
| 38 | conf.check_boost(lib='system iostreams thread unit_test_framework') |
| 39 | |
| 40 | if conf.options.log4cxx: |
| 41 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True) |
| 42 | |
| 43 | if conf.options._test: |
| 44 | conf.define('_TEST', 1) |
| 45 | |
| 46 | try: |
| 47 | conf.load('doxygen') |
| 48 | except: |
| 49 | pass |
| 50 | |
| 51 | conf.load('protoc') |
| 52 | |
| 53 | def build (bld): |
| 54 | libsync = bld ( |
| 55 | target="nsync", |
| 56 | # vnum = "1.0.0", |
| 57 | features=['cxx', 'cxxshlib'], |
| 58 | source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']), |
| 59 | use = 'BOOST NDNCPP OPENSSL', |
| 60 | includes = ['src'], |
| 61 | ) |
| 62 | |
| 63 | # Unit tests |
| 64 | if bld.get_define("_TEST"): |
| 65 | unittests = bld.program ( |
| 66 | target="unit-tests", |
| 67 | source = bld.path.ant_glob(['tests/**/*.cc']), |
| 68 | features=['cxx', 'cxxprogram'], |
| 69 | use = 'nsync', |
| 70 | includes = ['src'], |
| 71 | ) |
| 72 | |
| 73 | if bld.get_define ("HAVE_LOG4CXX"): |
| 74 | libsync.use += ' LOG4CXX' |
| 75 | if bld.get_define("_TEST"): |
| 76 | unittests.use += ' LOG4CXX' |
| 77 | |
| 78 | bld.install_files ( |
| 79 | dest = "%s/nsync" % bld.env['INCLUDEDIR'], |
| 80 | files = bld.path.ant_glob(['src/**/*.h']), |
| 81 | cwd = bld.path.find_dir ("src"), |
| 82 | relative_trick = True, |
| 83 | ) |
| 84 | |
| 85 | bld.install_files ( |
| 86 | dest = "%s/nsync" % bld.env['INCLUDEDIR'], |
| 87 | files = bld.path.get_bld().ant_glob(['src/**/*.h']), |
| 88 | cwd = bld.path.get_bld().find_dir ("src"), |
| 89 | relative_trick = True, |
| 90 | ) |
| 91 | |
| 92 | pc = bld ( |
| 93 | features = "subst", |
| 94 | source='nsync.pc.in', |
| 95 | target='nsync.pc', |
| 96 | install_path = '${LIBDIR}/pkgconfig', |
| 97 | PREFIX = bld.env['PREFIX'], |
| 98 | INCLUDEDIR = "%s/nsync" % bld.env['INCLUDEDIR'], |
| 99 | VERSION = VERSION, |
| 100 | ) |
| 101 | |
| 102 | # doxygen docs |
| 103 | from waflib.Build import BuildContext |
| 104 | class doxy (BuildContext): |
| 105 | cmd = "doxygen" |
| 106 | fun = "doxygen" |
| 107 | |
| 108 | def doxygen (bld): |
| 109 | if not bld.env.DOXYGEN: |
| 110 | bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 111 | bld (features="doxygen", |
| 112 | doxyfile='doc/doxygen.conf', |
| 113 | output_dir = 'doc') |
| 114 | |
| 115 | @Configure.conf |
| 116 | def add_supported_cxxflags(self, cxxflags): |
| 117 | """ |
| 118 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 119 | """ |
| 120 | self.start_msg('Checking allowed flags for c++ compiler') |
| 121 | |
| 122 | supportedFlags = [] |
| 123 | for flag in cxxflags: |
| 124 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 125 | supportedFlags += [flag] |
| 126 | |
| 127 | self.end_msg (' '.join (supportedFlags)) |
| 128 | self.env.CXXFLAGS += supportedFlags |