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 | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 3 | VERSION='0.1' |
| 4 | APPNAME='ChronoSync' |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 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') |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 10 | # opt.load('ndnx', tooldir=["waf-tools"]) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 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''') |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 15 | syncopt.add_option('--with-log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx''') |
| 16 | syncopt.add_option('--with-tests', 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') |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 20 | |
Zhenkai Zhu | 699d740 | 2012-05-29 16:47:39 -0700 | [diff] [blame] | 21 | if conf.options.debug: |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 22 | conf.define ('_DEBUG', 1) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 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 | ]) |
Alexander Afanasyev | a0c8a1d | 2012-04-05 13:55:42 -0700 | [diff] [blame] | 31 | else: |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 32 | conf.add_supported_cxxflags (cxxflags = ['-O3', '-g']) |
| 33 | |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame^] | 34 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDNCXX', mandatory=True) |
| 35 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 36 | conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 37 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 38 | conf.check_boost(lib='system iostreams thread unit_test_framework') |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 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 ( |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 55 | target="ChronoSync", |
Yingdi Yu | ce841ca | 2013-12-14 08:28:00 +0800 | [diff] [blame] | 56 | # vnum = "1.0.0", |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 57 | features=['cxx', 'cxxshlib'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 58 | source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']), |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame^] | 59 | use = 'BOOST NDNCXX OPENSSL', |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 60 | includes = ['src'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 61 | ) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame^] | 62 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 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'], |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 69 | use = 'ChronoSync', |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 70 | includes = ['src'], |
Yingdi Yu | 0eee600 | 2014-02-11 15:54:17 -0800 | [diff] [blame] | 71 | install_path = None, |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 72 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 74 | if bld.get_define ("HAVE_LOG4CXX"): |
| 75 | libsync.use += ' LOG4CXX' |
Zhenkai Zhu | 43ae5c7 | 2012-05-31 23:18:45 -0700 | [diff] [blame] | 76 | if bld.get_define("_TEST"): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 77 | unittests.use += ' LOG4CXX' |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 79 | bld.install_files ( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame^] | 80 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
| 81 | files = bld.path.ant_glob(['src/**/*.h']), |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 82 | cwd = bld.path.find_dir ("src"), |
| 83 | relative_trick = True, |
| 84 | ) |
| 85 | |
| 86 | bld.install_files ( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame^] | 87 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
| 88 | files = bld.path.get_bld().ant_glob(['src/**/*.h']), |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 89 | cwd = bld.path.get_bld().find_dir ("src"), |
| 90 | relative_trick = True, |
| 91 | ) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 93 | pc = bld ( |
| 94 | features = "subst", |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 95 | source='ChronoSync.pc.in', |
| 96 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 97 | install_path = '${LIBDIR}/pkgconfig', |
| 98 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 99 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 100 | VERSION = VERSION, |
| 101 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 102 | |
Alexander Afanasyev | 150f14d | 2012-03-05 21:24:49 -0800 | [diff] [blame] | 103 | # doxygen docs |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 104 | from waflib.Build import BuildContext |
| 105 | class doxy (BuildContext): |
| 106 | cmd = "doxygen" |
| 107 | fun = "doxygen" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 109 | def doxygen (bld): |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 110 | if not bld.env.DOXYGEN: |
| 111 | bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 112 | bld (features="doxygen", |
| 113 | doxyfile='doc/doxygen.conf', |
| 114 | output_dir = 'doc') |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 115 | |
| 116 | @Configure.conf |
| 117 | def add_supported_cxxflags(self, cxxflags): |
| 118 | """ |
| 119 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 120 | """ |
| 121 | self.start_msg('Checking allowed flags for c++ compiler') |
| 122 | |
| 123 | supportedFlags = [] |
| 124 | for flag in cxxflags: |
| 125 | if self.check_cxx (cxxflags=[flag], mandatory=False): |
| 126 | supportedFlags += [flag] |
| 127 | |
| 128 | self.end_msg (' '.join (supportedFlags)) |
| 129 | self.env.CXXFLAGS += supportedFlags |