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