blob: a20b70ca0fac5b7744d8375c96684e08e7b5914a [file] [log] [blame]
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08002VERSION='0.1'
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08003APPNAME='chronoshare'
4
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -08005from waflib import Build, Logs, Utils
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08006
7def options(opt):
8 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
9 opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080010 opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080011 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080012
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080013 if Utils.unversioned_sys_platform () == "darwin":
Zhenkai Zhubb170d42013-02-25 13:48:59 -080014 opt.add_option('--auto-update', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''')
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080015
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080016 opt.load('compiler_c compiler_cxx boost ccnx protoc qt4')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080017
18def configure(conf):
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080019 conf.load("compiler_c compiler_cxx")
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080020
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080021 # I wish I could use it, but there is some weirdness with boost tests. Give up for now
22 # try:
23 # conf.check(features='cxx cxxprogram', cxxflags="-std=c++11")
24 # conf.env.append_value ('CXXFLAGS', ["-std=c++11"])
25 # except:
26 # try:
27 # conf.check(features='cxx cxxprogram', cxxflags="-std=c++0x")
28 # conf.env.append_value ('CXXFLAGS', ["-std=c++0x"])
29 # except:
30 # conf.fatal ("You compiler doesn't support C++11. You can try GCC >= 4.4 or recent version of Clang.")
31
Alexander Afanasyevf2890632013-01-02 13:40:02 -080032 conf.define ("CHRONOSHARE_VERSION", VERSION)
33
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080034 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080035 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
36 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
37
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080038 if Utils.unversioned_sys_platform () == "darwin":
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080039 conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=False, compile_filename='test.mm')
40 conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', define_name='HAVE_COREWLAN', mandatory=False, compile_filename='test.mm')
41
42 if conf.options.autoupdate:
Zhenkai Zhubb170d42013-02-25 13:48:59 -080043 def check_sparkle(**kwargs):
44 conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
45 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
46 compile_filename='test.mm',
47 **kwargs
48 )
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080049 try:
50 # Try standard paths first
Zhenkai Zhubb170d42013-02-25 13:48:59 -080051 check_sparkle()
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080052 except:
53 try:
54 # Try local path
55 Logs.info ("Check local version of Sparkle framework")
Alexander Afanasyev7c85d572013-02-26 22:06:54 -080056 check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(),
57 linkflags="-F%s/osx/Frameworks/" % conf.path.abspath())
58 conf.env.HAVE_LOCAL_SPARKLE = 1
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080059 except:
60 # Download to local path and retry
61 Logs.info ("Sparkle framework not found, trying to download it to 'build/'")
62
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080063 import urllib, subprocess, os, shutil
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080064 urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip")
Zhenkai Zhubb170d42013-02-25 13:48:59 -080065 if os.path.exists('build/Sparkle.zip'):
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080066 try:
67 subprocess.check_call (['unzip', '-qq', 'build/Sparkle.zip', '-d', 'build/Sparkle'])
68 os.remove ("build/Sparkle.zip")
69 if not os.path.exists("osx/Frameworks"):
70 os.mkdir ("osx/Frameworks")
71 os.rename ("build/Sparkle/Sparkle.framework", "osx/Frameworks/Sparkle.framework")
72 shutil.rmtree("build/Sparkle", ignore_errors=True)
73
Alexander Afanasyev7c85d572013-02-26 22:06:54 -080074 check_sparkle(cxxflags="-F%s/osx/Frameworks/" % conf.path.abspath(),
75 linkflags="-F%s/osx/Frameworks/" % conf.path.abspath())
76 conf.env.HAVE_LOCAL_SPARKLE = 1
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080077 except subprocess.CalledProcessError as e:
78 conf.fatal("Cannot find Sparkle framework. Auto download failed: '%s' returned %s" % (' '.join(e.cmd), e.returncode))
79 except:
80 conf.fatal("Unknown Error happened when auto downloading Sparkle framework")
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080081
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080082 if conf.is_defined('HAVE_SPARKLE'):
83 conf.env.HAVE_SPARKLE = 1 # small cheat for wscript
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080084
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080085 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080086 libcrypto = conf.check_cc(lib='crypto',
87 header_name='openssl/crypto.h',
88 define_name='HAVE_SSL',
89 uselib_store='SSL')
90 else:
91 conf.define ("HAVE_SSL", 1)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080092 if not conf.get_define ("HAVE_SSL"):
93 conf.fatal ("Cannot find SSL libraries")
94
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080095 if conf.options.log4cxx:
96 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
97 conf.define ("HAVE_LOG4CXX", 1)
98
Zhenkai Zhu0a17aea2012-12-28 14:30:22 -080099 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800100
101 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -0800102
103 conf.load('qt4')
104
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800105 conf.load('boost')
106
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800107 conf.check_boost(lib='system test iostreams filesystem regex thread')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800108
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800109 boost_version = conf.env.BOOST_VERSION.split('_')
110 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
111 Logs.error ("Minumum required boost version is 1.46")
112 return
113
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800114 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800115 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800116
117 if conf.options.debug:
118 conf.define ('_DEBUG', 1)
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800119 conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800120 else:
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800121 conf.env.append_value('CXXFLAGS', ['-O3', '-g'])
122
123 if conf.env["CXX"] == ["clang++"]:
124 conf.env.append_value('CXXFLAGS', ['-fcolor-diagnostics', '-Qunused-arguments'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800125
126 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800127 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -0800128 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800129
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800130 conf.write_config_header('src/config.h')
131
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800132def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -0800133 executor = bld.objects (
134 target = "executor",
135 features = ["cxx"],
136 source = bld.path.ant_glob(['executor/**/*.cc']),
137 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
138 includes = "executor src",
139 )
140
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800141 scheduler = bld.objects (
142 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800143 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800144 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800145 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800146 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800147 )
148
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800149 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800150 target="ccnx",
151 features=['cxx'],
152 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800153 use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800154 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800155 )
156
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800157 adhoc = bld (
158 target = "adhoc",
159 features=['cxx'],
160 includes = "ccnx src",
161 )
162 if Utils.unversioned_sys_platform () == "darwin":
163 adhoc.mac_app = True
164 adhoc.source = 'adhoc/adhoc-osx.mm'
Alexander Afanasyeve33846d2013-02-25 15:26:08 -0800165 adhoc.use = "LOG4CXX OSX_FOUNDATION OSX_COREWLAN"
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800166
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800167 chornoshare = bld (
168 target="chronoshare",
169 features=['cxx'],
170 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800171 use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800172 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800173 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800174
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800175 fs_watcher = bld (
176 target = "fs_watcher",
177 features = "qt4 cxx",
178 defines = "WAF",
179 source = bld.path.ant_glob(['fs-watcher/*.cc']),
180 use = "SQLITE3 LOG4CXX scheduler executor QTCORE",
181 includes = "fs-watcher scheduler executor src",
182 )
183
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800184 # Unit tests
185 if bld.env['TEST']:
186 unittests = bld.program (
187 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800188 features = "qt4 cxx cxxprogram",
189 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800190 source = bld.path.ant_glob(['test/*.cc']),
191 use = 'BOOST_TEST BOOST_FILESYSTEM LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare',
192 includes = "ccnx scheduler src executor gui fs-watcher",
Alexander Afanasyev4f62f442013-02-07 22:36:08 -0800193 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800194 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800195
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800196 http_server = bld (
197 target = "http_server",
Zhenkai Zhud9429222013-02-25 22:34:09 -0800198 features = "qt4 cxx",
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800199 source = bld.path.ant_glob(['server/*.cpp']),
Zhenkai Zhud9429222013-02-25 22:34:09 -0800200 includes = "server src .",
201 use = "BOOST QTCORE"
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800202 )
203
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800204 qt = bld (
205 target = "ChronoShare",
206 features = "qt4 cxx cxxprogram",
207 defines = "WAF",
Zhenkai Zhu33f8fbb2013-02-27 10:29:03 -0800208 source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/*.qrc']),
Zhenkai Zhud9429222013-02-25 22:34:09 -0800209 includes = "ccnx scheduler executor fs-watcher gui src adhoc server . ",
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800210 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare http_server"
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800211 )
212
213 if Utils.unversioned_sys_platform () == "darwin":
214 app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800215<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
216<plist version="0.9">
217<dict>
218 <key>CFBundlePackageType</key>
219 <string>APPL</string>
220 <key>CFBundleGetInfoString</key>
221 <string>Created by Waf</string>
222 <key>CFBundleSignature</key>
223 <string>????</string>
224 <key>NOTE</key>
225 <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
226 <key>CFBundleExecutable</key>
227 <string>%s</string>
228 <key>LSUIElement</key>
229 <string>1</string>
230</dict>
231</plist>'''
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800232 qt.mac_app = "ChronoShare.app"
233 qt.mac_plist = app_plist % "ChronoShare"
234 qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800235
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800236 if bld.env['HAVE_SPARKLE']:
237 qt.use += " OSX_SPARKLE"
238 qt.source += ["osx/auto-update/sparkle-auto-update.mm"]
239 qt.includes += " osx/auto-update"
Alexander Afanasyev7c85d572013-02-26 22:06:54 -0800240 if bld.env['HAVE_LOCAL_SPARKLE']:
241 qt.mac_frameworks = "osx/Frameworks/Sparkle.framework"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800242
243 cmdline = bld (
244 target = "csd",
245 features = "qt4 cxx cxxprogram",
246 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800247 source = "cmd/csd.cc",
248 includes = "ccnx scheduler executor gui fs-watcher src . ",
249 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800250 )
251
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800252 dump_db = bld (
253 target = "dump-db",
254 features = "cxx cxxprogram",
255 source = "cmd/dump-db.cc",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800256 includes = "ccnx scheduler executor gui fs-watcher src . ",
257 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800258 )
259
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800260from waflib import TaskGen
261@TaskGen.extension('.mm')
262def m_hook(self, node):
263 """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
264 return self.create_compiled_task('cxx', node)