Add cross header.
[dcpomatic.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'dvdomatic'
5 VERSION = '0.30pre'
6
7 def options(opt):
8     opt.load('compiler_cxx')
9     opt.add_option('--debug-hash', action='store_true', default = False, help = 'print hashes of data at various points')
10     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
11     opt.add_option('--disable-gui', action='store_true', default = False, help = 'disable building of GUI tools')
12     opt.add_option('--disable-player', action='store_true', default = False, help = 'disable building of the player components')
13     opt.add_option('--ffmpeg-083', action='store_true', default = False, help = 'Use FFmpeg version in Ubuntu 12.04')
14     opt.add_option('--target-windows', action='store_true', default = False, help = 'set up to do a cross-compile to Windows')
15
16 def configure(conf):
17     conf.load('compiler_cxx')
18
19     conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS', '-msse', '-mfpmath=sse', '-ffast-math', '-fno-strict-aliasing', '-Wall', '-Wno-attributes'])
20     conf.env.append_value('CXXFLAGS', ['-DDVDOMATIC_VERSION="%s"' % VERSION])
21
22     if conf.options.target_windows:
23         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_WINDOWS')
24         conf.options.disable_player = True
25         conf.check(lib = 'ws2_32', uselib_store = 'WINSOCK2', msg = "Checking for library winsock2")
26     else:
27         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_POSIX')
28
29     conf.env.DEBUG_HASH = conf.options.debug_hash
30     conf.env.TARGET_WINDOWS = conf.options.target_windows
31     conf.env.DISABLE_GUI = conf.options.disable_gui
32     conf.env.DISABLE_PLAYER = conf.options.disable_player
33
34     if conf.options.disable_player:
35         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_DISABLE_PLAYER')
36
37     if conf.options.enable_debug:
38         conf.env.append_value('CXXFLAGS', '-g')
39     else:
40         conf.env.append_value('CXXFLAGS', '-O3')
41
42     if conf.options.ffmpeg_083:
43         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_FFMPEG_0_8_3')
44
45     conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
46     conf.check_cfg(package = 'libavformat', args = '--cflags --libs', uselib_store = 'AVFORMAT', mandatory = True)
47     conf.check_cfg(package = 'libavfilter', args = '--cflags --libs', uselib_store = 'AVFILTER', mandatory = True)
48     conf.check_cfg(package = 'libavcodec', args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = True)
49     conf.check_cfg(package = 'libavutil', args = '--cflags --libs', uselib_store = 'AVUTIL', mandatory = True)
50     conf.check_cfg(package = 'libswscale', args = '--cflags --libs', uselib_store = 'SWSCALE', mandatory = True)
51     conf.check_cfg(package = 'libpostproc', args = '--cflags --libs', uselib_store = 'POSTPROC', mandatory = True)
52     conf.check_cfg(package = 'sndfile', args = '--cflags --libs', uselib_store = 'SNDFILE', mandatory = True)
53     conf.check_cfg(package = 'libdcp', args = '--cflags --libs', uselib_store = 'DCP', mandatory = True)
54     conf.check_cfg(package = '', path = 'Magick++-config', args = '--cppflags --cxxflags --libs', uselib_store = 'MAGICK', mandatory = True)
55     conf.check_cc(msg = 'Checking for library libtiff', function_name = 'TIFFOpen', header_name = 'tiffio.h', lib = 'tiff', uselib_store = 'TIFF')
56     conf.check_cc(fragment  = """
57                               #include <stdio.h>\n
58                               #include <openjpeg.h>\n
59                               int main () {\n
60                               void* p = (void *) opj_image_create;\n
61                               return 0;\n
62                               }
63                               """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
64
65     conf.check_cc(fragment  = """
66                               #include <libssh/libssh.h>\n
67                               int main () {\n
68                               ssh_session s = ssh_new ();\n
69                               return 0;\n
70                               }
71                               """, msg = 'Checking for library libssh', mandatory = False, lib = 'ssh', uselib_store = 'SSH')
72                               
73     conf.check_cxx(fragment = """
74                               #include <boost/thread.hpp>\n
75                               int main() { boost::thread t (); }\n
76                               """, msg = 'Checking for boost threading library',
77                               lib = ['boost_thread_win32-mt', 'boost_system-mt'], uselib_store = 'BOOST_THREAD')
78     conf.check_cxx(fragment = """
79                               #include <boost/filesystem.hpp>\n
80                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
81                               """, msg = 'Checking for boost filesystem library',
82                               libpath = '/usr/local/lib', lib = ['boost_filesystem-mt', 'boost_system-mt'], uselib_store = 'BOOST_FILESYSTEM')
83
84     conf.check_cc(fragment = """
85                              #include <glib.h>
86                              int main() { g_format_size (1); }
87                              """, msg = 'Checking for g_format_size ()',
88                              lib = 'glib',
89                              define_name = 'HAVE_G_FORMAT_SIZE',
90                              mandatory = False)
91
92     conf.recurse('src')
93     conf.recurse('test')
94
95 def build(bld):
96     create_version_cc(VERSION)
97
98     bld.recurse('src')
99     bld.recurse('test')
100
101     d = { 'PREFIX' : '${PREFIX' }
102
103     obj = bld(features = 'subst')
104     obj.source = 'dvdomatic.desktop.in'
105     obj.target = 'dvdomatic.desktop'
106     obj.dict = d
107
108     bld.install_files('${PREFIX}/share/applications', 'dvdomatic.desktop')
109     for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
110         bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dvdomatic.png' % r)
111
112 def dist(ctx):
113     ctx.excl = 'TODO core *~ src/gtk/*~ src/lib/*~ .waf* build .git'
114
115 def create_version_cc(version):
116     if os.path.exists('.git'):
117         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
118         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
119         o = output[0].decode('utf-8')
120         commit = o.replace ("commit ", "")[0:10]
121     else:
122         commit = 'release'
123
124     try:
125         text =  '#include "version.h"\n'
126         text += 'char const * dvdomatic_git_commit = \"%s\";\n' % commit
127         text += 'char const * dvdomatic_version = \"%s\";\n' % version
128         print('Writing version information to src/lib/version.cc')
129         o = open('src/lib/version.cc', 'w')
130         o.write(text)
131         o.close()
132     except IOError:
133         print('Could not open src/lib/version.cc for writing\n')
134         sys.exit(-1)