Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 3 | VERSION='0.0.1' |
| 4 | APPNAME='sync' |
| 5 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 6 | from waflib import Configure, Build, Logs |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 7 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 8 | def options(opt): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 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''') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 17 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 18 | def configure(conf): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 19 | conf.load('compiler_c compiler_cxx gnu_dirs boost') |
| 20 | conf.load('ndnx') |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 21 | |
Zhenkai Zhu | 699d740 | 2012-05-29 16:47:39 -0700 | [diff] [blame] | 22 | if conf.options.debug: |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 23 | conf.define ('_DEBUG', 1) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 24 | conf.add_supported_cxxflags (cxxflags = ['-O0', |
| 25 | '-Wall', |
| 26 | '-Wno-unused-variable', |
| 27 | '-g3', |
| 28 | '-Wno-unused-private-field', # only clang supports |
| 29 | '-fcolor-diagnostics', # only clang supports |
| 30 | '-Qunused-arguments' # only clang supports |
| 31 | ]) |
Alexander Afanasyev | a0c8a1d | 2012-04-05 13:55:42 -0700 | [diff] [blame] | 32 | else: |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 33 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g']) |
| 34 | |
| 35 | conf.check_ndnx () |
| 36 | conf.check_openssl () |
| 37 | |
| 38 | conf.check_boost(lib='system iostreams test thread') |
| 39 | |
| 40 | if conf.options.log4cxx: |
| 41 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 42 | |
Zhenkai Zhu | 43ae5c7 | 2012-05-31 23:18:45 -0700 | [diff] [blame] | 43 | if conf.options._test: |
| 44 | conf.define('_TEST', 1) |
| 45 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 46 | try: |
| 47 | conf.load('doxygen') |
| 48 | except: |
| 49 | pass |
| 50 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 51 | conf.load('protoc') |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 53 | def build (bld): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 54 | libsync = bld ( |
| 55 | target=APPNAME, |
| 56 | features=['cxx', 'cxxshlib'], |
| 57 | source = ant_glob (['src/**/*.cc', 'src/**/*.proto']), |
| 58 | use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNX', |
| 59 | includes = ['include', 'src'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 60 | ) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 61 | |
| 62 | # Unit tests |
| 63 | if bld.get_define("_TEST"): |
| 64 | unittests = bld.program ( |
| 65 | target="unit-tests", |
| 66 | source = bld.path.ant_glob(['tests/**/*.cc']), |
| 67 | features=['cxx', 'cxxprogram'], |
| 68 | use = 'BOOST_TEST sync', |
| 69 | includes = ['include', 'src'], |
| 70 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 72 | if bld.get_define ("HAVE_LOG4CXX"): |
| 73 | libsync.use += ' LOG4CXX' |
Zhenkai Zhu | 43ae5c7 | 2012-05-31 23:18:45 -0700 | [diff] [blame] | 74 | if bld.get_define("_TEST"): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 75 | unittests.use += ' LOG4CXX' |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 77 | headers = bld.path.ant_glob(['include/*.h']) |
| 78 | headers.extend (bld.path.get_bld().ant_glob(['model/sync-state.pb.h'])) |
| 79 | bld.install_files ("%s/sync" % bld.env['INCLUDEDIR'], headers) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 80 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 81 | pc = bld ( |
| 82 | features = "subst", |
| 83 | source='libsync.pc.in', |
| 84 | target='libsync.pc', |
| 85 | install_path = '${LIBDIR}/pkgconfig', |
| 86 | PREFIX = bld.env['PREFIX'], |
| 87 | INCLUDEDIR = "%s/sync" % bld.env['INCLUDEDIR'], |
| 88 | VERSION = VERSION, |
| 89 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 150f14d | 2012-03-05 21:24:49 -0800 | [diff] [blame] | 91 | # doxygen docs |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 92 | from waflib.Build import BuildContext |
| 93 | class doxy (BuildContext): |
| 94 | cmd = "doxygen" |
| 95 | fun = "doxygen" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 97 | def doxygen (bld): |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 98 | if not bld.env.DOXYGEN: |
| 99 | bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 100 | bld (features="doxygen", |
| 101 | doxyfile='doc/doxygen.conf', |
| 102 | output_dir = 'doc') |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame^] | 103 | |
| 104 | @Configure.conf |
| 105 | def add_supported_cxxflags(self, cxxflags): |
| 106 | """ |
| 107 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 108 | """ |
| 109 | self.start_msg('Checking allowed flags for c++ compiler') |
| 110 | |
| 111 | supportedFlags = [] |
| 112 | for flag in cxxflags: |
| 113 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 114 | supportedFlags += [flag] |
| 115 | |
| 116 | self.end_msg (' '.join (supportedFlags)) |
| 117 | self.env.CXXFLAGS += supportedFlags |