blob: 8a0bede9bde692a7623f16b29f0ddd0d3172b6d9 [file] [log] [blame]
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08003VERSION='0.1'
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08004APPNAME='chronoshare'
5
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -08006from waflib import Build, Logs, Utils
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08007
8def 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 Afanasyev71b43e72012-12-27 01:03:43 -080011 opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080012 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080013
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080014 opt.load('compiler_c compiler_cxx boost ccnx protoc qt4')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080015
16def configure(conf):
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080017 conf.load("compiler_c compiler_cxx")
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080018
Alexander Afanasyevf2890632013-01-02 13:40:02 -080019 conf.define ("CHRONOSHARE_VERSION", VERSION)
20
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080021 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080022 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 Afanasyeva98e69c2013-02-24 15:42:45 -080025 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 Zhua7e3da72012-12-27 13:45:00 -080029 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080030 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 Zhua7e3da72012-12-27 13:45:00 -080036 if not conf.get_define ("HAVE_SSL"):
37 conf.fatal ("Cannot find SSL libraries")
38
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080039 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 Zhu0a17aea2012-12-28 14:30:22 -080043 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -080044
45 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -080046
47 conf.load('qt4')
48
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080049 conf.load('boost')
50
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080051 conf.check_boost(lib='system test iostreams filesystem regex thread')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080052
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080053 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 Zhua7e3da72012-12-27 13:45:00 -080058 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080059 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080060
61 if conf.options.debug:
62 conf.define ('_DEBUG', 1)
Alexander Afanasyevd7245812013-02-13 21:06:57 -080063 conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080064 else:
Alexander Afanasyevd7245812013-02-13 21:06:57 -080065 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 Zhua7e3da72012-12-27 13:45:00 -080069
70 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -080071 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -080072 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080073
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080074 conf.write_config_header('src/config.h')
75
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080076def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -080077 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 Afanasyev3f101ec2013-01-17 16:58:03 -080085 scheduler = bld.objects (
86 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080087 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -080088 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -080089 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -080090 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080091 )
92
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080093 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -080094 target="ccnx",
95 features=['cxx'],
96 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhue8409422013-01-28 12:52:17 -080097 use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -080098 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -080099 )
100
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800101 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'
109 adhoc.use = "OSX_FOUNDATION OSX_COREWLAN"
110
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800111 chornoshare = bld (
112 target="chronoshare",
113 features=['cxx'],
114 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800115 use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800116 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800117 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800118
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800119 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 Afanasyevee7e6132013-01-03 20:03:14 -0800128 # Unit tests
129 if bld.env['TEST']:
130 unittests = bld.program (
131 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800132 features = "qt4 cxx cxxprogram",
133 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800134 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 Afanasyev4f62f442013-02-07 22:36:08 -0800137 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800138 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800139
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800140 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']),
145 includes = "ccnx scheduler executor fs-watcher gui src . ",
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 Afanasyev83a53002013-01-24 11:12:01 -0800151<!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 Afanasyeva98e69c2013-02-24 15:42:45 -0800168 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 Afanasyev83a53002013-01-24 11:12:01 -0800172
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800173
174 cmdline = bld (
175 target = "csd",
176 features = "qt4 cxx cxxprogram",
177 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800178 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 Afanasyev548d38d2013-01-26 16:36:06 -0800181 )
182
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800183 dump_db = bld (
184 target = "dump-db",
185 features = "cxx cxxprogram",
186 source = "cmd/dump-db.cc",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800187 includes = "ccnx scheduler executor gui fs-watcher src . ",
188 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800189 )
190
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800191from waflib import TaskGen
192@TaskGen.extension('.mm')
193def 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)