build: Extending wscript to enable coverage information with --with-coverage option
When coverage option is enabled, all necessary flags are exported via
pkgconfig configuration.
Change-Id: Ieac8c17b2b81568fddbfd61d99bb79a5e2b99f13
refs: #1215
diff --git a/.waf-tools/coverage.py b/.waf-tools/coverage.py
new file mode 100644
index 0000000..eac7608
--- /dev/null
+++ b/.waf-tools/coverage.py
@@ -0,0 +1,20 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+from waflib import TaskGen
+
+def options(opt):
+ opt.add_option('--with-coverage',action='store_true',default=False,dest='with_coverage',
+ help='''Set compiler flags for gcc to enable code coverage information''')
+
+def configure(conf):
+ if conf.options.with_coverage:
+ conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'],
+ linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True)
+
+@TaskGen.feature('cxx','cc')
+@TaskGen.after('process_source')
+def add_coverage(self):
+ if getattr(self, 'use', ''):
+ self.use += ' GCOV'
+ else:
+ self.use = 'GCOV'
diff --git a/libndn-cpp-dev.pc.in b/libndn-cpp-dev.pc.in
index 4b0e793..be52ba0 100644
--- a/libndn-cpp-dev.pc.in
+++ b/libndn-cpp-dev.pc.in
@@ -6,5 +6,5 @@
Name: libndn-cpp-dev
Description: Development version of C++ API for NDN (NDN-TLV packet format)
Version: @VERSION@
-Libs: -L${libdir} @EXTRA_LDFLAGS@ -lndn-cpp-dev @EXTRA_LIBS@ @EXTRA_FRAMEWORKS@
-Cflags: -I${includedir} @EXTRA_INCLUDES@
+Libs: -L${libdir} @EXTRA_LINKFLAGS@ @EXTRA_LDFLAGS@ -lndn-cpp-dev @EXTRA_LIBS@ @EXTRA_FRAMEWORKS@
+Cflags: -I${includedir} @EXTRA_CXXFLAGS@ @EXTRA_INCLUDES@
diff --git a/wscript b/wscript
index 2fa9d16..8c23468 100644
--- a/wscript
+++ b/wscript
@@ -7,12 +7,12 @@
def options(opt):
opt.load('compiler_c compiler_cxx gnu_dirs c_osx')
- opt.load('boost doxygen openssl cryptopp', tooldir=['.waf-tools'])
+ opt.load('boost doxygen openssl cryptopp coverage', tooldir=['.waf-tools'])
opt = opt.add_option_group('NDN-CPP Options')
opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
-
+
opt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',
help='''build unit tests''')
opt.add_option('--with-log4cxx', action='store_true',default=False,dest='log4cxx',
@@ -27,7 +27,7 @@
opt.add_option('--without-sqlite-locking', action='store_false', default=True, dest='with_sqlite_locking',
help='''Disable filesystem locking in sqlite3 database (use unix-dot locking mechanism instead). '''
- '''This option may be necessary if home directory is hosted on NFS.''')
+ '''This option may be necessary if home directory is hosted on NFS.''')
opt.add_option('--with-pch', action='store_true', default=False, dest='with_pch',
help='''Try to use precompiled header to speed up compilation (only gcc and clang)''')
opt.add_option('--without-osx-keychain', action='store_false', default=True, dest='with_osx_keychain',
@@ -112,11 +112,11 @@
conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD', mandatory=False)
conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
- conf.check_cxx(cxxflags=['-fPIC'], uselib_store='PIC', mandatory=False)
+ conf.check_cxx(cxxflags=['-fPIC'], uselib_store='cxxstlib', mandatory=False)
if not conf.options.with_sqlite_locking:
conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
-
+
conf.env['WITH_PCH'] = conf.options.with_pch
if Utils.unversioned_sys_platform () == "darwin":
@@ -125,7 +125,9 @@
conf.define('WITH_OSX_KEYCHAIN', 1)
else:
conf.env['WITH_OSX_KEYCHAIN'] = False
-
+
+ conf.load("coverage")
+
conf.write_config_header('src/ndn-cpp-config.h', define_prefix='NDN_CPP_')
def build (bld):
@@ -144,7 +146,7 @@
if bld.env['WITH_PCH']:
libndn_cpp.pch = "src/common.hpp"
-
+
if Utils.unversioned_sys_platform () == "darwin":
libndn_cpp.source += bld.path.ant_glob('src/**/*-osx.cpp')
libndn_cpp.mac_app = True
@@ -156,7 +158,9 @@
pkgconfig_libs = []
pkgconfig_ldflags = []
+ pkgconfig_linkflags = []
pkgconfig_includes = []
+ pkgconfig_cxxflags = []
for lib in Utils.to_list(libndn_cpp.use):
if bld.env['LIB_%s' % lib]:
pkgconfig_libs += Utils.to_list(bld.env['LIB_%s' % lib])
@@ -164,16 +168,20 @@
pkgconfig_ldflags += Utils.to_list(bld.env['LIBPATH_%s' % lib])
if bld.env['INCLUDES_%s' % lib]:
pkgconfig_includes += Utils.to_list(bld.env['INCLUDES_%s' % lib])
+ if bld.env['LINKFLAGS_%s' % lib]:
+ pkgconfig_linkflags += Utils.to_list(bld.env['LINKFLAGS_%s' % lib])
+ if bld.env['CXXFLAGS_%s' % lib]:
+ pkgconfig_cxxflags += Utils.to_list(bld.env['CXXFLAGS_%s' % lib])
EXTRA_FRAMEWORKS = "";
if Utils.unversioned_sys_platform () == "darwin":
EXTRA_FRAMEWORKS = "-framework CoreFoundation -framework Security"
-
+
def uniq(alist):
set = {}
return [set.setdefault(e,e) for e in alist if e not in set]
-
- bld (features = "subst",
+
+ pkconfig = bld (features = "subst",
source = "libndn-cpp-dev.pc.in",
target = "libndn-cpp-dev.pc",
install_path = "${LIBDIR}/pkgconfig",
@@ -183,10 +191,12 @@
# that use the library
EXTRA_LIBS = " ".join([('-l%s' % i) for i in uniq(pkgconfig_libs)]),
EXTRA_LDFLAGS = " ".join([('-L%s' % i) for i in uniq(pkgconfig_ldflags)]),
+ EXTRA_LINKFLAGS = " ".join(uniq(pkgconfig_linkflags)),
EXTRA_INCLUDES = " ".join([('-I%s' % i) for i in uniq(pkgconfig_includes)]),
+ EXTRA_CXXFLAGS = " ".join(uniq(pkgconfig_cxxflags)),
EXTRA_FRAMEWORKS = EXTRA_FRAMEWORKS,
)
-
+
# Unit tests
if bld.env['WITH_TESTS']:
bld.recurse('tests')
@@ -195,7 +205,7 @@
bld.recurse("tools examples")
else:
bld.recurse("examples")
-
+
headers = bld.path.ant_glob(['src/**/*.hpp'])
bld.install_files("%s/ndn-cpp-dev" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('src'))
@@ -262,4 +272,3 @@
def post_run(self):
super(gchx, self).post_run()
self.orig_self.env['CXXFLAGS'] = ['-include', self.inputs[0].relpath()] + self.env['CXXFLAGS']
-