2 # Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
4 # This file is part of libdcp.
6 # libdcp is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # libdcp is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 # In addition, as a special exception, the copyright holders give
20 # permission to link the code of portions of this program with the
21 # OpenSSL library under certain conditions as described in each
22 # individual source file, and distribute linked combinations
25 # You must obey the GNU General Public License in all respects
26 # for all of the code used other than OpenSSL. If you modify
27 # file(s) with this exception, you may extend this exception to your
28 # version of the file(s), but you are not obligated to do so. If you
29 # do not wish to do so, delete this exception statement from your
30 # version. If you delete this exception statement from all source
31 # files in the program, then also delete it here.
38 import distutils.spawn
39 from waflib import Logs, Context
43 this_version = subprocess.Popen(shlex.split('git tag -l --points-at HEAD'), stdout=subprocess.PIPE).communicate()[0]
44 last_version = subprocess.Popen(shlex.split('git describe --tags --abbrev=0'), stdout=subprocess.PIPE).communicate()[0]
46 if this_version == '':
47 VERSION = '%sdevel' % last_version[1:].strip()
49 VERSION = this_version[1:].strip()
54 opt.load('compiler_cxx')
55 opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to Windows')
56 opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
57 opt.add_option('--static', action='store_true', default=False, help='build libdcp statically, and link statically to openjpeg, cxml, asdcplib-carl')
58 opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
59 opt.add_option('--disable-benchmarks', action='store_true', default=False, help='disable building of benchmarks')
60 opt.add_option('--disable-gcov', action='store_true', default=False, help='don''t use gcov in tests')
61 opt.add_option('--disable-examples', action='store_true', default=False, help='disable building of examples')
62 opt.add_option('--enable-openmp', action='store_true', default=False, help='enable use of OpenMP')
63 opt.add_option('--openmp', default='gomp', help='specify OpenMP Library to use: omp, gomp (default), iomp')
64 opt.add_option('--jpeg', default='oj2', help='specify JPEG library to build with: oj1 or oj2 for OpenJPEG 1.5.x or OpenJPEG 2.1.x respectively')
67 conf.load('compiler_cxx')
68 conf.load('clang_compilation_database', tooldir=['waf-tools'])
69 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS', '-std=c++11'])
70 gcc = conf.env['CC_VERSION']
71 if int(gcc[0]) >= 4 and int(gcc[1]) > 1:
72 conf.env.append_value('CXXFLAGS', ['-Wno-maybe-uninitialized'])
73 conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
75 conf.env.TARGET_WINDOWS = conf.options.target_windows
76 conf.env.TARGET_OSX = sys.platform == 'darwin'
77 conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
78 conf.env.ENABLE_DEBUG = conf.options.enable_debug
79 conf.env.DISABLE_TESTS = conf.options.disable_tests
80 conf.env.DISABLE_BENCHMARKS = conf.options.disable_benchmarks
81 conf.env.DISABLE_EXAMPLES = conf.options.disable_examples
82 conf.env.STATIC = conf.options.static
83 conf.env.API_VERSION = API_VERSION
85 if conf.env.TARGET_WINDOWS:
86 conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
87 if conf.env.TARGET_OSX:
88 conf.env.append_value('CXXFLAGS', '-DLIBDCP_OSX')
89 if conf.env.TARGET_LINUX:
90 conf.env.append_value('CXXFLAGS', '-DLIBDCP_LINUX')
92 if conf.env.TARGET_OSX:
93 conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
94 conf.env.append_value('LINKFLAGS', '-headerpad_max_install_names')
96 # Disable libxml++ deprecation warnings for now
97 conf.env.append_value('CXXFLAGS', ['-Wno-deprecated-declarations'])
99 if conf.options.enable_openmp:
100 conf.env.append_value('CXXFLAGS', ['-fopenmp', '-DLIBDCP_OPENMP'])
101 conf.env.LIB_OPENMP = [conf.options.openmp]
102 conf.env.append_value('LDFLAGS', ['-l%s' % conf.options.openmp])
103 conf.check_cxx(cxxflags='-fopenmp', msg='Checking that compiler supports -fopenmp')
105 if not conf.env.TARGET_WINDOWS:
106 conf.env.append_value('LINKFLAGS', '-pthread')
108 if conf.env.TARGET_LINUX:
109 conf.check(lib='dl', uselib_store='DL', msg='Checking for library dl')
111 if conf.options.jpeg == 'oj1':
112 conf.env.append_value('CXXFLAGS', ['-DLIBDCP_OPENJPEG1'])
113 elif conf.options.jpeg == 'oj2':
114 conf.env.append_value('CXXFLAGS', ['-DLIBDCP_OPENJPEG2'])
116 Logs.error('Invalid --jpeg value %s' % conf.options.jpeg)
118 conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
119 conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='LIBXML++', mandatory=True)
120 conf.check_cfg(package='xmlsec1', args='--cflags --libs', uselib_store='XMLSEC1', mandatory=True)
121 # Remove erroneous escaping of quotes from xmlsec1 defines
122 conf.env.DEFINES_XMLSEC1 = [f.replace('\\', '') for f in conf.env.DEFINES_XMLSEC1]
124 # ImageMagick / GraphicsMagick
125 if distutils.spawn.find_executable('Magick++-config'):
126 conf.check_cfg(package='', path='Magick++-config', args='--cppflags --cxxflags --libs', uselib_store='MAGICK', mandatory=True, msg='Checking for ImageMagick/GraphicsMagick')
128 image = conf.check_cfg(package='ImageMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
129 graphics = conf.check_cfg(package='GraphicsMagick++', args='--cflags --libs', uselib_store='MAGICK', mandatory=False)
130 if image is None and graphics is None:
131 Logs.error('Neither ImageMagick++ nor GraphicsMagick++ found: one or the other is required')
133 conf.check_cfg(package='sndfile', args='--cflags --libs', uselib_store='SNDFILE', mandatory=False)
135 if conf.options.static:
136 if conf.options.jpeg == 'oj2':
137 conf.check_cfg(package='libopenjp2', args='--cflags', atleast_version='2.1.0', uselib_store='OPENJPEG', mandatory=True)
138 conf.env.STLIB_OPENJPEG = ['openjp2']
139 elif conf.options.jpeg == 'oj1':
140 conf.check_cfg(package='libopenjpeg1', args='--cflags', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
141 conf.env.STLIB_OPENJPEG = ['openjpeg']
142 conf.check_cfg(package='libasdcp-carl', atleast_version='0.1.3', args='--cflags', uselib_store='ASDCPLIB_CTH', mandatory=True)
143 conf.env.HAVE_ASDCPLIB_CTH = 1
144 conf.env.STLIB_ASDCPLIB_CTH = ['asdcp-carl', 'kumu-carl']
145 conf.env.HAVE_CXML = 1
146 conf.env.LIB_CXML = ['xml++-2.6', 'glibmm-2.4']
147 conf.env.STLIB_CXML = ['cxml']
148 conf.check_cfg(package='xerces-c', args='--cflags', uselib_store='XERCES', mandatory=True)
149 conf.env.LIB_XERCES = ['xerces-c', 'icuuc', 'curl']
151 if conf.options.jpeg == 'oj2':
152 conf.check_cfg(package='libopenjp2', args='--cflags --libs', atleast_version='2.1.0', uselib_store='OPENJPEG', mandatory=True)
153 elif conf.options.jpeg == 'oj1':
154 conf.check_cfg(package='libopenjpeg1', args='--cflags --libs', atleast_version='1.5.0', uselib_store='OPENJPEG', mandatory=True)
155 conf.check_cfg(package='libasdcp-carl', atleast_version='0.1.3', args='--cflags --libs', uselib_store='ASDCPLIB_CTH', mandatory=True)
156 conf.check_cfg(package='libcxml', atleast_version='0.17.0', args='--cflags --libs', uselib_store='CXML', mandatory=True)
157 conf.check_cfg(package='xerces-c', args='--cflags --libs', uselib_store='XERCES', mandatory=True)
159 if conf.options.target_windows:
160 # XXX: it feels like there should be a more elegant way to get these included
161 conf.env.LIB_XERCES.append('curl')
162 conf.env.LIB_XERCES.append('ws2_32')
164 if conf.options.target_windows:
165 boost_lib_suffix = '-mt'
167 boost_lib_suffix = ''
169 if conf.options.enable_debug:
170 conf.env.append_value('CXXFLAGS', '-g')
172 # Somewhat experimental use of -O2 rather than -O3 to see if
173 # Windows builds are any more reliable
174 conf.env.append_value('CXXFLAGS', '-O2')
176 # We support older boosts on Linux so we can use the distribution-provided package
177 # on Centos 7, but it's good if we can use 1.61 for boost::dll::program_location()
178 boost_version = ('1.45', '104500') if conf.env.TARGET_LINUX else ('1.61', '106800')
180 conf.check_cxx(fragment="""
181 #include <boost/version.hpp>\n
182 #if BOOST_VERSION < %s\n
183 #error boost too old\n
185 int main(void) { return 0; }\n
186 """ % boost_version[1],
188 msg='Checking for boost library >= %s' % boost_version[0],
190 errmsg='too old\nPlease install boost version %s or higher.' % boost_version[0])
192 conf.check_cxx(fragment="""
193 #include <boost/filesystem.hpp>\n
194 int main() { boost::filesystem::copy_file ("a", "b"); }\n
196 msg='Checking for boost filesystem library',
197 libpath='/usr/local/lib',
198 lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
199 uselib_store='BOOST_FILESYSTEM')
201 conf.check_cxx(fragment="""
202 #include <boost/signals2.hpp>\n
203 int main() { boost::signals2::signal<void (int)> x; }\n
205 msg='Checking for boost signals2 library',
206 uselib_store='BOOST_SIGNALS2')
208 conf.check_cxx(fragment="""
209 #include <boost/date_time.hpp>\n
210 int main() { boost::gregorian::day_clock::local_day(); }\n
212 msg='Checking for boost datetime library',
213 libpath='/usr/local/lib',
214 lib=['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
215 uselib_store='BOOST_DATETIME')
217 if not conf.env.DISABLE_TESTS:
219 if not conf.options.disable_gcov:
220 conf.check(lib='gcov', define_name='HAVE_GCOV', mandatory=False)
221 conf.env.append_value('LINKFLAGS', '-fprofile-arcs')
224 create_version_cc(bld, VERSION)
226 if bld.env.TARGET_WINDOWS:
227 boost_lib_suffix = '-mt'
229 boost_lib_suffix = ''
231 libs="-L${libdir} -ldcp%s -lcxml -lboost_system%s" % (bld.env.API_VERSION, boost_lib_suffix)
232 if bld.env.TARGET_LINUX:
235 bld(source='libdcp%s.pc.in' % bld.env.API_VERSION,
237 includedir='%s/include/libdcp%s' % (bld.env.PREFIX, bld.env.API_VERSION),
239 install_path='${LIBDIR}/pkgconfig')
243 if not bld.env.DISABLE_TESTS:
245 if not bld.env.DISABLE_EXAMPLES:
246 bld.recurse('examples')
247 if not bld.env.DISABLE_BENCHMARKS:
248 bld.recurse('benchmark')
250 for i in os.listdir('xsd'):
251 bld.install_files('${PREFIX}/share/libdcp/xsd', os.path.join('xsd', i))
253 for i in ['language', 'region', 'script', 'variant', 'extlang', 'dcnc']:
254 bld.install_files('${PREFIX}/share/libdcp/tags', os.path.join('tags', i))
256 bld.add_post_fun(post)
259 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
261 def create_version_cc(bld, version):
262 if os.path.exists('.git'):
263 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
264 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
265 o = output[0].decode('utf-8')
266 commit = o.replace ("commit ", "")[0:10]
271 text = '#include "version.h"\n'
272 text += 'char const * dcp::git_commit = \"%s\";\n' % commit
273 text += 'char const * dcp::version = \"%s\";\n' % version
274 if bld.env.ENABLE_DEBUG:
275 debug_string = 'true'
277 debug_string = 'false'
278 text += 'bool const dcp::built_with_debug = %s;\n' % debug_string
279 print('Writing version information to src/version.cc')
280 o = open('src/version.cc', 'w')
284 print('Could not open src/version.cc for writing\n')
288 if ctx.cmd == 'install':
289 ctx.exec_command('/sbin/ldconfig')
292 os.system('etags src/*.cc src/*.h')