blob: 11c7b34228bca9194af322882671cc193d5ff2de [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 Afanasyevf2890632013-01-02 13:40:02 -080021 conf.define ("CHRONOSHARE_VERSION", VERSION)
22
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080023 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080024 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
25 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
26
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080027 if Utils.unversioned_sys_platform () == "darwin":
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080028 conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', mandatory=False, compile_filename='test.mm')
29 conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', define_name='HAVE_COREWLAN', mandatory=False, compile_filename='test.mm')
30
31 if conf.options.autoupdate:
Zhenkai Zhubb170d42013-02-25 13:48:59 -080032 def check_sparkle(**kwargs):
33 conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
34 uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
35 compile_filename='test.mm',
36 **kwargs
37 )
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080038 try:
39 # Try standard paths first
Zhenkai Zhubb170d42013-02-25 13:48:59 -080040 check_sparkle()
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080041 except:
42 try:
43 # Try local path
44 Logs.info ("Check local version of Sparkle framework")
Zhenkai Zhubb170d42013-02-25 13:48:59 -080045 check_sparkle(cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
46 linkflags="-F%s/build/Sparkle" % conf.path.abspath())
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080047 except:
48 # Download to local path and retry
49 Logs.info ("Sparkle framework not found, trying to download it to 'build/'")
50
51 import urllib, subprocess, os
52 urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip")
Zhenkai Zhubb170d42013-02-25 13:48:59 -080053 if os.path.exists('build/Sparkle.zip'):
54 try:
55 subprocess.check_call (['unzip', '-qq', 'build/Sparkle.zip', '-d', 'build/Sparkle'])
56 os.remove ("build/Sparkle.zip")
57 check_sparkle(cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
58 linkflags="-F%s/build/Sparkle" % conf.path.abspath())
59 except subprocess.CalledProcessError as e:
60 conf.fatal("Cannot find Sparkle framework. Auto download failed: '%s' returned %s" % (' '.join(e.cmd), e.returncode))
61 except:
62 conf.fatal("Unknown Error happened when auto downloading Sparkle framework")
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080063
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080064 if conf.is_defined('HAVE_SPARKLE'):
65 conf.env.HAVE_SPARKLE = 1 # small cheat for wscript
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080066
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080067 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080068 libcrypto = conf.check_cc(lib='crypto',
69 header_name='openssl/crypto.h',
70 define_name='HAVE_SSL',
71 uselib_store='SSL')
72 else:
73 conf.define ("HAVE_SSL", 1)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080074 if not conf.get_define ("HAVE_SSL"):
75 conf.fatal ("Cannot find SSL libraries")
76
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080077 if conf.options.log4cxx:
78 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
79 conf.define ("HAVE_LOG4CXX", 1)
80
Zhenkai Zhu0a17aea2012-12-28 14:30:22 -080081 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -080082
83 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -080084
85 conf.load('qt4')
86
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080087 conf.load('boost')
88
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080089 conf.check_boost(lib='system test iostreams filesystem regex thread')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080090
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080091 boost_version = conf.env.BOOST_VERSION.split('_')
92 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
93 Logs.error ("Minumum required boost version is 1.46")
94 return
95
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080096 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080097 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080098
99 if conf.options.debug:
100 conf.define ('_DEBUG', 1)
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800101 conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800102 else:
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800103 conf.env.append_value('CXXFLAGS', ['-O3', '-g'])
104
105 if conf.env["CXX"] == ["clang++"]:
106 conf.env.append_value('CXXFLAGS', ['-fcolor-diagnostics', '-Qunused-arguments'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800107
108 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800109 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -0800110 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800111
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800112 conf.write_config_header('src/config.h')
113
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800114def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -0800115 executor = bld.objects (
116 target = "executor",
117 features = ["cxx"],
118 source = bld.path.ant_glob(['executor/**/*.cc']),
119 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
120 includes = "executor src",
121 )
122
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800123 scheduler = bld.objects (
124 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800125 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800126 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800127 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800128 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800129 )
130
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800131 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800132 target="ccnx",
133 features=['cxx'],
134 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800135 use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800136 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800137 )
138
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800139 adhoc = bld (
140 target = "adhoc",
141 features=['cxx'],
142 includes = "ccnx src",
143 )
144 if Utils.unversioned_sys_platform () == "darwin":
145 adhoc.mac_app = True
146 adhoc.source = 'adhoc/adhoc-osx.mm'
147 adhoc.use = "OSX_FOUNDATION OSX_COREWLAN"
148
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800149 chornoshare = bld (
150 target="chronoshare",
151 features=['cxx'],
152 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800153 use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800154 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800155 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800156
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800157 fs_watcher = bld (
158 target = "fs_watcher",
159 features = "qt4 cxx",
160 defines = "WAF",
161 source = bld.path.ant_glob(['fs-watcher/*.cc']),
162 use = "SQLITE3 LOG4CXX scheduler executor QTCORE",
163 includes = "fs-watcher scheduler executor src",
164 )
165
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800166 # Unit tests
167 if bld.env['TEST']:
168 unittests = bld.program (
169 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800170 features = "qt4 cxx cxxprogram",
171 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800172 source = bld.path.ant_glob(['test/*.cc']),
173 use = 'BOOST_TEST BOOST_FILESYSTEM LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare',
174 includes = "ccnx scheduler src executor gui fs-watcher",
Alexander Afanasyev4f62f442013-02-07 22:36:08 -0800175 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800176 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800177
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800178 qt = bld (
179 target = "ChronoShare",
180 features = "qt4 cxx cxxprogram",
181 defines = "WAF",
182 source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/*.qrc']),
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800183 includes = "ccnx scheduler executor fs-watcher gui src adhoc . ",
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800184 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
185 )
186
187 if Utils.unversioned_sys_platform () == "darwin":
188 app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800189<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
190<plist version="0.9">
191<dict>
192 <key>CFBundlePackageType</key>
193 <string>APPL</string>
194 <key>CFBundleGetInfoString</key>
195 <string>Created by Waf</string>
196 <key>CFBundleSignature</key>
197 <string>????</string>
198 <key>NOTE</key>
199 <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
200 <key>CFBundleExecutable</key>
201 <string>%s</string>
202 <key>LSUIElement</key>
203 <string>1</string>
204</dict>
205</plist>'''
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800206 qt.mac_app = "ChronoShare.app"
207 qt.mac_plist = app_plist % "ChronoShare"
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800208 qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800209
Alexander Afanasyev5a95a252013-02-25 12:55:48 -0800210 if bld.env['HAVE_SPARKLE']:
211 qt.use += " OSX_SPARKLE"
212 qt.source += ["osx/auto-update/sparkle-auto-update.mm"]
213 qt.includes += " osx/auto-update"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800214
215 cmdline = bld (
216 target = "csd",
217 features = "qt4 cxx cxxprogram",
218 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800219 source = "cmd/csd.cc",
220 includes = "ccnx scheduler executor gui fs-watcher src . ",
221 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800222 )
223
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800224 dump_db = bld (
225 target = "dump-db",
226 features = "cxx cxxprogram",
227 source = "cmd/dump-db.cc",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800228 includes = "ccnx scheduler executor gui fs-watcher src . ",
229 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE LOG4CXX fs_watcher ccnx database chronoshare"
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800230 )
231
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800232from waflib import TaskGen
233@TaskGen.extension('.mm')
234def m_hook(self, node):
235 """Alias .mm files to be compiled the same as .cc files, gcc/clang will do the right thing."""
236 return self.create_compiled_task('cxx', node)