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