9 opt.load('compiler_cxx')
12 opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
13 opt.add_option('--disable-gui', action='store_true', default=False, help='disable building of GUI tools')
14 opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
15 opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
16 opt.add_option('--target-debian', action='store_true', default=False, help='set up to compile for a Debian/Ubuntu package')
17 opt.add_option('--debian-unstable', action='store_true', default=False, help='add extra libraries to static-build correctly on Debian unstable')
18 opt.add_option('--target-centos-6', action='store_true', default=False, help='set up to compile for a Centos 6.5 package')
19 opt.add_option('--target-centos-7', action='store_true', default=False, help='set up to compile for a Centos 7 package')
20 opt.add_option('--magickpp-config', action='store', default='Magick++-config', help='path to Magick++-config')
21 opt.add_option('--wx-config', action='store', default='wx-config', help='path to wx-config')
22 opt.add_option('--address-sanitizer', action='store_true', default=False, help='build with address sanitizer')
23 opt.add_option('--install-prefix', default=None, help='prefix of where DCP-o-matic will be installed')
25 def static_ffmpeg(conf):
26 conf.check_cfg(package='libavformat', args='--cflags', uselib_store='AVFORMAT', mandatory=True)
27 conf.env.STLIB_AVFORMAT = ['avformat']
28 conf.check_cfg(package='libavfilter', args='--cflags', uselib_store='AVFILTER', mandatory=True)
29 conf.env.STLIB_AVFILTER = ['avfilter', 'swresample']
30 conf.check_cfg(package='libavcodec', args='--cflags', uselib_store='AVCODEC', mandatory=True)
31 conf.env.STLIB_AVCODEC = ['avcodec']
32 conf.env.LIB_AVCODEC = ['z']
33 conf.check_cfg(package='libavutil', args='--cflags', uselib_store='AVUTIL', mandatory=True)
34 conf.env.STLIB_AVUTIL = ['avutil']
35 conf.check_cfg(package='libswscale', args='--cflags', uselib_store='SWSCALE', mandatory=True)
36 conf.env.STLIB_SWSCALE = ['swscale']
37 conf.check_cfg(package='libswresample', args='--cflags', uselib_store='SWRESAMPLE', mandatory=True)
38 conf.env.STLIB_SWRESAMPLE = ['swresample']
39 conf.check_cfg(package='libpostproc', args='--cflags', uselib_store='POSTPROC', mandatory=True)
40 conf.env.STLIB_POSTPROC = ['postproc']
42 def dynamic_ffmpeg(conf):
43 conf.check_cfg(package='libavformat', args='--cflags --libs', uselib_store='AVFORMAT', mandatory=True)
44 conf.check_cfg(package='libavfilter', args='--cflags --libs', uselib_store='AVFILTER', mandatory=True)
45 conf.check_cfg(package='libavcodec', args='--cflags --libs', uselib_store='AVCODEC', mandatory=True)
46 conf.check_cfg(package='libavutil', args='--cflags --libs', uselib_store='AVUTIL', mandatory=True)
47 conf.check_cfg(package='libswscale', args='--cflags --libs', uselib_store='SWSCALE', mandatory=True)
48 conf.check_cfg(package='libswresample', args='--cflags --libs', uselib_store='SWRESAMPLE', mandatory=True)
49 conf.check_cfg(package='libpostproc', args='--cflags --libs', uselib_store='POSTPROC', mandatory=True)
51 def static_openjpeg(conf):
52 conf.check_cfg(package='libopenjpeg', args='--cflags', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
53 conf.check_cfg(package='libopenjpeg', args='--cflags', max_version='1.5.2', mandatory=True)
54 conf.env.STLIB_OPENJPEG = ['openjpeg']
56 def dynamic_openjpeg(conf):
57 conf.check_cfg(package='libopenjpeg', args='--cflags --libs', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
58 conf.check_cfg(package='libopenjpeg', args='--cflags --libs', max_version='1.5.2', mandatory=True)
60 def static_dcp(conf, static_boost, static_xmlpp, static_xmlsec, static_ssh):
61 conf.check_cfg(package='libdcp', atleast_version='0.96', args='--cflags', uselib_store='DCP', mandatory=True)
62 conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
63 conf.env.STLIB_DCP = ['dcp', 'asdcp-libdcp', 'kumu-libdcp']
64 conf.env.LIB_DCP = ['glibmm-2.4', 'ssl', 'crypto', 'bz2', 'xslt']
67 conf.env.STLIB_DCP.append('boost_system')
70 conf.env.STLIB_DCP.append('xml++-2.6')
72 conf.env.LIB_DCP.append('xml++-2.6')
75 conf.env.STLIB_DCP.append('xmlsec1-openssl')
76 conf.env.STLIB_DCP.append('xmlsec1')
78 conf.env.LIB_DCP.append('xmlsec1-openssl')
79 conf.env.LIB_DCP.append('xmlsec1')
82 conf.env.STLIB_DCP.append('ssh')
84 conf.env.LIB_DCP.append('ssh')
86 def dynamic_dcp(conf):
87 conf.check_cfg(package='libdcp', atleast_version='0.97.0', args='--cflags --libs', uselib_store='DCP', mandatory=True)
88 conf.env.DEFINES_DCP = [f.replace('\\', '') for f in conf.env.DEFINES_DCP]
90 def dynamic_ssh(conf):
91 conf.check_cc(fragment="""
92 #include <libssh/libssh.h>\n
94 ssh_session s = ssh_new ();\n
97 """, msg='Checking for library libssh', mandatory=True, lib='ssh', uselib_store='SSH')
99 def dynamic_boost(conf, lib_suffix, thread):
100 conf.check_cxx(fragment="""
101 #include <boost/version.hpp>\n
102 #if BOOST_VERSION < 104500\n
103 #error boost too old\n
105 int main(void) { return 0; }\n
108 msg='Checking for boost library >= 1.45',
110 errmsg='too old\nPlease install boost version 1.45 or higher.')
112 conf.check_cxx(fragment="""
113 #include <boost/thread.hpp>\n
114 int main() { boost::thread t (); }\n
115 """, msg='Checking for boost threading library',
116 libpath='/usr/local/lib',
117 lib=[thread, 'boost_system%s' % lib_suffix],
118 uselib_store='BOOST_THREAD')
120 conf.check_cxx(fragment="""
121 #include <boost/filesystem.hpp>\n
122 int main() { boost::filesystem::copy_file ("a", "b"); }\n
123 """, msg='Checking for boost filesystem library',
124 libpath='/usr/local/lib',
125 lib=['boost_filesystem%s' % lib_suffix, 'boost_system%s' % lib_suffix],
126 uselib_store='BOOST_FILESYSTEM')
128 conf.check_cxx(fragment="""
129 #include <boost/date_time.hpp>\n
130 int main() { boost::gregorian::day_clock::local_day(); }\n
131 """, msg='Checking for boost datetime library',
132 libpath='/usr/local/lib',
133 lib=['boost_date_time%s' % lib_suffix, 'boost_system%s' % lib_suffix],
134 uselib_store='BOOST_DATETIME')
136 conf.check_cxx(fragment="""
137 #include <boost/signals2.hpp>\n
138 int main() { boost::signals2::signal<void (int)> x; }\n
140 msg='Checking for boost signals2 library',
141 uselib_store='BOOST_SIGNALS2')
143 def static_boost(conf, lib_suffix):
144 conf.env.STLIB_BOOST_THREAD = ['boost_thread']
145 conf.env.STLIB_BOOST_FILESYSTEM = ['boost_filesystem%s' % lib_suffix]
146 conf.env.STLIB_BOOST_DATETIME = ['boost_date_time%s' % lib_suffix, 'boost_system%s' % lib_suffix]
147 conf.env.STLIB_BOOST_SIGNALS2 = ['boost_signals2']
149 def dynamic_quickmail(conf):
150 conf.check_cxx(fragment="""
151 #include <quickmail.h>
152 int main(void) { quickmail_initialize (); }
155 msg='Checking for libquickmail',
156 libpath='/usr/local/lib',
157 lib=['quickmail', 'curl'],
158 uselib_store='QUICKMAIL')
161 conf.load('compiler_cxx')
162 if conf.options.target_windows:
165 # conf.options -> conf.env
166 conf.env.TARGET_WINDOWS = conf.options.target_windows
167 conf.env.DISABLE_GUI = conf.options.disable_gui
168 conf.env.DISABLE_TESTS = conf.options.disable_tests
169 conf.env.TARGET_DEBIAN = conf.options.target_debian
170 conf.env.DEBIAN_UNSTABLE = conf.options.debian_unstable
171 conf.env.TARGET_CENTOS_6 = conf.options.target_centos_6
172 conf.env.TARGET_CENTOS_7 = conf.options.target_centos_7
173 conf.env.VERSION = VERSION
174 conf.env.TARGET_OSX = sys.platform == 'darwin'
175 conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
176 # true if we should build dcpomatic/libdcpomatic/libdcpomatic-wx statically
177 conf.env.BUILD_STATIC = conf.options.target_debian or conf.options.target_centos_6 or conf.options.target_centos_7
178 if conf.options.install_prefix is None:
179 conf.env.INSTALL_PREFIX = conf.env.PREFIX
181 conf.env.INSTALL_PREFIX = conf.options.install_prefix
184 conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS', '-D__STDC_LIMIT_MACROS', '-msse', '-ffast-math', '-fno-strict-aliasing',
185 '-Wall', '-Wno-attributes', '-Wextra', '-D_FILE_OFFSET_BITS=64'])
187 if conf.options.enable_debug:
188 conf.env.append_value('CXXFLAGS', ['-g', '-DDCPOMATIC_DEBUG'])
190 conf.env.append_value('CXXFLAGS', '-O2')
192 if conf.options.address_sanitizer:
193 conf.env.append_value('CXXFLAGS', ['-fsanitize=address', '-fno-omit-frame-pointer'])
194 conf.env.append_value('LINKFLAGS', ['-fsanitize=address'])
197 # Platform-specific CFLAGS hacks and other tinkering
201 if conf.env.TARGET_WINDOWS:
202 conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_WINDOWS')
203 conf.env.append_value('CXXFLAGS', '-DWIN32_LEAN_AND_MEAN')
204 conf.env.append_value('CXXFLAGS', '-DBOOST_USE_WINDOWS_H')
205 conf.env.append_value('CXXFLAGS', '-DUNICODE')
206 conf.env.append_value('CXXFLAGS', '-DBOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN')
207 conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
208 wxrc = os.popen('wx-config --rescomp').read().split()[1:]
209 conf.env.append_value('WINRCFLAGS', wxrc)
210 if conf.options.enable_debug:
211 conf.env.append_value('CXXFLAGS', ['-mconsole'])
212 conf.env.append_value('LINKFLAGS', ['-mconsole'])
213 conf.check(lib='ws2_32', uselib_store='WINSOCK2', msg="Checking for library winsock2")
214 conf.check(lib='bfd', uselib_store='BFD', msg="Checking for library bfd")
215 conf.check(lib='dbghelp', uselib_store='DBGHELP', msg="Checking for library dbghelp")
216 conf.check(lib='iberty', uselib_store='IBERTY', msg="Checking for library iberty")
217 conf.check(lib='shlwapi', uselib_store='SHLWAPI', msg="Checking for library shlwapi")
218 conf.check(lib='mswsock', uselib_store='MSWSOCK', msg="Checking for library mswsock")
219 boost_lib_suffix = '-mt'
220 boost_thread = 'boost_thread_win32-mt'
223 if conf.env.TARGET_LINUX or conf.env.TARGET_OSX:
224 conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_POSIX')
225 conf.env.append_value('CXXFLAGS', '-DPOSIX_LOCALE_PREFIX="%s/share/locale"' % conf.env['INSTALL_PREFIX'])
226 conf.env.append_value('CXXFLAGS', '-DPOSIX_ICON_PREFIX="%s/share/dcpomatic"' % conf.env['INSTALL_PREFIX'])
227 boost_lib_suffix = ''
228 boost_thread = 'boost_thread'
229 conf.env.append_value('LINKFLAGS', '-pthread')
232 if conf.env.TARGET_LINUX:
233 conf.env.append_value('CXXFLAGS', '-mfpmath=sse')
234 conf.env.append_value('CXXFLAGS', '-DDCPOMATIC_LINUX')
236 if conf.env.TARGET_DEBIAN:
237 # libxml2 seems to be linked against this on Ubuntu but it doesn't mention it in its .pc file
238 conf.check_cfg(package='liblzma', args='--cflags --libs', uselib_store='LZMA', mandatory=True)
240 if not conf.env.DISABLE_GUI and conf.env.TARGET_LINUX:
241 conf.check_cfg(package='gtk+-2.0', args='--cflags --libs', uselib_store='GTK', mandatory=True)
244 if conf.env.TARGET_OSX:
245 conf.env.append_value('CXXFLAGS', ['-DDCPOMATIC_OSX', '-Wno-unused-function', '-Wno-unused-parameter'])
246 conf.env.append_value('LINKFLAGS', '-headerpad_max_install_names')
250 # There's probably a neater way of expressing these, but I've gone for brute force for now.
253 if conf.env.TARGET_DEBIAN:
254 conf.check_cfg(package='libcxml', atleast_version='0.11', args='--cflags', uselib_store='CXML', mandatory=True)
255 conf.env.STLIB_CXML = ['cxml']
256 conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
257 conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
258 conf.env.STLIB_QUICKMAIL = ['quickmail']
260 static_openjpeg(conf)
261 static_dcp(conf, False, False, False, False)
262 dynamic_boost(conf, boost_lib_suffix, boost_thread)
264 if conf.env.TARGET_CENTOS_6:
265 # Centos 6.5's boost is too old, so we build a new version statically in the chroot
266 conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs-only-L', uselib_store='CXML', mandatory=True)
267 conf.env.STLIB_CXML = ['cxml', 'boost_filesystem']
268 conf.check_cfg(package='libcurl', args='--cflags --libs-only-L', uselib_store='CURL', mandatory=True)
269 conf.env.STLIB_CURL = ['curl']
270 conf.env.LIB_CURL = ['ssh2', 'idn']
271 conf.env.STLIB_QUICKMAIL = ['quickmail', 'curl']
272 conf.env.LIB_QUICKMAIL = ['ssh2', 'idn']
274 static_openjpeg(conf)
275 static_dcp(conf, True, True, True, True)
276 static_boost(conf, boost_lib_suffix)
278 if conf.env.TARGET_CENTOS_7:
279 # Centos 7's boost is ok so we link it dynamically
280 conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags', uselib_store='CXML', mandatory=True)
281 conf.env.STLIB_CXML = ['cxml']
282 conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
283 conf.env.STLIB_QUICKMAIL = ['quickmail']
284 conf.env.LIB_SSH = ['gssapi_krb5']
285 conf.env.LIB_XMLPP = ['xml2']
286 conf.env.LIB_XMLSEC = ['ltdl']
288 static_openjpeg(conf)
289 static_dcp(conf, False, True, True, True)
290 dynamic_boost(conf, boost_lib_suffix, boost_thread)
292 if conf.env.TARGET_WINDOWS:
293 conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
294 conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
295 conf.check_cxx(fragment="""
296 #include <boost/locale.hpp>\n
297 int main() { std::locale::global (boost::locale::generator().generate ("")); }\n
298 """, msg='Checking for boost locale library',
299 libpath='/usr/local/lib',
300 lib=['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
301 uselib_store='BOOST_LOCALE')
302 dynamic_quickmail(conf)
303 dynamic_boost(conf, boost_lib_suffix, boost_thread)
305 dynamic_openjpeg(conf)
309 # Not packaging; just a straight build
310 if not conf.env.TARGET_WINDOWS and not conf.env.TARGET_DEBIAN and not conf.env.TARGET_CENTOS_6 and not conf.env.TARGET_CENTOS_7:
311 conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs', uselib_store='CXML', mandatory=True)
312 conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
313 conf.check_cfg(package='libcurl', args='--cflags --libs', uselib_store='CURL', mandatory=True)
314 dynamic_quickmail(conf)
315 dynamic_boost(conf, boost_lib_suffix, boost_thread)
318 dynamic_openjpeg(conf)
321 # Dependencies which are always dynamically linked
322 conf.check_cfg(package='sndfile', args='--cflags --libs', uselib_store='SNDFILE', mandatory=True)
323 conf.check_cfg(package='glib-2.0', args='--cflags --libs', uselib_store='GLIB', mandatory=True)
324 conf.check_cfg(package= '', path=conf.options.magickpp_config, args='--cppflags --cxxflags --libs', uselib_store='MAGICK', mandatory=True)
325 conf.check_cfg(package='libzip', args='--cflags --libs', uselib_store='ZIP', mandatory=True)
327 conf.check_cc(fragment="""
329 int main() { g_format_size (1); }
330 """, msg='Checking for g_format_size ()',
332 define_name='HAVE_G_FORMAT_SIZE',
335 conf.find_program('msgfmt', var='MSGFMT')
337 datadir = conf.env.DATADIR
339 datadir = os.path.join(conf.env.PREFIX, 'share')
341 conf.define('LOCALEDIR', os.path.join(datadir, 'locale'))
342 conf.define('DATADIR', datadir)
345 if not conf.env.DISABLE_TESTS:
349 create_version_cc(VERSION, bld.env.CXXFLAGS)
352 if not bld.env.DISABLE_TESTS:
354 if bld.env.TARGET_WINDOWS:
355 bld.recurse('platform/windows')
356 if bld.env.TARGET_LINUX:
357 bld.recurse('platform/linux')
358 if bld.env.TARGET_OSX:
359 bld.recurse('platform/osx')
361 for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
362 bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dcpomatic.png' % r)
364 if not bld.env.TARGET_WINDOWS:
365 bld.install_files('${PREFIX}/share/dcpomatic', 'icons/taskbar_icon.png')
367 bld.add_post_fun(post)
370 if not os.path.exists('.git'):
373 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
374 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
375 o = output[0].decode('utf-8')
376 return o.replace("commit ", "")[0:10]
381 f = open('.git_revision', 'w')
386 TODO core *~ src/wx/*~ src/lib/*~ builds/*~ doc/manual/*~ src/tools/*~ *.pyc .waf* build .git
387 deps alignment hacks sync *.tar.bz2 *.exe .lock* *build-windows doc/manual/pdf doc/manual/html
388 GRSYMS GRTAGS GSYMS GTAGS
392 def create_version_cc(version, cxx_flags):
393 commit = git_revision()
394 if commit is None and os.path.exists('.git_revision'):
395 f = open('.git_revision', 'r')
396 commit = f.readline().strip()
402 text = '#include "version.h"\n'
403 text += 'char const * dcpomatic_git_commit = \"%s\";\n' % commit
404 text += 'char const * dcpomatic_version = \"%s\";\n' % version
408 f = f.replace('"', '\\"')
410 text += 'char const * dcpomatic_cxx_flags = \"%s\";\n' % t[:-1]
412 print('Writing version information to src/lib/version.cc')
413 o = open('src/lib/version.cc', 'w')
417 print('Could not open src/lib/version.cc for writing\n')
421 if ctx.cmd == 'install':
422 ctx.exec_command('/sbin/ldconfig')
431 os.system('etags src/lib/*.cc src/lib/*.h src/wx/*.cc src/wx/*.h src/tools/*.cc src/tools/*.h')