blob: dff5965acbf36b3ece557cbbf261b9ae47aeebb9 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyev7804c232013-07-14 12:15:41 -07003VERSION='0.1'
4APPNAME='ChronoSync'
Alexander Afanasyev182fdc22012-03-05 18:06:52 -08005
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -07006from waflib import Configure, Build, Logs
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07007
Alexander Afanasyeve76f2632012-03-05 00:18:42 -08008def options(opt):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -07009 opt.load('compiler_c compiler_cxx boost doxygen gnu_dirs protoc')
Yingdi Yu43e71612013-10-30 22:19:31 -070010 # opt.load('ndnx', tooldir=["waf-tools"])
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070011
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 Yu0eee6002014-02-11 15:54:17 -080015 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 Afanasyev7a696fb2012-03-01 17:17:22 -080017
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080018def configure(conf):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070019 conf.load('compiler_c compiler_cxx gnu_dirs boost')
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070020
Zhenkai Zhu699d7402012-05-29 16:47:39 -070021 if conf.options.debug:
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070022 conf.define ('_DEBUG', 1)
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070023 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 Afanasyeva0c8a1d2012-04-05 13:55:42 -070031 else:
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070032 conf.add_supported_cxxflags (cxxflags = ['-O3', '-g'])
33
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070034 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDNCXX', mandatory=True)
35
Yingdi Yu43e71612013-10-30 22:19:31 -070036 conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True)
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070037
Yingdi Yu280bb962014-01-30 09:52:43 -080038 conf.check_boost(lib='system iostreams thread unit_test_framework')
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070039
40 if conf.options.log4cxx:
41 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070042
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070043 if conf.options._test:
44 conf.define('_TEST', 1)
45
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080046 try:
47 conf.load('doxygen')
48 except:
49 pass
50
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070051 conf.load('protoc')
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070052
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080053def build (bld):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070054 libsync = bld (
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070055 target="ChronoSync",
Yingdi Yuce841ca2013-12-14 08:28:00 +080056 # vnum = "1.0.0",
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070057 features=['cxx', 'cxxshlib'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070058 source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']),
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070059 use = 'BOOST NDNCXX OPENSSL',
Alexander Afanasyevce001692013-07-14 11:34:41 -070060 includes = ['src'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070061 )
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070062
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070063 # 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 Yu280bb962014-01-30 09:52:43 -080069 use = 'ChronoSync',
Alexander Afanasyevce001692013-07-14 11:34:41 -070070 includes = ['src'],
Yingdi Yu0eee6002014-02-11 15:54:17 -080071 install_path = None,
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070072 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070073
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070074 if bld.get_define ("HAVE_LOG4CXX"):
75 libsync.use += ' LOG4CXX'
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070076 if bld.get_define("_TEST"):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070077 unittests.use += ' LOG4CXX'
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070078
Alexander Afanasyevce001692013-07-14 11:34:41 -070079 bld.install_files (
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070080 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
81 files = bld.path.ant_glob(['src/**/*.h']),
Alexander Afanasyevce001692013-07-14 11:34:41 -070082 cwd = bld.path.find_dir ("src"),
83 relative_trick = True,
84 )
85
86 bld.install_files (
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070087 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
88 files = bld.path.get_bld().ant_glob(['src/**/*.h']),
Alexander Afanasyevce001692013-07-14 11:34:41 -070089 cwd = bld.path.get_bld().find_dir ("src"),
90 relative_trick = True,
91 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080092
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070093 pc = bld (
94 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070095 source='ChronoSync.pc.in',
96 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070097 install_path = '${LIBDIR}/pkgconfig',
98 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070099 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700100 VERSION = VERSION,
101 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700102
Alexander Afanasyev150f14d2012-03-05 21:24:49 -0800103# doxygen docs
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800104from waflib.Build import BuildContext
105class doxy (BuildContext):
106 cmd = "doxygen"
107 fun = "doxygen"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800108
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800109def doxygen (bld):
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800110 if not bld.env.DOXYGEN:
111 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800112 bld (features="doxygen",
113 doxyfile='doc/doxygen.conf',
114 output_dir = 'doc')
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700115
116@Configure.conf
117def 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