Bump version
[libdcp.git] / wscript
1 import subprocess
2 import os
3 import lut
4
5 APPNAME = 'libdcp'
6 VERSION = '0.39'
7
8 def options(opt):
9     opt.load('compiler_cxx')
10     opt.add_option('--target-windows', action='store_true', default = False, help = 'set up to do a cross-compile to Windows')
11     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
12     opt.add_option('--static-openjpeg', action='store_true', default = False, help = 'link statically to openjpeg')
13     opt.add_option('--static-libdcp', action='store_true', default = False, help = 'build libdcp and in-tree dependencies statically')
14
15 def configure(conf):
16     conf.load('compiler_cxx')
17     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-Wno-unused-result', '-O2', '-D_FILE_OFFSET_BITS=64'])
18     conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
19
20     conf.env.TARGET_WINDOWS = conf.options.target_windows
21     conf.env.STATIC_OPENJPEG = conf.options.static_openjpeg
22     conf.env.STATIC_LIBDCP = conf.options.static_libdcp
23     conf.env.ENABLE_DEBUG = conf.options.enable_debug
24
25     if conf.options.target_windows:
26         conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
27     else:
28         conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
29
30     conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
31     conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
32     if conf.options.static_openjpeg:
33         conf.check_cc(fragment = openjpeg_fragment, msg = 'Checking for library openjpeg', stlib = 'openjpeg', uselib_store = 'OPENJPEG')
34     else:
35         conf.check_cfg(package = 'libopenjpeg', args = '--cflags --libs', uselib_store = 'OPENJPEG', mandatory = True)
36
37     if conf.options.target_windows:
38         boost_lib_suffix = '-mt'
39     else:
40         boost_lib_suffix = ''
41
42     if conf.options.enable_debug:
43         conf.env.append_value('CXXFLAGS', '-g')
44     else:
45         # Somewhat experimental use of -O2 rather than -O3 to see if
46         # Windows builds are any more reliable
47         conf.env.append_value('CXXFLAGS', '-O2')
48
49     conf.check_cxx(fragment = """
50                               #include <boost/version.hpp>\n
51                               #if BOOST_VERSION < 104500\n
52                               #error boost too old\n
53                               #endif\n
54                               int main(void) { return 0; }\n
55                               """,
56                    mandatory = True,
57                    msg = 'Checking for boost library >= 1.45',
58                    okmsg = 'yes',
59                    errmsg = 'too old\nPlease install boost version 1.45 or higher.')
60
61     conf.check_cxx(fragment = """
62                               #include <boost/filesystem.hpp>\n
63                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
64                               """,
65                    msg = 'Checking for boost filesystem library',
66                    libpath = '/usr/local/lib',
67                    lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
68                    uselib_store = 'BOOST_FILESYSTEM')
69
70     conf.check_cxx(fragment = """
71                               #include <boost/signals2.hpp>\n
72                               int main() { boost::signals2::signal<void (int)> x; }\n
73                               """,
74                    msg = 'Checking for boost signals2 library',
75                    uselib_store = 'BOOST_SIGNALS2')
76
77     lut.make_luts()
78
79     conf.recurse('test')
80     conf.recurse('asdcplib')
81
82 def build(bld):
83     create_version_cc(bld, VERSION)
84
85     if bld.env.TARGET_WINDOWS:
86         boost_lib_suffix = '-mt'
87     else:
88         boost_lib_suffix = ''
89
90     bld(source = 'libdcp.pc.in',
91         version = VERSION,
92         includedir = '%s/include' % bld.env.PREFIX,
93         libs = "-L${libdir} -ldcp -lasdcp-libdcp -lkumu-libdcp -lboost_system%s" % boost_lib_suffix,
94         install_path = '${LIBDIR}/pkgconfig')
95
96     bld.recurse('src')
97     bld.recurse('tools')
98     bld.recurse('test')
99     bld.recurse('asdcplib')
100     bld.recurse('examples')
101
102     bld.add_post_fun(post)
103
104 def dist(ctx):
105     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__'
106
107 def create_version_cc(bld, version):
108     if os.path.exists('.git'):
109         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
110         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
111         o = output[0].decode('utf-8')
112         commit = o.replace ("commit ", "")[0:10]
113     else:
114         commit = "release"
115
116     try:
117         text =  '#include "version.h"\n'
118         text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
119         text += 'char const * libdcp::version = \"%s\";\n' % version
120         if bld.env.ENABLE_DEBUG:
121             debug_string = 'true'
122         else:
123             debug_string = 'false'
124         text += 'bool const built_with_debug = %s;\n' % debug_string
125         print('Writing version information to src/version.cc')
126         o = open('src/version.cc', 'w')
127         o.write(text)
128         o.close()
129     except IOError:
130         print('Could not open src/version.cc for writing\n')
131         sys.exit(-1)
132
133 def post(ctx):
134     if ctx.cmd == 'install':
135         ctx.exec_command('/sbin/ldconfig')