build: pass pkg_config_path to check_cfg() when looking for libndn-cxx

Instead of modifying os.environ.

This commit also updates some waf tools and fixes the value of
includedir in the generated .pc file.

Refs: #5042
Change-Id: Idf0481f36664cc085571265747a004655001c0ed
This commit is contained in:
Davide Pesavento
2019-11-09 17:25:09 -05:00
parent a1ad604672
commit c47774fd95
4 changed files with 89 additions and 76 deletions
+51 -40
View File
@@ -56,6 +56,7 @@ from waflib.TaskGen import feature, after_method
BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib'] BOOST_LIBS = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/sw/lib', '/lib']
BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include'] BOOST_INCLUDES = ['/usr/include', '/usr/local/include', '/opt/local/include', '/sw/include']
BOOST_VERSION_FILE = 'boost/version.hpp' BOOST_VERSION_FILE = 'boost/version.hpp'
BOOST_VERSION_CODE = ''' BOOST_VERSION_CODE = '''
#include <iostream> #include <iostream>
@@ -90,13 +91,18 @@ int main() { boost::thread t; }
BOOST_LOG_CODE = ''' BOOST_LOG_CODE = '''
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
int main() { BOOST_LOG_TRIVIAL(info) << "boost_log is working"; }
'''
BOOST_LOG_SETUP_CODE = '''
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/console.hpp> #include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp> #include <boost/log/utility/setup/common_attributes.hpp>
int main() { int main() {
using namespace boost::log; using namespace boost::log;
add_common_attributes(); add_common_attributes();
add_console_log(std::clog, keywords::format = "%Message%"); add_console_log(std::clog, keywords::format = "%Message%");
BOOST_LOG_TRIVIAL(debug) << "log is working" << std::endl; BOOST_LOG_TRIVIAL(info) << "boost_log_setup is working";
} }
''' '''
@@ -145,7 +151,7 @@ def options(opt):
opt.add_option('--boost-abi', type='string', default='', dest='boost_abi', opt.add_option('--boost-abi', type='string', default='', dest='boost_abi',
help='''select libraries with tags (gd for debug, static is automatically added), help='''select libraries with tags (gd for debug, static is automatically added),
see doc Boost, Getting Started, chapter 6.1''') see doc Boost, Getting Started, chapter 6.1''')
opt.add_option('--boost-linkage_autodetect', action="store_true", dest='boost_linkage_autodetect', opt.add_option('--boost-linkage_autodetect', action='store_true', dest='boost_linkage_autodetect',
help="auto-detect boost linkage options (don't get used to it / might break other stuff)") help="auto-detect boost linkage options (don't get used to it / might break other stuff)")
opt.add_option('--boost-toolset', type='string', opt.add_option('--boost-toolset', type='string',
default='', dest='boost_toolset', default='', dest='boost_toolset',
@@ -175,7 +181,7 @@ def boost_get_version(self, d):
try: try:
txt = node.read() txt = node.read()
except EnvironmentError: except EnvironmentError:
Logs.error("Could not read the file %r" % node.abspath()) Logs.error('Could not read the file %r' % node.abspath())
else: else:
re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M) re_but1 = re.compile('^#define\\s+BOOST_LIB_VERSION\\s+"(.+)"', re.M)
m1 = re_but1.search(txt) m1 = re_but1.search(txt)
@@ -183,7 +189,7 @@ def boost_get_version(self, d):
m2 = re_but2.search(txt) m2 = re_but2.search(txt)
if m1 and m2: if m1 and m2:
return (m1.group(1), m2.group(1)) return (m1.group(1), m2.group(1))
return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(":") return self.check_cxx(fragment=BOOST_VERSION_CODE, includes=[d], execute=True, define_ret=True).split(':')
@conf @conf
def boost_get_includes(self, *k, **kw): def boost_get_includes(self, *k, **kw):
@@ -194,10 +200,10 @@ def boost_get_includes(self, *k, **kw):
if self.__boost_get_version_file(d): if self.__boost_get_version_file(d):
return d return d
if includes: if includes:
self.end_msg('headers not found in %s' % includes) self.end_msg('headers not found in %s' % includes, 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
else: else:
self.end_msg('headers not found, please provide a --boost-includes argument (see help)') self.end_msg('headers not found, please provide a --boost-includes argument (see help)', 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
@@ -240,10 +246,10 @@ def __boost_get_libs_path(self, *k, **kw):
break break
if not path: if not path:
if libs: if libs:
self.end_msg('libs not found in %s' % libs) self.end_msg('libs not found in %s' % libs, 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
else: else:
self.end_msg('libs not found, please provide a --boost-libs argument (see help)') self.end_msg('libs not found, please provide a --boost-libs argument (see help)', 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
self.to_log('Found the boost path in %r with the libraries:' % path) self.to_log('Found the boost path in %r with the libraries:' % path)
@@ -313,7 +319,7 @@ def boost_get_libs(self, *k, **kw):
libs.append(format_lib_name(file.name)) libs.append(format_lib_name(file.name))
break break
else: else:
self.end_msg('lib %s not found in %s' % (lib, path.abspath())) self.end_msg('lib %s not found in %s' % (lib, path.abspath()), 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
return libs return libs
@@ -354,7 +360,7 @@ def _check_pthread_flag(self, *k, **kw):
# ... -mt is also the pthreads flag for HP/aCC # ... -mt is also the pthreads flag for HP/aCC
# -lpthread: GNU Linux, etc. # -lpthread: GNU Linux, etc.
# --thread-safe: KAI C++ # --thread-safe: KAI C++
if Utils.unversioned_sys_platform() == "sunos": if Utils.unversioned_sys_platform() == 'sunos':
# On Solaris (at least, for some versions), libc contains stubbed # On Solaris (at least, for some versions), libc contains stubbed
# (non-functional) versions of the pthreads routines, so link-based # (non-functional) versions of the pthreads routines, so link-based
# tests will erroneously succeed. (We need to link with -pthreads/-mt/ # tests will erroneously succeed. (We need to link with -pthreads/-mt/
@@ -362,23 +368,22 @@ def _check_pthread_flag(self, *k, **kw):
# a function called by this macro, so we could check for that, but # a function called by this macro, so we could check for that, but
# who knows whether they'll stub that too in a future libc.) So, # who knows whether they'll stub that too in a future libc.) So,
# we'll just look for -pthreads and -lpthread first: # we'll just look for -pthreads and -lpthread first:
boost_pthread_flags = ["-pthreads", "-lpthread", "-mt", "-pthread"] boost_pthread_flags = ['-pthreads', '-lpthread', '-mt', '-pthread']
else: else:
boost_pthread_flags = ["", "-lpthreads", "-Kthread", "-kthread", "-llthread", "-pthread", boost_pthread_flags = ['', '-lpthreads', '-Kthread', '-kthread', '-llthread', '-pthread',
"-pthreads", "-mthreads", "-lpthread", "--thread-safe", "-mt"] '-pthreads', '-mthreads', '-lpthread', '--thread-safe', '-mt']
for boost_pthread_flag in boost_pthread_flags: for boost_pthread_flag in boost_pthread_flags:
try: try:
self.env.stash() self.env.stash()
self.env['CXXFLAGS_%s' % var] += [boost_pthread_flag] self.env['CXXFLAGS_%s' % var] += [boost_pthread_flag]
self.env['LINKFLAGS_%s' % var] += [boost_pthread_flag] self.env['LINKFLAGS_%s' % var] += [boost_pthread_flag]
self.check_cxx(code=PTHREAD_CODE, msg=None, use=var, execute=False) self.check_cxx(code=PTHREAD_CODE, msg=None, use=var, execute=False, quiet=True)
self.end_msg(boost_pthread_flag) self.end_msg(boost_pthread_flag)
return return
except self.errors.ConfigurationError: except self.errors.ConfigurationError:
self.env.revert() self.env.revert()
self.end_msg('None') self.end_msg('none')
@conf @conf
def check_boost(self, *k, **kw): def check_boost(self, *k, **kw):
@@ -403,21 +408,24 @@ def check_boost(self, *k, **kw):
var = kw.get('uselib_store', 'BOOST') var = kw.get('uselib_store', 'BOOST')
self.find_program('dpkg-architecture', var='DPKG_ARCHITECTURE', mandatory=False) if not self.env.DONE_FIND_BOOST_COMMON:
if self.env.DPKG_ARCHITECTURE: self.find_program('dpkg-architecture', var='DPKG_ARCHITECTURE', mandatory=False)
deb_host_multiarch = self.cmd_and_log([self.env.DPKG_ARCHITECTURE[0], '-qDEB_HOST_MULTIARCH']) if self.env.DPKG_ARCHITECTURE:
BOOST_LIBS.insert(0, '/usr/lib/%s' % deb_host_multiarch.strip()) deb_host_multiarch = self.cmd_and_log([self.env.DPKG_ARCHITECTURE[0], '-qDEB_HOST_MULTIARCH'])
BOOST_LIBS.insert(0, '/usr/lib/%s' % deb_host_multiarch.strip())
self.start_msg('Checking boost includes') self.start_msg('Checking boost includes')
self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params) self.env['INCLUDES_%s' % var] = inc = self.boost_get_includes(**params)
versions = self.boost_get_version(inc) versions = self.boost_get_version(inc)
self.env.BOOST_VERSION = versions[0] self.env.BOOST_VERSION = versions[0]
self.env.BOOST_VERSION_NUMBER = int(versions[1]) self.env.BOOST_VERSION_NUMBER = int(versions[1])
self.end_msg("%d.%d.%d" % (int(versions[1]) / 100000, self.end_msg('%d.%d.%d' % (int(versions[1]) / 100000,
int(versions[1]) / 100 % 1000, int(versions[1]) / 100 % 1000,
int(versions[1]) % 100)) int(versions[1]) % 100))
if Logs.verbose: if Logs.verbose:
Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var]) Logs.pprint('CYAN', ' path : %s' % self.env['INCLUDES_%s' % var])
self.env.DONE_FIND_BOOST_COMMON = True
if not params['lib'] and not params['stlib']: if not params['lib'] and not params['stlib']:
return return
@@ -429,7 +437,7 @@ def check_boost(self, *k, **kw):
self.env['STLIBPATH_%s' % var] = [path] self.env['STLIBPATH_%s' % var] = [path]
self.env['LIB_%s' % var] = libs self.env['LIB_%s' % var] = libs
self.env['STLIB_%s' % var] = stlibs self.env['STLIB_%s' % var] = stlibs
self.end_msg('ok') self.end_msg(' '.join(libs + stlibs))
if Logs.verbose: if Logs.verbose:
Logs.pprint('CYAN', ' path : %s' % path) Logs.pprint('CYAN', ' path : %s' % path)
Logs.pprint('CYAN', ' shared libs : %s' % libs) Logs.pprint('CYAN', ' shared libs : %s' % libs)
@@ -450,15 +458,18 @@ def check_boost(self, *k, **kw):
self.check_cxx(fragment=BOOST_ERROR_CODE, use=var, execute=False) self.check_cxx(fragment=BOOST_ERROR_CODE, use=var, execute=False)
if has_lib('thread'): if has_lib('thread'):
self.check_cxx(fragment=BOOST_THREAD_CODE, use=var, execute=False) self.check_cxx(fragment=BOOST_THREAD_CODE, use=var, execute=False)
if has_lib('log'): if has_lib('log') or has_lib('log_setup'):
if not has_lib('thread'): if not has_lib('thread'):
self.env['DEFINES_%s' % var] += ['BOOST_LOG_NO_THREADS'] self.env['DEFINES_%s' % var] += ['BOOST_LOG_NO_THREADS']
if has_shlib('log'): if has_shlib('log') or has_shlib('log_setup'):
self.env['DEFINES_%s' % var] += ['BOOST_LOG_DYN_LINK'] self.env['DEFINES_%s' % var] += ['BOOST_LOG_DYN_LINK']
self.check_cxx(fragment=BOOST_LOG_CODE, use=var, execute=False) if has_lib('log_setup'):
self.check_cxx(fragment=BOOST_LOG_SETUP_CODE, use=var, execute=False)
else:
self.check_cxx(fragment=BOOST_LOG_CODE, use=var, execute=False)
if params.get('linkage_autodetect', False): if params.get('linkage_autodetect', False):
self.start_msg("Attempting to detect boost linkage flags") self.start_msg('Attempting to detect boost linkage flags')
toolset = self.boost_get_toolset(kw.get('toolset', '')) toolset = self.boost_get_toolset(kw.get('toolset', ''))
if toolset in ('vc',): if toolset in ('vc',):
# disable auto-linking feature, causing error LNK1181 # disable auto-linking feature, causing error LNK1181
@@ -480,10 +491,10 @@ def check_boost(self, *k, **kw):
# we attempt to play with some known-to-work CXXFLAGS combinations # we attempt to play with some known-to-work CXXFLAGS combinations
for cxxflags in (['/MD', '/EHsc'], []): for cxxflags in (['/MD', '/EHsc'], []):
self.env.stash() self.env.stash()
self.env["CXXFLAGS_%s" % var] += cxxflags self.env['CXXFLAGS_%s' % var] += cxxflags
try: try:
try_link() try_link()
self.end_msg("ok: winning cxxflags combination: %s" % (self.env["CXXFLAGS_%s" % var])) self.end_msg('ok: winning cxxflags combination: %s' % (self.env['CXXFLAGS_%s' % var]))
exc = None exc = None
break break
except Errors.ConfigurationError as e: except Errors.ConfigurationError as e:
@@ -491,17 +502,17 @@ def check_boost(self, *k, **kw):
exc = e exc = e
if exc is not None: if exc is not None:
self.end_msg("Could not auto-detect boost linking flags combination, you may report it to boost.py author", ex=exc) self.end_msg('Could not auto-detect boost linking flags combination, you may report it to boost.py author', ex=exc)
self.fatal('The configuration failed') self.fatal('The configuration failed')
else: else:
self.end_msg("Boost linkage flags auto-detection not implemented (needed ?) for this toolchain") self.end_msg('Boost linkage flags auto-detection not implemented (needed ?) for this toolchain')
self.fatal('The configuration failed') self.fatal('The configuration failed')
else: else:
self.start_msg('Checking for boost linkage') self.start_msg('Checking for boost linkage')
try: try:
try_link() try_link()
except Errors.ConfigurationError as e: except Errors.ConfigurationError as e:
self.end_msg("Could not link against boost libraries using supplied options") self.end_msg('Could not link against boost libraries using supplied options', 'YELLOW')
self.fatal('The configuration failed') self.fatal('The configuration failed')
self.end_msg('ok') self.end_msg('ok')
+8 -8
View File
@@ -44,28 +44,28 @@ def apply_sphinx(self):
task.inputs.append(conf) task.inputs.append(conf)
confdir = conf.parent.abspath() confdir = conf.parent.abspath()
buildername = getattr(self, "builder", "html") buildername = getattr(self, 'builder', 'html')
srcdir = getattr(self, "srcdir", confdir) srcdir = getattr(self, 'srcdir', confdir)
outdir = self.path.find_or_declare(getattr(self, "outdir", buildername)).get_bld() outdir = self.path.find_or_declare(getattr(self, 'outdir', buildername)).get_bld()
doctreedir = getattr(self, "doctreedir", os.path.join(outdir.abspath(), ".doctrees")) doctreedir = getattr(self, 'doctreedir', os.path.join(outdir.abspath(), '.doctrees'))
task.env['BUILDERNAME'] = buildername task.env['BUILDERNAME'] = buildername
task.env['SRCDIR'] = srcdir task.env['SRCDIR'] = srcdir
task.env['DOCTREEDIR'] = doctreedir task.env['DOCTREEDIR'] = doctreedir
task.env['OUTDIR'] = outdir.abspath() task.env['OUTDIR'] = outdir.abspath()
task.env['VERSION'] = "version=%s" % self.VERSION task.env['VERSION'] = 'version=%s' % self.version
task.env['RELEASE'] = "release=%s" % self.VERSION task.env['RELEASE'] = 'release=%s' % getattr(self, 'release', self.version)
import imp import imp
confData = imp.load_source('sphinx_conf', conf.abspath()) confData = imp.load_source('sphinx_conf', conf.abspath())
if buildername == "man": if buildername == 'man':
for i in confData.man_pages: for i in confData.man_pages:
target = outdir.find_or_declare('%s.%d' % (i[1], i[4])) target = outdir.find_or_declare('%s.%d' % (i[1], i[4]))
task.outputs.append(target) task.outputs.append(target)
if self.install_path: if self.install_path:
self.bld.install_files("%s/man%d/" % (self.install_path, i[4]), target) self.bld.install_files('%s/man%d/' % (self.install_path, i[4]), target)
else: else:
task.outputs.append(outdir) task.outputs.append(outdir)
+1 -2
View File
@@ -3,8 +3,7 @@ libdir=@LIBDIR@
includedir=@INCLUDEDIR@ includedir=@INCLUDEDIR@
Name: ChronoSync Name: ChronoSync
Description: ChronoSync library Description: NDN ChronoSync library
Version: @VERSION@ Version: @VERSION@
Libs: -L${libdir} -lChronoSync Libs: -L${libdir} -lChronoSync
Cflags: -I${includedir} Cflags: -I${includedir}
+29 -26
View File
@@ -1,50 +1,54 @@
# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
from waflib import Context, Logs, Utils
import os, subprocess
VERSION = '0.5.2' VERSION = '0.5.2'
APPNAME = 'ChronoSync' APPNAME = 'ChronoSync'
GIT_TAG_PREFIX = '' GIT_TAG_PREFIX = ''
from waflib import Logs, Utils, Context
import os, subprocess
def options(opt): def options(opt):
opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build', opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build',
'coverage', 'sanitizers'], 'coverage', 'sanitizers'],
tooldir=['.waf-tools']) tooldir=['.waf-tools'])
opt.add_option('--with-tests', action='store_true', default=False, optgrp = opt.add_option_group('ChronoSync Options')
help='Build unit tests') optgrp.add_option('--with-tests', action='store_true', default=False,
help='Build unit tests')
def configure(conf): def configure(conf):
conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
'default-compiler-flags', 'boost', 'coverage', 'default-compiler-flags', 'boost',
'doxygen', 'sphinx_build']) 'doxygen', 'sphinx_build'])
if 'PKG_CONFIG_PATH' not in os.environ: conf.env.WITH_TESTS = conf.options.with_tests
os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
uselib_store='NDN_CXX', mandatory=True) pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
boost_libs = ['system', 'iostreams']
if conf.env.WITH_TESTS:
boost_libs.append('unit_test_framework')
boost_libs = 'system iostreams thread log log_setup'
if conf.options.with_tests:
conf.env['CHRONOSYNC_HAVE_TESTS'] = True
conf.define('CHRONOSYNC_HAVE_TESTS', 1)
boost_libs += ' unit_test_framework'
conf.check_boost(lib=boost_libs, mt=True) conf.check_boost(lib=boost_libs, mt=True)
conf.check_compiler_flags() conf.check_compiler_flags()
# Loading "late" to prevent tests from being compiled with profiling flags # Loading "late" to prevent tests from being compiled with profiling flags
conf.load('coverage') conf.load('coverage')
conf.load('sanitizers') conf.load('sanitizers')
# If there happens to be a static library, waf will put the corresponding -L flags # If there happens to be a static library, waf will put the corresponding -L flags
# before dynamic library flags. This can result in compilation failure when the # before dynamic library flags. This can result in compilation failure when the
# system has a different version of the ChronoSync library installed. # system has a different version of the ChronoSync library installed.
conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] conf.env.prepend_value('STLIBPATH', ['.'])
conf.define_cond('CHRONOSYNC_HAVE_TESTS', conf.env.WITH_TESTS)
# The config header will contain all defines that were added using conf.define()
# or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
# will not appear in the config header, but will instead be passed directly to the
# compiler on the command line.
conf.write_config_header('config.hpp') conf.write_config_header('config.hpp')
def build(bld): def build(bld):
@@ -56,28 +60,26 @@ def build(bld):
includes='src .', includes='src .',
export_includes='src .') export_includes='src .')
if bld.env['CHRONOSYNC_HAVE_TESTS']: if bld.env.WITH_TESTS:
bld.recurse('tests') bld.recurse('tests')
bld.install_files( bld.install_files(
dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']), files = bld.path.ant_glob(['src/*.hpp', 'common.hpp']),
cwd = bld.path.find_dir('src'), cwd = bld.path.find_dir('src'),
relative_trick = False) relative_trick = False)
bld.install_files( bld.install_files(
dest = '%s/ChronoSync' % bld.env['INCLUDEDIR'], dest = '%s/ChronoSync' % bld.env.INCLUDEDIR,
files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']), files = bld.path.get_bld().ant_glob(['src/*.hpp', 'common.hpp', 'config.hpp']),
cwd = bld.path.get_bld().find_dir('src'), cwd = bld.path.get_bld().find_dir('src'),
relative_trick = False) relative_trick = False)
bld(features = 'subst', bld(features='subst',
source='ChronoSync.pc.in', source='ChronoSync.pc.in',
target='ChronoSync.pc', target='ChronoSync.pc',
install_path = '${LIBDIR}/pkgconfig', install_path='${LIBDIR}/pkgconfig',
PREFIX = bld.env['PREFIX'], VERSION=VERSION)
INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'],
VERSION = VERSION)
def docs(bld): def docs(bld):
from waflib import Options from waflib import Options
@@ -115,7 +117,8 @@ def sphinx(bld):
config='docs/conf.py', config='docs/conf.py',
outdir='docs', outdir='docs',
source=bld.path.ant_glob('docs/**/*.rst'), source=bld.path.ant_glob('docs/**/*.rst'),
VERSION=VERSION) version=VERSION_BASE,
release=VERSION)
def version(ctx): def version(ctx):
# don't execute more than once # don't execute more than once