blob: e8725b63f99510ce8e7e4566ca4bedcdca12b0c7 [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 Afanasyeva98e69c2013-02-24 15:42:45 -080015 opt.load('compiler_c compiler_cxx boost ccnx protoc qt4')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080016
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080017def check_framework(conf, name, **kwargs):
18 frameworkLocations = (os.environ.get('HOME') + '/Library/Frameworks'
19 , '/opt/local/Library/Frameworks'
20 , '/Library/Frameworks'
21 , '/Network/Library/Frameworks'
22 , '/System/Library/Frameworks'
23 )
24 uselib = name.upper()
25 frameworkName = name + ".framework"
26 found = False
27 for frameworkLocation in frameworkLocations:
28 dynamicLib = os.path.join(frameworkLocation, frameworkName, name)
29 if os.path.exists(dynamicLib):
30 conf.env.append_unique('FRAMEWORK_' + uselib, name)
31 conf.msg('Checking for %s' % name, dynamicLib, 'GREEN')
32 conf.env.append_unique('INCLUDES_' + uselib, os.path.join(frameworkLocation, frameworkName, 'Headers'))
33 found = True
34 define_name = kwargs.get('define_name', None)
35 if define_name is not None:
36 conf.define(define_name, 1)
37 break
38
39 if not found:
40 mandatory = kwargs.get('mandatory', True)
41 if mandatory:
42 conf.fatal('Cannot find ' + frameworkName)
43 else:
44 conf.msg('Checking for %s' % name, False, 'YELLOW')
45
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080046def configure(conf):
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080047 conf.load("compiler_c compiler_cxx")
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080048
Alexander Afanasyevf2890632013-01-02 13:40:02 -080049 conf.define ("CHRONOSHARE_VERSION", VERSION)
50
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080051 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080052 conf.check_cfg(package='libevent', args=['--cflags', '--libs'], uselib_store='LIBEVENT', mandatory=True)
53 conf.check_cfg(package='libevent_pthreads', args=['--cflags', '--libs'], uselib_store='LIBEVENT_PTHREADS', mandatory=True)
54
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080055 if Utils.unversioned_sys_platform () == "darwin":
56 conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION', cxxflags="-ObjC++", mandatory=False)
57 conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN', cxxflags="-ObjC++", define_name='HAVE_COREWLAN', mandatory=False)
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -080058 conf.check_cxx(framework_name='Sparkle', uselib_store='SPARKLE', cxxflags='-ObjC++', define_name='HAVE_SPARKLE', mandatory=False)
59 #check_framework(conf, 'Sparkle', define_name='HAVE_SPARKLE', mandatory=False)
60 if conf.get_define('HAVE_SPARKLE'):
61 conf.env.SPARKLE = True
62 else:
63 conf.env.SPARKLE = False
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080064
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080065 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
Alexander Afanasyev5f9d09e2012-12-28 19:43:08 -080066 libcrypto = conf.check_cc(lib='crypto',
67 header_name='openssl/crypto.h',
68 define_name='HAVE_SSL',
69 uselib_store='SSL')
70 else:
71 conf.define ("HAVE_SSL", 1)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080072 if not conf.get_define ("HAVE_SSL"):
73 conf.fatal ("Cannot find SSL libraries")
74
Alexander Afanasyevc507ac22013-01-21 16:01:58 -080075 if conf.options.log4cxx:
76 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
77 conf.define ("HAVE_LOG4CXX", 1)
78
Zhenkai Zhu0a17aea2012-12-28 14:30:22 -080079 conf.load ('ccnx')
Alexander Afanasyev33206982013-01-09 16:29:29 -080080
81 conf.load('protoc')
Alexander Afanasyev33206982013-01-09 16:29:29 -080082
83 conf.load('qt4')
84
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080085 conf.load('boost')
86
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080087 conf.check_boost(lib='system test iostreams filesystem regex thread')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080088
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080089 boost_version = conf.env.BOOST_VERSION.split('_')
90 if int(boost_version[0]) < 1 or int(boost_version[1]) < 46:
91 Logs.error ("Minumum required boost version is 1.46")
92 return
93
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080094 conf.check_ccnx (path=conf.options.ccnx_dir)
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080095 conf.define ('CCNX_PATH', conf.env.CCNX_ROOT)
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080096
97 if conf.options.debug:
98 conf.define ('_DEBUG', 1)
Alexander Afanasyevd7245812013-02-13 21:06:57 -080099 conf.env.append_value('CXXFLAGS', ['-O0', '-Wall', '-Wno-unused-variable', '-g3'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800100 else:
Alexander Afanasyevd7245812013-02-13 21:06:57 -0800101 conf.env.append_value('CXXFLAGS', ['-O3', '-g'])
102
103 if conf.env["CXX"] == ["clang++"]:
104 conf.env.append_value('CXXFLAGS', ['-fcolor-diagnostics', '-Qunused-arguments'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800105
106 if conf.options._test:
Alexander Afanasyev9e5a4702013-01-24 13:15:23 -0800107 conf.define ('_TESTS', 1)
Alexander Afanasyev72ac2192013-01-03 19:33:43 -0800108 conf.env.TEST = 1
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800109
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800110 conf.write_config_header('src/config.h')
111
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800112def build (bld):
Zhenkai Zhue8409422013-01-28 12:52:17 -0800113 executor = bld.objects (
114 target = "executor",
115 features = ["cxx"],
116 source = bld.path.ant_glob(['executor/**/*.cc']),
117 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX',
118 includes = "executor src",
119 )
120
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800121 scheduler = bld.objects (
122 target = "scheduler",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800123 features = ["cxx"],
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800124 source = bld.path.ant_glob(['scheduler/**/*.cc']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800125 use = 'BOOST BOOST_THREAD LIBEVENT LIBEVENT_PTHREADS LOG4CXX executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800126 includes = "scheduler executor src",
Alexander Afanasyev68f2a952013-01-08 14:34:16 -0800127 )
128
Zhenkai Zhua7e3da72012-12-27 13:45:00 -0800129 libccnx = bld (
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800130 target="ccnx",
131 features=['cxx'],
132 source = bld.path.ant_glob(['ccnx/**/*.cc', 'ccnx/**/*.cpp']),
Zhenkai Zhue8409422013-01-28 12:52:17 -0800133 use = 'BOOST BOOST_THREAD SSL CCNX LOG4CXX scheduler executor',
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800134 includes = "ccnx src scheduler executor",
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800135 )
136
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800137 adhoc = bld (
138 target = "adhoc",
139 features=['cxx'],
140 includes = "ccnx src",
141 )
142 if Utils.unversioned_sys_platform () == "darwin":
143 adhoc.mac_app = True
144 adhoc.source = 'adhoc/adhoc-osx.mm'
145 adhoc.use = "OSX_FOUNDATION OSX_COREWLAN"
146
Alexander Afanasyev3f101ec2013-01-17 16:58:03 -0800147 chornoshare = bld (
148 target="chronoshare",
149 features=['cxx'],
150 source = bld.path.ant_glob(['src/**/*.cc', 'src/**/*.cpp', 'src/**/*.proto']),
Alexander Afanasyevc507ac22013-01-21 16:01:58 -0800151 use = "BOOST BOOST_FILESYSTEM SQLITE3 LOG4CXX scheduler ccnx",
Zhenkai Zhu1888f742013-01-28 12:47:33 -0800152 includes = "ccnx scheduler src executor",
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800153 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800154
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800155 fs_watcher = bld (
156 target = "fs_watcher",
157 features = "qt4 cxx",
158 defines = "WAF",
159 source = bld.path.ant_glob(['fs-watcher/*.cc']),
160 use = "SQLITE3 LOG4CXX scheduler executor QTCORE",
161 includes = "fs-watcher scheduler executor src",
162 )
163
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800164 # Unit tests
165 if bld.env['TEST']:
166 unittests = bld.program (
167 target="unit-tests",
Zhenkai Zhud1756272013-02-01 17:02:18 -0800168 features = "qt4 cxx cxxprogram",
169 defines = "WAF",
Zhenkai Zhu369eff12013-02-05 15:43:49 -0800170 source = bld.path.ant_glob(['test/*.cc']),
171 use = 'BOOST_TEST BOOST_FILESYSTEM LOG4CXX SQLITE3 QTCORE QTGUI ccnx database fs_watcher chronoshare',
172 includes = "ccnx scheduler src executor gui fs-watcher",
Alexander Afanasyev4f62f442013-02-07 22:36:08 -0800173 install_prefix = None,
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800174 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800175
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800176 qt = bld (
177 target = "ChronoShare",
178 features = "qt4 cxx cxxprogram",
179 defines = "WAF",
180 source = bld.path.ant_glob(['gui/*.cpp', 'gui/*.cc', 'gui/*.qrc']),
Alexander Afanasyev85a4ba02013-02-24 16:30:17 -0800181 includes = "ccnx scheduler executor fs-watcher gui src adhoc . ",
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800182 use = "BOOST BOOST_FILESYSTEM SQLITE3 QTCORE QTGUI LOG4CXX fs_watcher ccnx database chronoshare"
183 )
184
185 if Utils.unversioned_sys_platform () == "darwin":
186 app_plist = '''<?xml version="1.0" encoding="UTF-8"?>
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800187<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
188<plist version="0.9">
189<dict>
190 <key>CFBundlePackageType</key>
191 <string>APPL</string>
192 <key>CFBundleGetInfoString</key>
193 <string>Created by Waf</string>
194 <key>CFBundleSignature</key>
195 <string>????</string>
196 <key>NOTE</key>
197 <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string>
198 <key>CFBundleExecutable</key>
199 <string>%s</string>
200 <key>LSUIElement</key>
201 <string>1</string>
202</dict>
203</plist>'''
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800204 qt.mac_app = "ChronoShare.app"
205 qt.mac_plist = app_plist % "ChronoShare"
Zhenkai Zhuaca6cb52013-02-24 23:34:03 -0800206 if not bld.env['SPARKLE']:
207 qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
208 else:
209 qt.use += " OSX_SPARKLE OSX_FOUNDATION OSX_COREWLAN adhoc"
210 qt.source.append("osx/auto-update/sparkle-auto-update.mm")
211 qt.includes += " osx/auto-update"
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800212 # qt.use += " OSX_FOUNDATION OSX_COREWLAN adhoc"
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800213
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)