blob: 0c1783e13f3fee742fb8bc8d15bccdf38ca1a06d [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
Yingdi Yuce841ca2013-12-14 08:28:00 +080018 opt.load('ndn_cpp', tooldir=['waf-tools'])
19
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080020def configure(conf):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070021 conf.load('compiler_c compiler_cxx gnu_dirs boost')
Yingdi Yuce841ca2013-12-14 08:28:00 +080022 conf.load('ndn_cpp')
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070023
Zhenkai Zhu699d7402012-05-29 16:47:39 -070024 if conf.options.debug:
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070025 conf.define ('_DEBUG', 1)
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070026 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 Afanasyeva0c8a1d2012-04-05 13:55:42 -070034 else:
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070035 conf.add_supported_cxxflags (cxxflags = ['-O3', '-g'])
36
Yingdi Yu43e71612013-10-30 22:19:31 -070037 # conf.check_ndnx ()
38
Yingdi Yuce841ca2013-12-14 08:28:00 +080039 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 Yu43e71612013-10-30 22:19:31 -070042 conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True)
43 # conf.check_openssl ()
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070044
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 Afanasyev0ad7c212012-04-05 13:31:14 -070049
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070050 if conf.options._test:
51 conf.define('_TEST', 1)
52
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080053 try:
54 conf.load('doxygen')
55 except:
56 pass
57
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070058 conf.load('protoc')
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070059
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080060def build (bld):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070061 libsync = bld (
Alexander Afanasyevf46eac52013-07-26 11:27:39 -070062 target="ChronoSync",
Yingdi Yuce841ca2013-12-14 08:28:00 +080063 # vnum = "1.0.0",
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070064 features=['cxx', 'cxxshlib'],
Alexander Afanasyevce001692013-07-14 11:34:41 -070065 source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']),
Yingdi Yuce841ca2013-12-14 08:28:00 +080066 use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNCPP NDN-CPP-ET OPENSSL',
Alexander Afanasyevce001692013-07-14 11:34:41 -070067 includes = ['src'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070068 )
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070069
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 Afanasyevf46eac52013-07-26 11:27:39 -070076 use = 'BOOST_TEST ChronoSync',
Alexander Afanasyevce001692013-07-14 11:34:41 -070077 includes = ['src'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070078 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070079
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070080 if bld.get_define ("HAVE_LOG4CXX"):
81 libsync.use += ' LOG4CXX'
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070082 if bld.get_define("_TEST"):
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070083 unittests.use += ' LOG4CXX'
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070084
Alexander Afanasyevce001692013-07-14 11:34:41 -070085 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 Afanasyeve76f2632012-03-05 00:18:42 -080098
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -070099 pc = bld (
100 features = "subst",
Alexander Afanasyev7804c232013-07-14 12:15:41 -0700101 source='ChronoSync.pc.in',
102 target='ChronoSync.pc',
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700103 install_path = '${LIBDIR}/pkgconfig',
104 PREFIX = bld.env['PREFIX'],
Alexander Afanasyevce001692013-07-14 11:34:41 -0700105 INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700106 VERSION = VERSION,
107 )
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700108
Alexander Afanasyev150f14d2012-03-05 21:24:49 -0800109# doxygen docs
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800110from waflib.Build import BuildContext
111class doxy (BuildContext):
112 cmd = "doxygen"
113 fun = "doxygen"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800114
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800115def doxygen (bld):
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800116 if not bld.env.DOXYGEN:
117 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800118 bld (features="doxygen",
119 doxyfile='doc/doxygen.conf',
120 output_dir = 'doc')
Alexander Afanasyev6133f9a2013-07-14 10:58:26 -0700121
122@Configure.conf
123def 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