blob: 6b9c8d6dbc6a0dc1b7f09be889c1ca940a0e1b9c [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')
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 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')
20 conf.load('ndnx')
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070021
Zhenkai Zhu699d7402012-05-29 16:47:39 -070022 if conf.options.debug:
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070023 conf.define ('_DEBUG', 1)
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070024 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 Afanasyeva0c8a1d2012-04-05 13:55:42 -070032 else:
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070033 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 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 (
55 target=APPNAME,
56 features=['cxx', 'cxxshlib'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070057 source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']),
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070058 use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNX',
Alexander Afanasyevce001692013-07-14 11:34:41 -070059 includes = ['src'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070060 )
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070061
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',
Alexander Afanasyevce001692013-07-14 11:34:41 -070069 includes = ['src'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070070 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070071
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070072 if bld.get_define ("HAVE_LOG4CXX"):
73 libsync.use += ' LOG4CXX'
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070074 if bld.get_define("_TEST"):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070075 unittests.use += ' LOG4CXX'
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070076
Alexander Afanasyevce001692013-07-14 11:34:41 -070077 bld.install_files (
78 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
79 files = bld.path.ant_glob(['src/**/*.h']),
80 cwd = bld.path.find_dir ("src"),
81 relative_trick = True,
82 )
83
84 bld.install_files (
85 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
86 files = bld.path.get_bld().ant_glob(['src/**/*.h']),
87 cwd = bld.path.get_bld().find_dir ("src"),
88 relative_trick = True,
89 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080090
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070091 pc = bld (
92 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070093 source='ChronoSync.pc.in',
94 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070095 install_path = '${LIBDIR}/pkgconfig',
96 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070097 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070098 VERSION = VERSION,
99 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700100
Alexander Afanasyev150f14d2012-03-05 21:24:49 -0800101# doxygen docs
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800102from waflib.Build import BuildContext
103class doxy (BuildContext):
104 cmd = "doxygen"
105 fun = "doxygen"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800106
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800107def doxygen (bld):
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800108 if not bld.env.DOXYGEN:
109 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800110 bld (features="doxygen",
111 doxyfile='doc/doxygen.conf',
112 output_dir = 'doc')
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700113
114@Configure.conf
115def add_supported_cxxflags(self, cxxflags):
116 """
117 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
118 """
119 self.start_msg('Checking allowed flags for c++ compiler')
120
121 supportedFlags = []
122 for flag in cxxflags:
123 if self.check_cxx (cxxflags=[flag], mandatory=False):
124 supportedFlags += [flag]
125
126 self.end_msg (' '.join (supportedFlags))
127 self.env.CXXFLAGS += supportedFlags