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')
15 conf.load('compiler_cxx')
16 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-O2', '-D_FILE_OFFSET_BITS=64'])
17 conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
19 conf.env.TARGET_WINDOWS = conf.options.target_windows
20 conf.env.STATIC = conf.options.static
21 conf.env.OSX = conf.options.osx
22 conf.env.ENABLE_DEBUG = conf.options.enable_debug
24 if conf.options.target_windows:
25 conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
27 conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
29 if not conf.options.osx:
30 conf.env.append_value('CXXFLAGS', ['-Wno-unused-result'])
32 conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
33 conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
34 conf.check_cfg(package = 'xmlsec1', args = '--cflags --libs', uselib_store = 'XMLSEC1', mandatory = True)
35 # Remove erroneous escaping of quotes from xmlsec1 defines
36 conf.env.DEFINES_XMLSEC1 = [f.replace('\\', '') for f in conf.env.DEFINES_XMLSEC1]
38 if conf.options.static:
39 conf.check_cc(fragment = """
41 #include <openjpeg.h>\n
43 void* p = (void *) opj_image_create;\n
47 msg = 'Checking for library openjpeg', stlib = 'openjpeg', uselib_store = 'OPENJPEG', mandatory = True)
49 conf.env.HAVE_CXML = 1
50 conf.env.STLIB_CXML = ['cxml']
52 conf.check_cfg(package = 'libopenjpeg', args = '--cflags --libs', uselib_store = 'OPENJPEG', mandatory = True)
53 conf.check_cfg(package = 'libcxml', args = '--cflags --libs', uselib_store = 'CXML', mandatory = True)
55 if conf.options.target_windows:
56 boost_lib_suffix = '-mt'
60 if conf.options.enable_debug:
61 conf.env.append_value('CXXFLAGS', '-g')
63 # Somewhat experimental use of -O2 rather than -O3 to see if
64 # Windows builds are any more reliable
65 conf.env.append_value('CXXFLAGS', '-O2')
67 conf.check_cxx(fragment = """
68 #include <boost/version.hpp>\n
69 #if BOOST_VERSION < 104500\n
70 #error boost too old\n
72 int main(void) { return 0; }\n
75 msg = 'Checking for boost library >= 1.45',
77 errmsg = 'too old\nPlease install boost version 1.45 or higher.')
79 conf.check_cxx(fragment = """
80 #include <boost/filesystem.hpp>\n
81 int main() { boost::filesystem::copy_file ("a", "b"); }\n
83 msg = 'Checking for boost filesystem library',
84 libpath = '/usr/local/lib',
85 lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
86 uselib_store = 'BOOST_FILESYSTEM')
88 conf.check_cxx(fragment = """
89 #include <boost/signals2.hpp>\n
90 int main() { boost::signals2::signal<void (int)> x; }\n
92 msg = 'Checking for boost signals2 library',
93 uselib_store = 'BOOST_SIGNALS2')
95 conf.check_cxx(fragment = """
96 #include <boost/date_time.hpp>\n
97 int main() { boost::gregorian::day_clock::local_day(); }\n
99 msg = 'Checking for boost datetime library',
100 libpath = '/usr/local/lib',
101 lib = ['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
102 uselib_store = 'BOOST_DATETIME')
105 conf.recurse('asdcplib')
108 create_version_cc(bld, VERSION)
110 if bld.env.TARGET_WINDOWS:
111 boost_lib_suffix = '-mt'
113 boost_lib_suffix = ''
115 bld(source = 'libdcp.pc.in',
117 includedir = '%s/include' % bld.env.PREFIX,
118 libs = "-L${libdir} -ldcp -lasdcp-libdcp -lkumu-libdcp -lboost_system%s" % boost_lib_suffix,
119 install_path = '${LIBDIR}/pkgconfig')
124 bld.recurse('asdcplib')
125 bld.recurse('examples')
127 bld.add_post_fun(post)
130 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
132 def create_version_cc(bld, version):
133 if os.path.exists('.git'):
134 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
135 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
136 o = output[0].decode('utf-8')
137 commit = o.replace ("commit ", "")[0:10]
142 text = '#include "version.h"\n'
143 text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
144 text += 'char const * libdcp::version = \"%s\";\n' % version
145 if bld.env.ENABLE_DEBUG:
146 debug_string = 'true'
148 debug_string = 'false'
149 text += 'bool const built_with_debug = %s;\n' % debug_string
150 print('Writing version information to src/version.cc')
151 o = open('src/version.cc', 'w')
155 print('Could not open src/version.cc for writing\n')
159 if ctx.cmd == 'install':
160 ctx.exec_command('/sbin/ldconfig')