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