blob: 0799117c1eaf017f040cc127372a1b250e4ea476 [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 Afanasyev1b51bb52017-02-10 19:52:32 -08002VERSION='0.1.0'
Alexander Afanasyeve83c0562016-12-24 10:20:41 -08003APPNAME='ChronoShare'
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -08004APPCAST='https://named-data.net/binaries/ChronoShare/sparkle-appcast.xml'
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08005
Alexander Afanasyeve83c0562016-12-24 10:20:41 -08006from waflib import Logs, Utils, Task, TaskGen
Zhenkai Zhua7e3da72012-12-27 13:45:00 -08007
8def options(opt):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -08009 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
10 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 Afanasyev5f9d09e2012-12-28 19:43:08 -080012
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080013 opt.add_option('--without-sqlite-locking', action='store_false', default=True,
14 dest='with_sqlite_locking',
15 help='''Disable filesystem locking in sqlite3 database '''
16 '''(use unix-dot locking mechanism instead). '''
17 '''This option may be necessary if home directory is hosted on NFS.''')
Alexander Afanasyev5a95a252013-02-25 12:55:48 -080018
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080019 if Utils.unversioned_sys_platform() == "darwin":
20 opt.add_option('--with-auto-update', action='store_true', default=False, dest='autoupdate',
21 help='''(OSX) Download sparkle framework and enable autoupdate feature''')
22
23 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'qt5'])
24 opt.load(['default-compiler-flags',
25 'osx-frameworks', 'boost', 'sqlite3', 'protoc', 'tinyxml',
26 'coverage', 'sanitizers',
27 'doxygen', 'sphinx_build'], tooldir=['.waf-tools'])
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080028
29def configure(conf):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080030 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
31 'default-compiler-flags',
32 'osx-frameworks', 'boost', 'sqlite3', 'protoc', 'tinyxml',
33 'doxygen', 'sphinx_build'])
Alexander Afanasyeva1b7bb52013-02-26 17:04:02 -080034
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080035 if 'PKG_CONFIG_PATH' not in conf.environ:
36 conf.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Alexander Afanasyevf2890632013-01-02 13:40:02 -080037
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080038 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
39 uselib_store='NDN_CXX')
40
41 # add homebrew path, as qt5 is no longer linked
42 conf.environ['PKG_CONFIG_PATH'] += ":/usr/local/opt/qt5/lib/pkgconfig:/opt/qt5/5.8/clang_64/lib/pkgconfig"
43 conf.environ['PATH'] += ":/usr/local/opt/qt5/bin:/opt/qt5/5.8/clang_64/bin"
44
45 conf.load('qt5')
46
47 conf.define("CHRONOSHARE_VERSION", VERSION)
48
49 conf.check_sqlite3(mandatory=True)
50 if not conf.options.with_sqlite_locking:
51 conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
52
Zhenkai Zhu3457ed42013-03-12 15:15:21 -070053 conf.check_tinyxml(path=conf.options.tinyxml_dir)
Zhenkai Zhubc2f6282013-01-08 16:40:58 -080054
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080055 conf.define("TRAY_ICON", "chronoshare-big.png")
56 if Utils.unversioned_sys_platform() == "linux":
57 conf.define("TRAY_ICON", "chronoshare-ubuntu.png")
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -080058
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080059 USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -080060 'regex', 'program_options', 'thread', 'log', 'log_setup']
Alexander Afanasyev33206982013-01-09 16:29:29 -080061
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080062 conf.env['WITH_TESTS'] = conf.options.with_tests
63 if conf.env['WITH_TESTS']:
64 USED_BOOST_LIBS += ['unit_test_framework']
65 conf.define('HAVE_TESTS', 1)
Alexander Afanasyev33206982013-01-09 16:29:29 -080066
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -080067 conf.check_boost(lib=USED_BOOST_LIBS, mt=True)
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080068 if conf.env.BOOST_VERSION_NUMBER < 105400:
69 Logs.error("Minimum required boost version is 1.54.0")
70 Logs.error("Please upgrade your distribution or install custom boost libraries" +
71 " (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080072 return
73
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080074 # Loading "late" to prevent tests to be compiled with profiling flags
75 conf.load('coverage')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080076
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080077 conf.load('sanitizers')
Zhenkai Zhua7e3da72012-12-27 13:45:00 -080078
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080079 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080080
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -080081 conf.define('CHRONOSHARE_VERSION', VERSION)
82 conf.define('CHRONOSHARE_APPCAST', APPCAST)
83
84 if Utils.unversioned_sys_platform() == "darwin":
85 conf.define('OSX_BUILD', 1)
86 conf.env['AUTOUPDATE'] = conf.options.autoupdate
87 if conf.env['AUTOUPDATE']:
88 conf.define('AUTOUPDATE', 1)
89
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080090 conf.write_config_header('core/chronoshare-config.hpp')
Zhenkai Zhue8409422013-01-28 12:52:17 -080091
Alexander Afanasyeve83c0562016-12-24 10:20:41 -080092def build(bld):
Alexander Afanasyev360f41f2016-12-25 13:20:21 -080093 bld(name='core-objects',
94 target='core-objects',
95 features=['cxx'],
96 source=bld.path.ant_glob('core/**/*.cpp'),
Alexander Afanasyev1cf5c432017-01-13 23:22:15 -080097 use='NDN_CXX BOOST',
Alexander Afanasyev360f41f2016-12-25 13:20:21 -080098 includes='.',
99 export_includes='.')
100
Lijing Wange84adea2015-05-31 16:25:16 -0700101 chornoshare = bld(
102 target="chronoshare",
103 features=['cxx'],
104 source=bld.path.ant_glob(['src/*.proto',
Yukai Tu05126792016-10-11 15:03:30 -0700105 'src/*.cpp',
Lijing Wange84adea2015-05-31 16:25:16 -0700106 ]),
Yukai Tu09e02fd2016-10-24 13:48:01 -0700107 use='core-objects adhoc NDN_CXX BOOST TINYXML SQLITE3',
Lijing Wange84adea2015-05-31 16:25:16 -0700108 includes="src",
109 export_includes="src",
110 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800111
Lijing Wange0dd63e2015-05-31 16:25:16 -0700112 fs_watcher = bld(
113 features=['qt5', 'cxx'],
114 target='fs-watcher',
115 defines='WAF',
116 moc = "fs-watcher/fs-watcher.hpp",
117 source=bld.path.ant_glob('fs-watcher/*.cpp'),
118 use='chronoshare QT5CORE',
119 includes='fs-watcher',
120 export_includes='fs-watcher',
121 )
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800122
Alexander Afanasyevcaf61b12016-12-25 14:18:52 -0800123 http_server = bld(
Lijing Wang152449c2015-05-31 16:25:16 -0700124 target = "http_server",
125 features = "qt5 cxx",
126 source = bld.path.ant_glob(['server/*.cpp']),
127 includes = "server src .",
128 use = 'BOOST QT5CORE',
Yukai Tu73287f52017-02-06 15:46:40 -0800129 export_includes="server"
Lijing Wang152449c2015-05-31 16:25:16 -0700130 )
Alexander Afanasyevb2fe74e2013-01-20 16:06:43 -0800131
Yukai Tu73287f52017-02-06 15:46:40 -0800132 chronoshare_gui = bld(
133 target = "chronoshare_gui",
134 features = "qt5 cxx",
Lijing Wang152449c2015-05-31 16:25:16 -0700135 defines = "WAF",
Yukai Tu73287f52017-02-06 15:46:40 -0800136 source = bld.path.ant_glob(['gui/*.cpp'], excl='gui/main.cpp'),
Lijing Wang152449c2015-05-31 16:25:16 -0700137 includes = "fs-watcher gui src adhoc server . ",
138 use = "fs-watcher chronoshare http_server QT5CORE QT5GUI QT5WIDGETS",
139 moc = "gui/chronosharegui.hpp",
Yukai Tu73287f52017-02-06 15:46:40 -0800140 export_includes='gui',
141 )
142
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800143 app = bld(
Yukai Tu73287f52017-02-06 15:46:40 -0800144 target = "ChronoShare",
145 features = "qt5 cxx cxxprogram html_resources",
146 defines = "WAF",
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800147 source = bld.path.ant_glob(['gui/main.cpp']) + ['gui/images.qrc'],
Yukai Tu73287f52017-02-06 15:46:40 -0800148 includes = "fs-watcher gui src adhoc server . ",
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800149 use = "chronoshare_gui",
Lijing Wang152449c2015-05-31 16:25:16 -0700150 html_resources = bld.path.find_dir("gui/html").ant_glob([
151 '**/*.js', '**/*.png', '**/*.css',
152 '**/*.html', '**/*.gif', '**/*.ico'
153 ]),
Yukai Tu73287f52017-02-06 15:46:40 -0800154 export_includes='gui',
155 )
Alexander Afanasyevf2890632013-01-02 13:40:02 -0800156
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800157 if Utils.unversioned_sys_platform() == "darwin":
158 bld(features="subst",
159 source='src/Info.plist.in',
160 target='src/Info.plist',
161 install_path=None,
162 VERSION=VERSION,
163 APPCAST=APPCAST)
Zhenkai Zhua9a7e1d2013-02-25 18:29:07 -0800164
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800165 if bld.env['AUTOUPDATE']:
166 chronoshare_gui.source += bld.path.ant_glob(['gui/osx-*.mm'])
167 chronoshare_gui.use += " OSX_FOUNDATION OSX_SPARKLE"
168 app.mac_app = True
169 app.mac_plist = 'src/Info.plist'
170 app.mac_files = [i.path_from(bld.path) for i in bld.path.ant_glob('res/**/*', excl='**/*.ai')]
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800171
Alexander Afanasyev1b51bb52017-02-10 19:52:32 -0800172 if Utils.unversioned_sys_platform() == "linux":
173 bld(
174 features = "process_in",
175 target = "ChronoShare.desktop",
176 source = "ChronoShare.desktop.in",
177 install_prefix = "${DATADIR}/applications",
178 )
179 bld.install_files("${DATADIR}/applications", "ChronoShare.desktop")
180 bld.install_files("${DATADIR}/ChronoShare", "gui/images/chronoshare-big.png")
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800181
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700182 cmdline = bld(
183 target = "csd",
184 features = "qt5 cxx cxxprogram",
185 defines = "WAF",
186 source = 'cmd/csd.cpp',
187 moc = 'cmd/csd.hpp',
Yukai Tu73287f52017-02-06 15:46:40 -0800188 use = "fs-watcher chronoshare http_server chronoshare_gui QT5CORE",
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700189 )
Alexander Afanasyev83a53002013-01-24 11:12:01 -0800190
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700191 dump_db = bld(
192 target = "dump-db",
193 features = "cxx cxxprogram",
194 source = bld.path.ant_glob(['cmd/dump-db.cpp']),
Yukai Tu73287f52017-02-06 15:46:40 -0800195 use = "fs-watcher chronoshare http_server chronoshare_gui QT5CORE",
Alexander Afanasyev61ced272015-05-31 16:25:16 -0700196 )
Alexander Afanasyev548d38d2013-01-26 16:36:06 -0800197
Alexander Afanasyev45289972016-12-24 20:23:03 -0800198 bld.recurse('tests');
Alexander Afanasyeveb575e02013-01-26 17:14:51 -0800199
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800200from waflib import TaskGen
201@TaskGen.extension('.mm')
202def m_hook(self, node):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800203 """Alias .mm files to be compiled the same as .cpp files, gcc/clang will do the right thing."""
Alexander Afanasyeva98e69c2013-02-24 15:42:45 -0800204 return self.create_compiled_task('cxx', node)
Zhenkai Zhu6b53f932013-03-02 20:46:02 -0800205
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700206@TaskGen.extension('.js', '.png', '.css', '.html', '.gif', '.ico', '.in')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800207def sig_hook(self, node):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800208 node.sig=Utils.h_file(node.abspath())
Zhenkai Zhu6b53f932013-03-02 20:46:02 -0800209
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700210@TaskGen.feature('process_in')
211@TaskGen.after_method('process_source')
212def create_process_in(self):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800213 dst = self.bld.path.find_or_declare(self.target)
214 tsk = self.create_task('process_in', self.source, dst)
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700215
216class process_in(Task.Task):
217 color='PINK'
218
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800219 def run(self):
220 self.outputs[0].write(Utils.subst_vars(self.inputs[0].read(), self.env))
Alexander Afanasyev0b38ad02013-03-19 13:42:22 -0700221
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800222@TaskGen.feature('html_resources')
223@TaskGen.before_method('process_source')
224def create_qrc_task(self):
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800225 output = self.bld.path.find_or_declare("gui/html.qrc")
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800226 tsk = self.create_task('html_resources', self.html_resources, output)
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800227 tsk.base_path = output.parent.get_src()
228 self.create_rcc_task(output.get_src())
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800229
230class html_resources(Task.Task):
231 color='PINK'
232
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800233 def __str__(self):
234 return "%s: Generating %s\n" % (self.__class__.__name__.replace('_task',''), self.outputs[0].path_from(self.outputs[0].ctx.launch_node()))
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800235
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800236 def run(self):
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800237 out = self.outputs[0]
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800238 bld_out = out.get_bld()
239 src_out = out.get_src()
Alexander Afanasyev9cc6c212013-03-04 12:45:38 -0800240 bld_out.write('<RCC>\n <qresource prefix="/">\n')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800241 for f in self.inputs:
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800242 bld_out.write(' <file>%s</file>\n' % f.path_from(self.base_path), 'a')
Alexander Afanasyev9cc6c212013-03-04 12:45:38 -0800243 bld_out.write(' </qresource>\n</RCC>', 'a')
Alexander Afanasyev1cb641f2013-03-03 17:49:02 -0800244
Alexander Afanasyeve83c0562016-12-24 10:20:41 -0800245 src_out.write(bld_out.read(), 'w')
Alexander Afanasyevcaf48e22013-03-02 22:47:32 -0800246 return 0