Sort-of generates a signed CPL.
[libdcp.git] / wscript
1 import subprocess
2 import os
3 import lut
4
5 APPNAME = 'libdcp'
6 VERSION = '0.36pre'
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
24     if conf.options.target_windows:
25         conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
26     else:
27         conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
28
29     conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
30     conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
31     conf.check_cfg(package = 'xmlsec1', args = '--cflags --libs', uselib_store = 'XMLSEC1', mandatory = True)
32     # Remove erroneous escaping of quotes from xmlsec1 defines
33     conf.env.DEFINES_XMLSEC1 = [f.replace('\\', '') for f in conf.env.DEFINES_XMLSEC1]
34
35     openjpeg_fragment = """
36                         #include <stdio.h>\n
37                         #include <openjpeg.h>\n
38                         int main () {\n
39                         void* p = (void *) opj_image_create;\n
40                         return 0;\n
41                         }
42                         """
43     if conf.options.static_openjpeg:
44         conf.check_cc(fragment = openjpeg_fragment, msg = 'Checking for library openjpeg', stlib = 'openjpeg', uselib_store = 'OPENJPEG')
45     else:
46         conf.check_cc(fragment = openjpeg_fragment, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
47
48     if conf.options.target_windows:
49         boost_lib_suffix = '-mt'
50     else:
51         boost_lib_suffix = ''
52
53     if conf.options.enable_debug:
54         conf.env.append_value('CXXFLAGS', '-g')
55     else:
56         # Somewhat experimental use of -O2 rather than -O3 to see if
57         # Windows builds are any more reliable
58         conf.env.append_value('CXXFLAGS', '-O2')
59
60     conf.check_cxx(fragment = """
61                               #include <boost/filesystem.hpp>\n
62                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
63                               """,
64                    msg = 'Checking for boost filesystem library',
65                    libpath = '/usr/local/lib',
66                    lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
67                    uselib_store = 'BOOST_FILESYSTEM')
68
69     conf.check_cxx(fragment = """
70                               #include <boost/signals2.hpp>\n
71                               int main() { boost::signals2::signal<void (int)> x; }\n
72                               """,
73                    msg = 'Checking for boost signals2 library',
74                    uselib_store = 'BOOST_SIGNALS2')
75
76     lut.make_luts()
77
78     conf.recurse('test')
79     conf.recurse('asdcplib')
80
81 def build(bld):
82     create_version_cc(VERSION)
83
84     if bld.env.TARGET_WINDOWS:
85         boost_lib_suffix = '-mt'
86     else:
87         boost_lib_suffix = ''
88
89     bld(source = 'libdcp.pc.in',
90         version = VERSION,
91         includedir = '%s/include' % bld.env.PREFIX,
92         libs = "-L${libdir} -ldcp -lasdcp-libdcp -lkumu-libdcp -lboost_system%s" % boost_lib_suffix,
93         install_path = '${LIBDIR}/pkgconfig')
94
95     bld.recurse('src')
96     bld.recurse('tools')
97     bld.recurse('test')
98     bld.recurse('asdcplib')
99     bld.recurse('examples')
100
101     bld.add_post_fun(post)
102
103 def dist(ctx):
104     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__'
105
106 def create_version_cc(version):
107     if os.path.exists('.git'):
108         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
109         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
110         o = output[0].decode('utf-8')
111         commit = o.replace ("commit ", "")[0:10]
112     else:
113         commit = "release"
114
115     try:
116         text =  '#include "version.h"\n'
117         text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
118         text += 'char const * libdcp::version = \"%s\";\n' % version
119         print('Writing version information to src/version.cc')
120         o = open('src/version.cc', 'w')
121         o.write(text)
122         o.close()
123     except IOError:
124         print('Could not open src/version.cc for writing\n')
125         sys.exit(-1)
126
127 def post(ctx):
128     if ctx.cmd == 'install':
129         ctx.exec_command('/sbin/ldconfig')