Some platforms don't even have libxml++ version defines.
[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].decode('UTF-8')
28 last_version = subprocess.Popen(shlex.split('git describe --tags --abbrev=0'), stdout=subprocess.PIPE).communicate()[0].decode('UTF-8')
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-64', action='store_true', default=False, help='set up to do a cross-compile to Windows 64-bit')
40     opt.add_option('--target-windows-32', action='store_true', default=False, help='set up to do a cross-compile to Windows 32-bit')
41     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
42     opt.add_option('--static', action='store_true', default=False, help='build statically')
43     opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
44     opt.add_option('--c++17', action='store_true', default=False, help='build with C++17 and libxml++-4.0')
45
46 def configure(conf):
47     conf.load('compiler_cxx')
48
49     if vars(conf.options)['c++17']:
50         cpp_std = '17'
51         conf.env.XMLPP_API = '4.0'
52         conf.env.GLIBMM_API = '2.68'
53     else:
54         cpp_std = '11'
55         conf.env.XMLPP_API = '2.6'
56         conf.env.GLIBMM_API = '2.4'
57
58     if conf.options.enable_debug:
59         conf.env.append_value('CXXFLAGS', '-g')
60     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-O2', '-Wno-deprecated-declarations', '-std=c++' + cpp_std, '-DBOOST_NO_CXX11_SCOPED_ENUMS'])
61
62     conf.env.TARGET_WINDOWS = conf.options.target_windows_32 or conf.options.target_windows_64
63     conf.env.STATIC = conf.options.static
64     conf.env.DISABLE_TESTS = conf.options.disable_tests
65     conf.env.API_VERSION = API_VERSION
66
67     if conf.env.TARGET_WINDOWS:
68         boost_lib_suffix = '-mt-x32' if conf.options.target_windows_32 else '-mt-x64'
69         conf.env.append_value('CXXFLAGS', '-DLIBCXML_WINDOWS')
70     else:
71         boost_lib_suffix = ''
72         conf.env.append_value('CXXFLAGS', '-DLIBCXML_POSIX')
73
74     conf.check_cfg(package='libxml++-' + conf.env.XMLPP_API, args='--cflags --libs', uselib_store='LIBXML++', mandatory=True)
75
76     conf.check_cxx(fragment="""
77                    #include <boost/filesystem.hpp>\n
78                    int main() { boost::filesystem::copy_file ("a", "b"); }\n
79                    """,
80                    msg='Checking for boost filesystem library',
81                    libpath='/usr/local/lib',
82                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
83                    uselib_store='BOOST_FILESYSTEM')
84
85     if not conf.options.disable_tests:
86         conf.check_cxx(fragment="""
87                                   #define BOOST_TEST_MODULE Config test\n
88                                   #include <boost/test/unit_test.hpp>\n
89                                   int main() {}
90                                   """,
91                                   msg='Checking for boost unit testing library',
92                                   lib=['boost_unit_test_framework%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
93                                   uselib_store='BOOST_TEST')
94
95         conf.recurse('test')
96
97 def build(bld):
98     bld(source='libcxml.pc.in',
99         version=VERSION,
100         includedir='%s/include' % bld.env.PREFIX,
101         libs="-L${libdir} -lcxml",
102         install_path='${LIBDIR}/pkgconfig',
103         xmlpp_api=bld.env.XMLPP_API,
104         glibmm_api=bld.env.GLIBMM_API)
105
106     bld.recurse('src')
107     if not bld.env.DISABLE_TESTS:
108         bld.recurse('test')