365a8c1ee4f20f11217b315bbd1986757c980cd1
[asdcplib-cth.git] / wscript
1 import subprocess
2 import os
3 import sys
4 import distutils.spawn
5 from waflib import Logs
6
7 APPNAME = 'libasdcp-cth'
8 VERSION = '0.1.2devel'
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 statically')
15
16 def configure(conf):
17     conf.load('compiler_cxx')
18     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
19
20     conf.env.TARGET_WINDOWS = conf.options.target_windows
21     conf.env.TARGET_OSX = sys.platform == 'darwin'
22     conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
23     conf.env.STATIC = conf.options.static
24     conf.env.VERSION = VERSION
25
26     if conf.env.TARGET_OSX:
27         conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
28
29     if conf.env.TARGET_LINUX:
30         gcc = conf.env['CC_VERSION']
31         if int(gcc[0]) >= 4 and int(gcc[1]) > 1:
32             conf.env.append_value('CXXFLAGS', ['-Wno-unused-result'])
33
34     conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
35
36     if conf.options.target_windows:
37         boost_lib_suffix = '-mt'
38     else:
39         boost_lib_suffix = ''
40
41     if conf.options.enable_debug:
42         conf.env.append_value('CXXFLAGS', '-g')
43     else:
44         conf.env.append_value('CXXFLAGS', '-O2')
45
46     conf.check_cxx(fragment="""
47                             #include <boost/version.hpp>\n
48                             #if BOOST_VERSION < 104500\n
49                             #error boost too old\n
50                             #endif\n
51                             int main(void) { return 0; }\n
52                             """,
53                    mandatory=True,
54                    msg='Checking for boost library >= 1.45',
55                    okmsg='yes',
56                    errmsg='too old\nPlease install boost version 1.45 or higher.')
57
58     conf.check_cxx(fragment="""
59                             #include <boost/filesystem.hpp>\n
60                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
61                             """,
62                    msg='Checking for boost filesystem library',
63                    libpath='/usr/local/lib',
64                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
65                    uselib_store='BOOST_FILESYSTEM')
66
67     conf.recurse('src')
68
69 def build(bld):
70     if bld.env.TARGET_WINDOWS:
71         boost_lib_suffix = '-mt'
72         flags = '-DKM_WIN32'
73     else:
74         boost_lib_suffix = ''
75         flags = ''
76
77     bld(source='libasdcp-cth.pc.in',
78         version=VERSION,
79         includedir='%s/include/libasdcp-cth' % bld.env.PREFIX,
80         libs="-L${libdir} -lasdcp-cth -lkumu-cth -lboost_system%s" % boost_lib_suffix,
81         cflags=flags,
82         install_path='${LIBDIR}/pkgconfig')
83
84     bld.recurse('src')
85
86     bld.add_post_fun(post)
87
88 def post(ctx):
89     if ctx.cmd == 'install':
90         ctx.exec_command('/sbin/ldconfig')
91
92 def tags(bld):
93     os.system('etags src/*.cc src/*.h')