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