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