Fix tests on platforms that statically-link boost.
[libcxml.git] / wscript
1 # -*- mode: python -*-
2 #
3 #    Copyright (C) 2016-2018 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 import subprocess
22 import shlex
23 from waflib import Context
24
25 APPNAME = 'libcxml'
26
27 this_version = subprocess.Popen(shlex.split('git tag -l --points-at HEAD'), stdout=subprocess.PIPE).communicate()[0]
28 last_version = subprocess.Popen(shlex.split('git describe --tags --abbrev=0'), stdout=subprocess.PIPE).communicate()[0]
29
30 if this_version == '':
31     VERSION = '%sdevel' % last_version[1:].strip()
32 else:
33     VERSION = this_version[1:].strip()
34
35 API_VERSION = '0.0.0'
36
37 def options(opt):
38     opt.load('compiler_cxx')
39     opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to Windows')
40     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
41     opt.add_option('--static', action='store_true', default=False, help='build statically')
42     opt.add_option('--static-boost-test', action='store_true', default=False, help='boost test library will be statically linked')
43
44 def configure(conf):
45     conf.load('compiler_cxx')
46     if conf.options.enable_debug:
47         conf.env.append_value('CXXFLAGS', '-g')
48     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-O2', '-Wno-deprecated-declarations', '-std=c++11', '-DBOOST_NO_CXX11_SCOPED_ENUMS'])
49
50     conf.env.TARGET_WINDOWS = conf.options.target_windows
51     conf.env.STATIC = conf.options.static
52     conf.env.API_VERSION = API_VERSION
53
54     if conf.options.target_windows:
55         boost_lib_suffix = '-mt'
56         conf.env.append_value('CXXFLAGS', '-DLIBCXML_WINDOWS')
57     else:
58         boost_lib_suffix = ''
59         conf.env.append_value('CXXFLAGS', '-DLIBCXML_POSIX')
60
61     if not conf.options.static_boost_test:
62         conf.env.append_value('CXXFLAGS', '-DBOOST_TEST_DYN_LINK')
63
64     conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='LIBXML++', mandatory=True)
65
66     conf.check_cxx(fragment="""
67                    #include <boost/filesystem.hpp>\n
68                    int main() { boost::filesystem::copy_file ("a", "b"); }\n
69                    """,
70                    msg='Checking for boost filesystem library',
71                    libpath='/usr/local/lib',
72                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
73                    uselib_store='BOOST_FILESYSTEM')
74
75     conf.check_cxx(fragment="""
76                               #define BOOST_TEST_MODULE Config test\n
77                            #include <boost/test/unit_test.hpp>\n
78                               int main() {}
79                               """,
80                               msg='Checking for boost unit testing library',
81                               lib=['boost_unit_test_framework%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
82                               uselib_store='BOOST_TEST')
83
84     conf.recurse('test')
85
86 def build(bld):
87
88     bld(source='libcxml.pc.in',
89         version=VERSION,
90         includedir='%s/include' % bld.env.PREFIX,
91         libs="-L${libdir} -lcxml",
92         install_path='${LIBDIR}/pkgconfig')
93
94     bld.recurse('src')
95     bld.recurse('test')