blob: 63c8eb227c522b55195bcbb7b439c55319f624bf [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''')
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')
Yingdi Yu43e71612013-10-30 22:19:31 -070020 # 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
Yingdi Yu43e71612013-10-30 22:19:31 -070035 # conf.check_ndnx ()
36
37 conf.check_cfg(package='libndn.cxx', args=['--cflags', '--libs'], uselib_store='NDNCXX', mandatory=True)
38 conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True)
39 # conf.check_openssl ()
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070040
41 conf.check_boost(lib='system iostreams test thread')
42
43 if conf.options.log4cxx:
44 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070045
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070046 if conf.options._test:
47 conf.define('_TEST', 1)
48
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080049 try:
50 conf.load('doxygen')
51 except:
52 pass
53
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070054 conf.load('protoc')
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070055
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080056def build (bld):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070057 libsync = bld (
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070058 target="ChronoSync",
Alexander Afanasyev5eb1cb52013-11-07 18:06:38 -080059 vnum = "1.0.0",
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070060 features=['cxx', 'cxxshlib'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070061 source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']),
Yingdi Yu43e71612013-10-30 22:19:31 -070062 use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNCXX OPENSSL',
Alexander Afanasyevce001692013-07-14 11:34:41 -070063 includes = ['src'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070064 )
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070065
66 # Unit tests
67 if bld.get_define("_TEST"):
68 unittests = bld.program (
69 target="unit-tests",
70 source = bld.path.ant_glob(['tests/**/*.cc']),
71 features=['cxx', 'cxxprogram'],
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070072 use = 'BOOST_TEST ChronoSync',
Alexander Afanasyevce001692013-07-14 11:34:41 -070073 includes = ['src'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070074 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070075
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070076 if bld.get_define ("HAVE_LOG4CXX"):
77 libsync.use += ' LOG4CXX'
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070078 if bld.get_define("_TEST"):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070079 unittests.use += ' LOG4CXX'
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070080
Alexander Afanasyevce001692013-07-14 11:34:41 -070081 bld.install_files (
82 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
83 files = bld.path.ant_glob(['src/**/*.h']),
84 cwd = bld.path.find_dir ("src"),
85 relative_trick = True,
86 )
87
88 bld.install_files (
89 dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
90 files = bld.path.get_bld().ant_glob(['src/**/*.h']),
91 cwd = bld.path.get_bld().find_dir ("src"),
92 relative_trick = True,
93 )
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080094
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070095 pc = bld (
96 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -070097 source='ChronoSync.pc.in',
98 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070099 install_path = '${LIBDIR}/pkgconfig',
100 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -0700101 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700102 VERSION = VERSION,
103 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700104
Alexander Afanasyev150f14d2012-03-05 21:24:49 -0800105# doxygen docs
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800106from waflib.Build import BuildContext
107class doxy (BuildContext):
108 cmd = "doxygen"
109 fun = "doxygen"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800110
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800111def doxygen (bld):
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800112 if not bld.env.DOXYGEN:
113 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800114 bld (features="doxygen",
115 doxyfile='doc/doxygen.conf',
116 output_dir = 'doc')
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700117
118@Configure.conf
119def add_supported_cxxflags(self, cxxflags):
120 """
121 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
122 """
123 self.start_msg('Checking allowed flags for c++ compiler')
124
125 supportedFlags = []
126 for flag in cxxflags:
127 if self.check_cxx (cxxflags=[flag], mandatory=False):
128 supportedFlags += [flag]
129
130 self.end_msg (' '.join (supportedFlags))
131 self.env.CXXFLAGS += supportedFlags