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')
13 opt.add_option('--valgrind', action='store_true', default=False, help='build with instructions to Valgrind to reduce false positives')
16 conf.load('compiler_cxx')
17 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
18 conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
20 conf.env.TARGET_WINDOWS = conf.options.target_windows
21 conf.env.STATIC = conf.options.static
22 conf.env.OSX = conf.options.osx
23 conf.env.ENABLE_DEBUG = conf.options.enable_debug
25 if conf.options.target_windows:
26 conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
28 conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
30 if conf.options.valgrind:
31 conf.env.append_value('CXXFLAGS', '-DLIBDCP_VALGRIND')
33 if not conf.options.osx:
34 conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter'])
36 conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
37 conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
38 conf.check_cfg(package = 'xmlsec1', args = '--cflags --libs', uselib_store = 'XMLSEC1', mandatory = True)
39 # Remove erroneous escaping of quotes from xmlsec1 defines
40 conf.env.DEFINES_XMLSEC1 = [f.replace('\\', '') for f in conf.env.DEFINES_XMLSEC1]
42 if conf.options.static:
43 conf.check_cc(fragment = """
45 #include <openjpeg.h>\n
47 void* p = (void *) opj_image_create;\n
51 msg = 'Checking for library openjpeg', stlib = 'openjpeg', uselib_store = 'OPENJPEG', mandatory = True)
53 conf.env.HAVE_CXML = 1
54 conf.env.STLIB_CXML = ['cxml']
56 conf.check_cfg(package='libopenjpeg', args='--cflags --libs', uselib_store='OPENJPEG', mandatory=True)
57 conf.check_cfg(package='libcxml', atleast_version='0.08', args='--cflags --libs', uselib_store='CXML', mandatory=True)
59 if conf.options.target_windows:
60 boost_lib_suffix = '-mt'
64 if conf.options.enable_debug:
65 conf.env.append_value('CXXFLAGS', '-g')
67 # Somewhat experimental use of -O2 rather than -O3 to see if
68 # Windows builds are any more reliable
69 conf.env.append_value('CXXFLAGS', '-O2')
71 conf.check_cxx(fragment = """
72 #include <boost/version.hpp>\n
73 #if BOOST_VERSION < 104500\n
74 #error boost too old\n
76 int main(void) { return 0; }\n
79 msg = 'Checking for boost library >= 1.45',
81 errmsg = 'too old\nPlease install boost version 1.45 or higher.')
83 conf.check_cxx(fragment = """
84 #include <boost/filesystem.hpp>\n
85 int main() { boost::filesystem::copy_file ("a", "b"); }\n
87 msg = 'Checking for boost filesystem library',
88 libpath = '/usr/local/lib',
89 lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
90 uselib_store = 'BOOST_FILESYSTEM')
92 conf.check_cxx(fragment = """
93 #include <boost/signals2.hpp>\n
94 int main() { boost::signals2::signal<void (int)> x; }\n
96 msg = 'Checking for boost signals2 library',
97 uselib_store = 'BOOST_SIGNALS2')
99 conf.check_cxx(fragment = """
100 #include <boost/date_time.hpp>\n
101 int main() { boost::gregorian::day_clock::local_day(); }\n
103 msg = 'Checking for boost datetime library',
104 libpath = '/usr/local/lib',
105 lib = ['boost_date_time%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
106 uselib_store = 'BOOST_DATETIME')
109 conf.recurse('asdcplib')
112 create_version_cc(bld, VERSION)
114 if bld.env.TARGET_WINDOWS:
115 boost_lib_suffix = '-mt'
117 boost_lib_suffix = ''
119 bld(source = 'libdcp.pc.in',
121 includedir = '%s/include' % bld.env.PREFIX,
122 libs = "-L${libdir} -ldcp -lasdcp-libdcp -lkumu-libdcp -lcxml -lboost_system%s" % boost_lib_suffix,
123 install_path = '${LIBDIR}/pkgconfig')
128 bld.recurse('asdcplib')
129 bld.recurse('examples')
131 bld.add_post_fun(post)
134 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
136 def create_version_cc(bld, version):
137 if os.path.exists('.git'):
138 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
139 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
140 o = output[0].decode('utf-8')
141 commit = o.replace ("commit ", "")[0:10]
146 text = '#include "version.h"\n'
147 text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
148 text += 'char const * libdcp::version = \"%s\";\n' % version
149 if bld.env.ENABLE_DEBUG:
150 debug_string = 'true'
152 debug_string = 'false'
153 text += 'bool const built_with_debug = %s;\n' % debug_string
154 print('Writing version information to src/version.cc')
155 o = open('src/version.cc', 'w')
159 print('Could not open src/version.cc for writing\n')
163 if ctx.cmd == 'install':
164 ctx.exec_command('/sbin/ldconfig')