4430532cea020ea065288e9835fe9771f49948b6
[libcxml.git] / wscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
4 #
5 #    This file is part of libcxml.
6 #
7 #    libcxml is free software; you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation; either version 2 of the License, or
10 #    (at your option) any later version.
11 #
12 #    libcxml is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with libcxml.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 from waflib import Context
22
23 APPNAME = 'libcxml'
24 VERSION = '0.15.1devel'
25 API_VERSION = '0.0.0'
26
27 def options(opt):
28     opt.load('compiler_cxx')
29     opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to Windows')
30     opt.add_option('--static', action='store_true', default=False, help='build statically')
31     opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
32
33 def configure(conf):
34     conf.load('compiler_cxx')
35     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-O2'])
36
37     conf.env.TARGET_WINDOWS = conf.options.target_windows
38     conf.env.STATIC = conf.options.static
39     conf.env.DISABLE_TESTS = conf.options.disable_tests
40     conf.env.API_VERSION = API_VERSION
41
42     if conf.options.target_windows:
43         boost_lib_suffix = '-mt'
44     else:
45         boost_lib_suffix = ''
46
47     conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='LIBXML++', mandatory=True)
48     conf.check_cfg(package='locked_sstream', args='--cflags --libs', uselib_store='LOCKED_SSTREAM', mandatory=True)
49
50     conf.check_cxx(fragment="""
51                    #include <boost/filesystem.hpp>\n
52                    int main() { boost::filesystem::copy_file ("a", "b"); }\n
53                    """,
54                    msg='Checking for boost filesystem library',
55                    libpath='/usr/local/lib',
56                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
57                    uselib_store='BOOST_FILESYSTEM')
58
59     if not conf.options.disable_tests:
60         conf.check_cxx(fragment="""
61                                   #define BOOST_TEST_MODULE Config test\n
62                                   #include <boost/test/unit_test.hpp>\n
63                                   int main() {}
64                                   """,
65                                   msg='Checking for boost unit testing library',
66                                   lib=['boost_unit_test_framework%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
67                                   uselib_store='BOOST_TEST')
68
69         conf.recurse('test')
70
71     # libxml++ 2.39.1 and later must be built with -std=c++11
72     libxmlpp_version = conf.cmd_and_log(['pkg-config', '--modversion', 'libxml++-2.6'], output=Context.STDOUT, quiet=Context.BOTH)
73     s = libxmlpp_version.split('.')
74     v = (int(s[0]) << 16) | (int(s[1]) << 8) | int(s[2])
75     if v >= 0x022701:
76         conf.env.append_value('CXXFLAGS', '-std=c++11')
77
78 def build(bld):
79
80     bld(source='libcxml.pc.in',
81         version=VERSION,
82         includedir='%s/include' % bld.env.PREFIX,
83         libs="-L${libdir} -lcxml",
84         install_path='${LIBDIR}/pkgconfig')
85
86     bld.recurse('src')
87     if not bld.env.DISABLE_TESTS:
88         bld.recurse('test')