Bump version
[libdcp.git] / wscript
1 import subprocess
2 import os
3 import sys
4 import distutils.spawn
5 from waflib import Logs
6
7 APPNAME = 'libdcp'
8 VERSION = '1.2.10'
9 API_VERSION = '-1.0'
10
11 def options(opt):
12     opt.load('compiler_cxx')
13     opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to Windows')
14     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
15     opt.add_option('--static', action='store_true', default=False, help='build libdcp and in-tree dependencies statically, and link statically to openjpeg and cxml')
16     opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
17     opt.add_option('--disable-gcov', action='store_true', default=False, help='don''t use gcov in tests')
18     opt.add_option('--disable-examples', action='store_true', default=False, help='disable building of examples')
19
20 def configure(conf):
21     conf.load('compiler_cxx')
22     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
23     conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
24
25     conf.env.TARGET_WINDOWS = conf.options.target_windows
26     conf.env.TARGET_OSX = sys.platform == 'darwin'
27     conf.env.ENABLE_DEBUG = conf.options.enable_debug
28     conf.env.DISABLE_TESTS = conf.options.disable_tests
29     conf.env.DISABLE_EXAMPLES = conf.options.disable_examples
30     conf.env.STATIC = conf.options.static
31     conf.env.API_VERSION = API_VERSION
32
33     if conf.options.target_windows:
34         conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
35     else:
36         conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
37
38     if not conf.env.TARGET_OSX:
39         conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter'])
40
41     conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
42     conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='LIBXML++', mandatory=True)
43     conf.check_cfg(package='xmlsec1', args='--cflags --libs', uselib_store='XMLSEC1', mandatory=True)
44     # Remove erroneous escaping of quotes from xmlsec1 defines
45     conf.env.DEFINES_XMLSEC1 = [f.replace('\\', '') for f in conf.env.DEFINES_XMLSEC1]
46
47     # ImageMagick / GraphicsMagick
48     if distutils.spawn.find_executable('Magick++-config'):
49         conf.check_cfg(package='', path='Magick++-config', args='--cppflags --cxxflags --libs', uselib_store='MAGICK', mandatory=True)
50     else:
51         image = conf.check_cfg(package='ImageMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
52         graphics = conf.check_cfg(package='GraphicsMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
53         if image is None and graphics is None:
54             Logs.pprint('RED', 'Neither ImageMagick++ nor GraphicsMagick++ found: one or the other is required')
55
56     conf.check_cfg(package='sndfile', args='--cflags --libs', uselib_store='SNDFILE', mandatory=False)
57
58     if conf.options.static:
59         conf.check_cc(fragment="""
60                      #include <stdio.h>\n
61                      #include <openjpeg.h>\n
62                      int main () {\n
63                      void* p = (void *) opj_image_create;\n
64                      return 0;\n
65                      }
66                      """,
67                        msg='Checking for library openjpeg', stlib='openjpeg', uselib_store='OPENJPEG', mandatory=True)
68
69         conf.env.HAVE_CXML = 1
70         conf.env.STLIB_CXML = ['cxml']
71     else:
72         conf.check_cfg(package='libopenjpeg', args='--cflags --libs', uselib_store='OPENJPEG', mandatory=True)
73         conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags --libs', uselib_store='CXML', mandatory=True)
74
75     if conf.options.target_windows:
76         boost_lib_suffix = '-mt'
77     else:
78         boost_lib_suffix = ''
79
80     if conf.options.enable_debug:
81         conf.env.append_value('CXXFLAGS', '-g')
82     else:
83         # Somewhat experimental use of -O2 rather than -O3 to see if
84         # Windows builds are any more reliable
85         conf.env.append_value('CXXFLAGS', '-O2')
86
87     conf.check_cxx(fragment="""
88                             #include <boost/version.hpp>\n
89                             #if BOOST_VERSION < 104500\n
90                             #error boost too old\n
91                             #endif\n
92                             int main(void) { return 0; }\n
93                             """,
94                    mandatory=True,
95                    msg='Checking for boost library >= 1.45',
96                    okmsg='yes',
97                    errmsg='too old\nPlease install boost version 1.45 or higher.')
98
99     conf.check_cxx(fragment="""
100                             #include <boost/filesystem.hpp>\n
101                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
102                             """,
103                    msg='Checking for boost filesystem library',
104                    libpath='/usr/local/lib',
105                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
106                    uselib_store='BOOST_FILESYSTEM')
107
108     conf.check_cxx(fragment="""
109                             #include <boost/signals2.hpp>\n
110                             int main() { boost::signals2::signal<void (int)> x; }\n
111                             """,
112                    msg='Checking for boost signals2 library',
113                    uselib_store='BOOST_SIGNALS2')
114
115     conf.check_cxx(fragment="""
116                             #include <boost/date_time.hpp>\n
117                             int main() { boost::gregorian::day_clock::local_day(); }\n
118                             """,
119                    msg='Checking for boost datetime library',
120                    libpath='/usr/local/lib',
121                    lib=['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
122                    uselib_store='BOOST_DATETIME')
123
124     if not conf.env.DISABLE_TESTS:
125         conf.recurse('test')
126         if not conf.options.disable_gcov:
127             conf.check(lib='gcov', define_name='HAVE_GCOV', mandatory=False)
128     conf.recurse('asdcplib')
129
130 def build(bld):
131     create_version_cc(bld, VERSION)
132
133     if bld.env.TARGET_WINDOWS:
134         boost_lib_suffix = '-mt'
135     else:
136         boost_lib_suffix = ''
137
138     bld(source='libdcp%s.pc.in' % bld.env.API_VERSION,
139         version=VERSION,
140         includedir='%s/include/libdcp%s' % (bld.env.PREFIX, bld.env.API_VERSION),
141         libs="-L${libdir} -ldcp%s -lasdcp-libdcp%s -lkumu-libdcp%s -lcxml -lboost_system%s" % (API_VERSION, bld.env.API_VERSION, bld.env.API_VERSION, boost_lib_suffix),
142         install_path='${LIBDIR}/pkgconfig')
143
144     bld.recurse('src')
145     bld.recurse('tools')
146     if not bld.env.DISABLE_TESTS:
147         bld.recurse('test')
148     bld.recurse('asdcplib')
149     if not bld.env.DISABLE_EXAMPLES:
150         bld.recurse('examples')
151
152     bld.add_post_fun(post)
153
154 def dist(ctx):
155     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
156
157 def create_version_cc(bld, version):
158     if os.path.exists('.git'):
159         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
160         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
161         o = output[0].decode('utf-8')
162         commit = o.replace ("commit ", "")[0:10]
163     else:
164         commit = "release"
165
166     try:
167         text =  '#include "version.h"\n'
168         text += 'char const * dcp::git_commit = \"%s\";\n' % commit
169         text += 'char const * dcp::version = \"%s\";\n' % version
170         if bld.env.ENABLE_DEBUG:
171             debug_string = 'true'
172         else:
173             debug_string = 'false'
174         text += 'bool const dcp::built_with_debug = %s;\n' % debug_string
175         print('Writing version information to src/version.cc')
176         o = open('src/version.cc', 'w')
177         o.write(text)
178         o.close()
179     except IOError:
180         print('Could not open src/version.cc for writing\n')
181         sys.exit(-1)
182
183 def post(ctx):
184     if ctx.cmd == 'install':
185         ctx.exec_command('/sbin/ldconfig')
186
187 def tags(bld):
188     os.system('etags src/*.cc src/*.h')