Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 3 | VERSION='0.1' |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 4 | APPNAME='chronoshare' |
| 5 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 6 | from waflib import Build, Logs, Utils |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 7 | |
| 8 | def options(opt): |
| 9 | opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''') |
| 10 | opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''') |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 11 | opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 12 | opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''') |
Alexander Afanasyev | 5f9d09e | 2012-12-28 19:43:08 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 14 | opt.load('compiler_c compiler_cxx boost ccnx protoc qt4') |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 15 | |
| 16 | def configure(conf): |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 17 | conf.load("compiler_c compiler_cxx") |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 19 | conf.define ("CHRONOSHARE_VERSION", VERSION) |
| 20 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 21 | conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True) |
Zhenkai Zhu | bc2f628 | 2013-01-08 16:40:58 -0800 | [diff] [blame] | 22 | conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True) |
| 23 | conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True) |
| 24 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 25 | if Utils.unversioned_sys_platform () == "darwin": |
| 26 | conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', cxxflags="-ObjC++", mandatory=False) |
| 27 | conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', cxxflags="-ObjC++", define_name='HAVE_COREWLAN', mandatory=False) |
| 28 | |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 29 | if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False): |
Alexander Afanasyev | 5f9d09e | 2012-12-28 19:43:08 -0800 | [diff] [blame] | 30 | libcrypto = conf.check_cc(lib='crypto', |
| 31 | header_name='openssl/crypto.h', |
| 32 | define_name='HAVE_SSL', |
| 33 | uselib_store='SSL') |
| 34 | else: |
| 35 | conf.define ("HAVE_SSL", 1) |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 36 | if not conf.get_define ("HAVE_SSL"): |
| 37 | conf.fatal ("Cannot find SSL libraries") |
| 38 | |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 39 | if conf.options.log4cxx: |
| 40 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True) |
| 41 | conf.define ("HAVE_LOG4CXX", 1) |
| 42 | |
Zhenkai Zhu | 0a17aea | 2012-12-28 14:30:22 -0800 | [diff] [blame] | 43 | conf.load ('ccnx') |
Alexander Afanasyev | 3320698 | 2013-01-09 16:29:29 -0800 | [diff] [blame] | 44 | |
| 45 | conf.load('protoc') |
Alexander Afanasyev | 3320698 | 2013-01-09 16:29:29 -0800 | [diff] [blame] | 46 | |
| 47 | conf.load('qt4') |
| 48 | |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 49 | conf.load('boost') |
| 50 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 51 | conf.check_boost(lib='system test iostreams filesystem regex thread') |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 53 | boost_version = conf.env.BOOST_VERSION.split('_') |
| 54 | if int(boost_version[0]) < 1 or int(boost_version[1]) < 46: |
| 55 | Logs.error ("Minumum required boost version is 1.46") |
| 56 | return |
| 57 | |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 58 | conf.check_ccnx (path=conf.options.ccnx_dir) |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 59 | conf.define ('CCNX_PATH', conf.env.CCNX_ROOT) |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 60 | |
| 61 | if conf.options.debug: |
| 62 | conf.define ('_DEBUG', 1) |
Alexander Afanasyev | d724581 | 2013-02-13 21:06:57 -0800 | [diff] [blame] | 63 | conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3']) |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 64 | else: |
Alexander Afanasyev | d724581 | 2013-02-13 21:06:57 -0800 | [diff] [blame] | 65 | conf.env.append_value('CXXFLAGS', ['-O3', '-g']) |
| 66 | |
| 67 | if conf.env["CXX"] == ["clang++"]: |
| 68 | conf.env.append_value('CXXFLAGS', ['-fcolor-diagnostics', '-Qunused-arguments']) |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 69 | |
| 70 | if conf.options._test: |
Alexander Afanasyev | 9e5a470 | 2013-01-24 13:15:23 -0800 | [diff] [blame] | 71 | conf.define ('_TESTS', 1) |
Alexander Afanasyev | 72ac219 | 2013-01-03 19:33:43 -0800 | [diff] [blame] | 72 | conf.env.TEST = 1 |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 74 | conf.write_config_header('src/config.h') |
| 75 | |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 76 | def build (bld): |
Zhenkai Zhu | e840942 | 2013-01-28 12:52:17 -0800 | [diff] [blame] | 77 | executor = bld.objects ( |
| 78 | target = "executor", |
| 79 | features = ["cxx"], |
| 80 | source = bld.path.ant_glob(['executor/**/*.cc']), |
| 81 | use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX', |
| 82 | includes = "executor src", |
| 83 | ) |
| 84 | |
Alexander Afanasyev | 3f101ec | 2013-01-17 16:58:03 -0800 | [diff] [blame] | 85 | scheduler = bld.objects ( |
| 86 | target = "scheduler", |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 87 | features = ["cxx"], |
Alexander Afanasyev | 3f101ec | 2013-01-17 16:58:03 -0800 | [diff] [blame] | 88 | source = bld.path.ant_glob(['scheduler/**/*.cc']), |
Zhenkai Zhu | e840942 | 2013-01-28 12:52:17 -0800 | [diff] [blame] | 89 | use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor', |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 90 | includes = "scheduler executor src", |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 91 | ) |
| 92 | |
Zhenkai Zhu | a7e3da7 | 2012-12-27 13:45:00 -0800 | [diff] [blame] | 93 | libccnx = bld ( |
Alexander Afanasyev | 3f101ec | 2013-01-17 16:58:03 -0800 | [diff] [blame] | 94 | target="ccnx", |
| 95 | features=['cxx'], |
| 96 | source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']), |
Zhenkai Zhu | e840942 | 2013-01-28 12:52:17 -0800 | [diff] [blame] | 97 | use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor', |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 98 | includes = "ccnx src scheduler executor", |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 99 | ) |
| 100 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 101 | adhoc = bld ( |
| 102 | target = "adhoc", |
| 103 | features=['cxx'], |
| 104 | includes = "ccnx src", |
| 105 | ) |
| 106 | if Utils.unversioned_sys_platform () == "darwin": |
| 107 | adhoc.mac_app = True |
| 108 | adhoc.source = 'adhoc/adhoc-osx.mm' |
Alexander Afanasyev | e33846d | 2013-02-25 15:26:08 -0800 | [diff] [blame^] | 109 | adhoc.use = "LOG4CXX OSX_FOUNDATION OSX_COREWLAN" |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 110 | |
Alexander Afanasyev | 3f101ec | 2013-01-17 16:58:03 -0800 | [diff] [blame] | 111 | chornoshare = bld ( |
| 112 | target="chronoshare", |
| 113 | features=['cxx'], |
| 114 | source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']), |
Alexander Afanasyev | c507ac2 | 2013-01-21 16:01:58 -0800 | [diff] [blame] | 115 | use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx", |
Zhenkai Zhu | 1888f74 | 2013-01-28 12:47:33 -0800 | [diff] [blame] | 116 | includes = "ccnx scheduler src executor", |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 117 | ) |
Alexander Afanasyev | b2fe74e | 2013-01-20 16:06:43 -0800 | [diff] [blame] | 118 | |
Zhenkai Zhu | 369eff1 | 2013-02-05 15:43:49 -0800 | [diff] [blame] | 119 | fs_watcher = bld ( |
| 120 | target = "fs_watcher", |
| 121 | features = "qt4 cxx", |
| 122 | defines = "WAF", |
| 123 | source = bld.path.ant_glob(['fs-watcher/*.cc']), |
| 124 | use = "SQLITE3 LOG4CXX scheduler executor QTCORE", |
| 125 | includes = "fs-watcher scheduler executor src", |
| 126 | ) |
| 127 | |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 128 | # Unit tests |
| 129 | if bld.env['TEST']: |
| 130 | unittests = bld.program ( |
| 131 | target="unit-tests", |
Zhenkai Zhu | d175627 | 2013-02-01 17:02:18 -0800 | [diff] [blame] | 132 | features = "qt4 cxx cxxprogram", |
| 133 | defines = "WAF", |
Zhenkai Zhu | 369eff1 | 2013-02-05 15:43:49 -0800 | [diff] [blame] | 134 | source = bld.path.ant_glob(['test/*.cc']), |
| 135 | use = 'BOOST_TEST BOOST_FILESYSTEM LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare', |
| 136 | includes = "ccnx scheduler src executor gui fs-watcher", |
Alexander Afanasyev | 4f62f44 | 2013-02-07 22:36:08 -0800 | [diff] [blame] | 137 | install_prefix = None, |
Alexander Afanasyev | ee7e613 | 2013-01-03 20:03:14 -0800 | [diff] [blame] | 138 | ) |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 139 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 140 | qt = bld ( |
| 141 | target = "ChronoShare", |
| 142 | features = "qt4 cxx cxxprogram", |
| 143 | defines = "WAF", |
| 144 | source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/*.qrc']), |
Alexander Afanasyev | 85a4ba0 | 2013-02-24 16:30:17 -0800 | [diff] [blame] | 145 | includes = "ccnx scheduler executor fs-watcher gui src adhoc . ", |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 146 | use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare" |
| 147 | ) |
| 148 | |
| 149 | if Utils.unversioned_sys_platform () == "darwin": |
| 150 | app_plist = '''<?xml version="1.0" encoding="UTF-8"?> |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 151 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> |
| 152 | <plist version="0.9"> |
| 153 | <dict> |
| 154 | <key>CFBundlePackageType</key> |
| 155 | <string>APPL</string> |
| 156 | <key>CFBundleGetInfoString</key> |
| 157 | <string>Created by Waf</string> |
| 158 | <key>CFBundleSignature</key> |
| 159 | <string>????</string> |
| 160 | <key>NOTE</key> |
| 161 | <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string> |
| 162 | <key>CFBundleExecutable</key> |
| 163 | <string>%s</string> |
| 164 | <key>LSUIElement</key> |
| 165 | <string>1</string> |
| 166 | </dict> |
| 167 | </plist>''' |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 168 | qt.mac_app = "ChronoShare.app" |
| 169 | qt.mac_plist = app_plist % "ChronoShare" |
| 170 | qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc" |
| 171 | # qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc" |
Alexander Afanasyev | 83a5300 | 2013-01-24 11:12:01 -0800 | [diff] [blame] | 172 | |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 173 | |
| 174 | cmdline = bld ( |
| 175 | target = "csd", |
| 176 | features = "qt4 cxx cxxprogram", |
| 177 | defines = "WAF", |
Zhenkai Zhu | 369eff1 | 2013-02-05 15:43:49 -0800 | [diff] [blame] | 178 | source = "cmd/csd.cc", |
| 179 | includes = "ccnx scheduler executor gui fs-watcher src . ", |
| 180 | use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare" |
Alexander Afanasyev | 548d38d | 2013-01-26 16:36:06 -0800 | [diff] [blame] | 181 | ) |
| 182 | |
Alexander Afanasyev | eb575e0 | 2013-01-26 17:14:51 -0800 | [diff] [blame] | 183 | dump_db = bld ( |
| 184 | target = "dump-db", |
| 185 | features = "cxx cxxprogram", |
| 186 | source = "cmd/dump-db.cc", |
Zhenkai Zhu | 369eff1 | 2013-02-05 15:43:49 -0800 | [diff] [blame] | 187 | includes = "ccnx scheduler executor gui fs-watcher src . ", |
| 188 | use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare" |
Alexander Afanasyev | eb575e0 | 2013-01-26 17:14:51 -0800 | [diff] [blame] | 189 | ) |
| 190 | |
Alexander Afanasyev | a98e69c | 2013-02-24 15:42:45 -0800 | [diff] [blame] | 191 | from waflib import TaskGen |
| 192 | @TaskGen.extension('.mm') |
| 193 | def m_hook(self, node): |
| 194 | """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing.""" |
| 195 | return self.create_compiled_task('cxx', node) |