blob: 151271a83328087a4a3f2988977aab6f377461e5 [file] [log] [blame]
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -08002import os
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08003
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08004VERSION='0.1'
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08005APPNAME='chronoshare'
6
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -08007from waflib import Build, Logs, Utils
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08008
9def options(opt):
10 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
11 opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080012 opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080013 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080014
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080015 if Utils.unversioned_sys_platform () == "darwin":
16 opt.add_option('--autoupdate', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''')
17
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080018 opt.load('compiler_c compiler_cxx boost ccnx protoc qt4')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080019
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080020def check_framework(conf, name, **kwargs):
21 frameworkLocations = (os.environ.get('HOME') + '/Library/Frameworks'
22 , '/opt/local/Library/Frameworks'
23 , '/Library/Frameworks'
24 , '/Network/Library/Frameworks'
25 , '/System/Library/Frameworks'
26 )
27 uselib = name.upper()
28 frameworkName = name + ".framework"
29 found = False
30 for frameworkLocation in frameworkLocations:
31 dynamicLib = os.path.join(frameworkLocation, frameworkName, name)
32 if os.path.exists(dynamicLib):
33 conf.env.append_unique('FRAMEWORK_' + uselib, name)
34 conf.msg('Checking for %s' % name, dynamicLib, 'GREEN')
35 conf.env.append_unique('INCLUDES_' + uselib, os.path.join(frameworkLocation, frameworkName, 'Headers'))
36 found = True
37 define_name = kwargs.get('define_name', None)
38 if define_name is not None:
39 conf.define(define_name, 1)
40 break
41
42 if not found:
43 mandatory = kwargs.get('mandatory', True)
44 if mandatory:
45 conf.fatal('Cannot find ' + frameworkName)
46 else:
47 conf.msg('Checking for %s' % name, False, 'YELLOW')
48
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080049def configure(conf):
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080050 conf.load("compiler_c compiler_cxx")
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080051
Alexander Afanasyevf2890632013-01-02 13:40:02 -080052 conf.define ("CHRONOSHARE_VERSION", VERSION)
53
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080054 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080055 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
56 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
57
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080058 if Utils.unversioned_sys_platform () == "darwin":
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080059 conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=False, compile_filename='test.mm')
60 conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', define_name='HAVE_COREWLAN', mandatory=False, compile_filename='test.mm')
61
62 if conf.options.autoupdate:
63 try:
64 # Try standard paths first
65 conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
66 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True, compile_filename='test.mm')
67 except:
68 try:
69 # Try local path
70 Logs.info ("Check local version of Sparkle framework")
71 conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
72 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
73 cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
74 linkflags="-F%s/build/Sparkle" % conf.path.abspath(), compile_filename='test.mm')
75 except:
76 # Download to local path and retry
77 Logs.info ("Sparkle framework not found, trying to download it to 'build/'")
78
79 import urllib, subprocess, os
80 urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip")
81 subprocess.call ("unzip build/Sparkle.zip -d build/Sparkle", shell=True)
82 os.remove ("build/Sparkle.zip")
83
84 conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
85 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
86 cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
87 linkflags="-F%s/build/Sparkle" % conf.path.abspath(), compile_filename='test.mm')
88 if conf.is_defined('HAVE_SPARKLE'):
89 conf.env.HAVE_SPARKLE = 1 # small cheat for wscript
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080090
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080091 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080092 libcrypto = conf.check_cc(lib='crypto',
93 header_name='openssl/crypto.h',
94 define_name='HAVE_SSL',
95 uselib_store='SSL')
96 else:
97 conf.define ("HAVE_SSL", 1)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080098 if not conf.get_define ("HAVE_SSL"):
99 conf.fatal ("Cannot find SSL libraries")
100
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800101 if conf.options.log4cxx:
102 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
103 conf.define ("HAVE_LOG4CXX", 1)
104
Zhenkai Zhu0a17aea2012-12-28 14:30:22 -0800105 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800106
107 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800108
109 conf.load('qt4')
110
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800111 conf.load('boost')
112
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800113 conf.check_boost(lib='system test iostreams filesystem regex thread')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800114
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800115 boost_version = conf.env.BOOST_VERSION.split('_')
116 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
117 Logs.error ("Minumum required boost version is 1.46")
118 return
119
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800120 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800121 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800122
123 if conf.options.debug:
124 conf.define ('_DEBUG', 1)
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800125 conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800126 else:
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800127 conf.env.append_value('CXXFLAGS', ['-O3', '-g'])
128
129 if conf.env["CXX"] == ["clang++"]:
130 conf.env.append_value('CXXFLAGS', ['-fcolor-diagnostics', '-Qunused-arguments'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800131
132 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800133 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -0800134 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800135
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800136 conf.write_config_header('src/config.h')
137
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800138def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -0800139 executor = bld.objects (
140 target = "executor",
141 features = ["cxx"],
142 source = bld.path.ant_glob(['executor/**/*.cc']),
143 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
144 includes = "executor src",
145 )
146
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800147 scheduler = bld.objects (
148 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800149 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800150 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800151 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800152 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800153 )
154
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800155 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800156 target="ccnx",
157 features=['cxx'],
158 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800159 use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800160 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800161 )
162
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800163 adhoc = bld (
164 target = "adhoc",
165 features=['cxx'],
166 includes = "ccnx src",
167 )
168 if Utils.unversioned_sys_platform () == "darwin":
169 adhoc.mac_app = True
170 adhoc.source = 'adhoc/adhoc-osx.mm'
171 adhoc.use = "OSX_FOUNDATION OSX_COREWLAN"
172
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800173 chornoshare = bld (
174 target="chronoshare",
175 features=['cxx'],
176 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800177 use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800178 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800179 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800180
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800181 fs_watcher = bld (
182 target = "fs_watcher",
183 features = "qt4 cxx",
184 defines = "WAF",
185 source = bld.path.ant_glob(['fs-watcher/*.cc']),
186 use = "SQLITE3 LOG4CXX scheduler executor QTCORE",
187 includes = "fs-watcher scheduler executor src",
188 )
189
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800190 # Unit tests
191 if bld.env['TEST']:
192 unittests = bld.program (
193 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800194 features = "qt4 cxx cxxprogram",
195 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800196 source = bld.path.ant_glob(['test/*.cc']),
197 use = 'BOOST_TEST BOOST_FILESYSTEM LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare',
198 includes = "ccnx scheduler src executor gui fs-watcher",
Alexander Afanasyev4f62f442013-02-07 22:36:08 -0800199 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800200 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800201
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800202 qt = bld (
203 target = "ChronoShare",
204 features = "qt4 cxx cxxprogram",
205 defines = "WAF",
206 source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/*.qrc']),
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800207 includes = "ccnx scheduler executor fs-watcher gui src adhoc . ",
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800208 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
209 )
210
211 if Utils.unversioned_sys_platform () == "darwin":
212 app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800213<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
214<plist version="0.9">
215<dict>
216 <key>CFBundlePackageType</key>
217 <string>APPL</string>
218 <key>CFBundleGetInfoString</key>
219 <string>Created by Waf</string>
220 <key>CFBundleSignature</key>
221 <string>????</string>
222 <key>NOTE</key>
223 <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
224 <key>CFBundleExecutable</key>
225 <string>%s</string>
226 <key>LSUIElement</key>
227 <string>1</string>
228</dict>
229</plist>'''
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800230 qt.mac_app = "ChronoShare.app"
231 qt.mac_plist = app_plist % "ChronoShare"
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800232 qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800233
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800234 if bld.env['HAVE_SPARKLE']:
235 qt.use += " OSX_SPARKLE"
236 qt.source += ["osx/auto-update/sparkle-auto-update.mm"]
237 qt.includes += " osx/auto-update"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800238
239 cmdline = bld (
240 target = "csd",
241 features = "qt4 cxx cxxprogram",
242 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800243 source = "cmd/csd.cc",
244 includes = "ccnx scheduler executor gui fs-watcher src . ",
245 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800246 )
247
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800248 dump_db = bld (
249 target = "dump-db",
250 features = "cxx cxxprogram",
251 source = "cmd/dump-db.cc",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800252 includes = "ccnx scheduler executor gui fs-watcher src . ",
253 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800254 )
255
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800256from waflib import TaskGen
257@TaskGen.extension('.mm')
258def m_hook(self, node):
259 """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
260 return self.create_compiled_task('cxx', node)