blob: 979324d0c1062cf9ff6259ff72b9509b1bc96e0b [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.3~dev0'
3NAME="ndn-cpp-dev"
4
5from waflib import Build, Logs, Utils, Task, TaskGen, Configure
6
7def options(opt):
8 opt.load('compiler_c compiler_cxx gnu_dirs c_osx')
9 opt.load('boost doxygen openssl cryptopp', tooldir=['.waf-tools'])
10
11 opt = opt.add_option_group('NDN-CPP Options')
12
13 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
14
15 opt.add_option('--with-tests', action='store_true',default=False,dest='with_tests',
16 help='''build unit tests''')
17 opt.add_option('--with-log4cxx', action='store_true',default=False,dest='log4cxx',
18 help='''Compile with log4cxx logging support''')
19
20 opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
21 help='''Use C++11 features, even if available in the compiler''')
22 opt.add_option('--without-system-boost', action='store_false', default=True, dest='use_system_boost',
23 help='''Use system's boost libraries''')
24
25
26def configure(conf):
27 conf.load("compiler_c compiler_cxx boost gnu_dirs c_osx openssl cryptopp")
28 try:
29 conf.load("doxygen")
30 except:
31 pass
32
33 if conf.options.with_tests:
34 conf.env['WITH_TESTS'] = True
35
36 # Optional functions
37 for func in ['memcmp', 'memcpy', 'memset']:
38 conf.check(function_name=func, header_name='string.h', mandatory=False)
39
40 # Mandatory functions
41 for func in ['strchr', 'sscanf']:
42 conf.check(function_name=func, header_name=['string.h', 'stdio.h'])
43
44 # Mandatory headers
45 for header in ['time.h', 'sys/time.h']:
46 conf.check(header_name=header)
47
48 conf.check(function_name='gettimeofday', header_name=['time.h', 'sys/time.h'])
49
50 conf.check_openssl()
51
52 if conf.options.debug:
53 conf.define ('_DEBUG', 1)
54 flags = ['-O0',
55 '-Wall',
56 # '-Werror',
57 '-Wno-unused-variable',
58 '-g3',
59 '-Wno-unused-private-field', # only clang supports
60 '-fcolor-diagnostics', # only clang supports
61 '-Qunused-arguments', # only clang supports
62 '-Wno-tautological-compare', # suppress warnings from CryptoPP
63 '-Wno-unused-function', # another annoying warning from CryptoPP
64
65 '-Wno-deprecated-declarations',
66 ]
67
68 conf.add_supported_cxxflags (cxxflags = flags)
69 else:
70 flags = ['-O3', '-g', '-Wno-tautological-compare', '-Wno-unused-function', '-Wno-deprecated-declarations']
71 conf.add_supported_cxxflags (cxxflags = flags)
72
73 if Utils.unversioned_sys_platform () == "darwin":
74 conf.check_cxx(framework_name='CoreFoundation', uselib_store='OSX_COREFOUNDATION', mandatory=True)
Alexander Afanasyevd409d592014-01-28 18:36:38 -080075 conf.check_cxx(framework_name='CoreServices', uselib_store='OSX_CORESERVICES', mandatory=True)
76 conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY', define_name='HAVE_SECURITY',
77 use="OSX_COREFOUNDATION", mandatory=True)
78 conf.define('HAVE_OSX_SECURITY', 1)
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -080079
80 conf.define ("PACKAGE_BUGREPORT", "ndn-lib@lists.cs.ucla.edu")
81 conf.define ("PACKAGE_NAME", NAME)
82 conf.define ("PACKAGE_VERSION", VERSION)
83 conf.define ("PACKAGE_URL", "https://github.com/named-data/ndn-cpp")
84
85 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
86
87 if conf.options.log4cxx:
88 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
89 conf.define ("HAVE_LOG4CXX", 1)
90
91 conf.check_cryptopp(path=conf.options.cryptopp_dir, mandatory=True)
92
93 if conf.options.use_cxx11:
94 conf.add_supported_cxxflags(cxxflags = ['-std=c++11', '-std=c++0x'])
95
96 conf.check(msg='Checking for type std::shared_ptr',
97 type_name="std::shared_ptr<int>", header_name="memory", define_name='HAVE_STD_SHARED_PTR')
98 conf.check(msg='Checking for type std::function',
99 type_name="std::function<void()>", header_name="functional", define_name='HAVE_STD_FUNCTION')
100 conf.define('HAVE_CXX11', 1)
101 else:
102 if conf.options.use_system_boost:
103 USED_BOOST_LIBS = 'system filesystem iostreams'
104 if conf.env['WITH_TESTS']:
105 USED_BOOST_LIBS += " unit_test_framework"
106
107 conf.check_boost(lib=USED_BOOST_LIBS)
108
109 boost_version = conf.env.BOOST_VERSION.split('_')
110 if int(boost_version[0]) > 1 or (int(boost_version[0]) == 1 and int(boost_version[1]) >= 46):
111 conf.env['USE_SYSTEM_BOOST'] = True
112 conf.define('USE_SYSTEM_BOOST', 1)
113
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800114 conf.write_config_header('include/ndn-cpp-dev/ndn-cpp-config.h', define_prefix='NDN_CPP_')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800115
116def build (bld):
117 libndn_cpp = bld (
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800118 target="lib-objects",
119 name = "lib-objects",
120 features=['cxx'],
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800121 source = bld.path.ant_glob(['src/**/*.cpp',
122 'new/**/*.cpp']),
123 use = 'BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3',
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800124 includes = "include",
125 export_includes = "include",
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800126 )
127
128 if Utils.unversioned_sys_platform () == "darwin":
129 libndn_cpp.mac_app = True
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800130 libndn_cpp.use += " OSX_COREFOUNDATION OSX_SECURITY"
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800131
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800132 shlib = bld(features = 'cxx cxxshlib',
133 vnum = "0.3.0",
134 target = "ndn-cpp-dev",
135 use = "lib-objects",
136 name = "ndn-cpp-dev-shlib",
137 )
138
139 stlib = bld(features = 'cxx cxxstlib',
140 target = "ndn-cpp-dev",
141 use = "lib-objects",
142 name = "ndn-cpp-dev-stlib",
143 )
144
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800145 pkgconfig_libs = []
146 pkgconfig_ldflags = []
147 pkgconfig_includes = []
148 for lib in Utils.to_list(libndn_cpp.use):
149 if bld.env['LIB_%s' % lib]:
150 pkgconfig_libs += Utils.to_list(bld.env['LIB_%s' % lib])
151 if bld.env['LIBPATH_%s' % lib]:
152 pkgconfig_ldflags += Utils.to_list(bld.env['LIBPATH_%s' % lib])
153 if bld.env['INCLUDES_%s' % lib]:
154 pkgconfig_includes += Utils.to_list(bld.env['INCLUDES_%s' % lib])
155
156 def uniq(alist):
157 set = {}
158 return [set.setdefault(e,e) for e in alist if e not in set]
159
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800160 bld (features = "subst",
161 source = "libndn-cpp-dev.pc.in",
162 target = "libndn-cpp-dev.pc",
163 install_path = "${LIBDIR}/pkgconfig",
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800164 VERSION = VERSION,
165
166 # This probably not the right thing to do, but to simplify life of apps
167 # that use the library
168 EXTRA_LIBS = " ".join([('-l%s' % i) for i in uniq(pkgconfig_libs)]),
169 EXTRA_LDFLAGS = " ".join([('-L%s' % i) for i in uniq(pkgconfig_ldflags)]),
170 EXTRA_INCLUDES = " ".join([('-I%s' % i) for i in uniq(pkgconfig_includes)]),
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800171 )
Alexander Afanasyev200dd6f2014-01-28 19:04:25 -0800172
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800173 # Unit tests
174 if bld.env['WITH_TESTS']:
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800175 bld.recurse('tests')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800176
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800177 bld.recurse("tools examples")
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800178
179 headers = bld.path.ant_glob(['src/**/*.hpp',
180 'src/**/*.h'])
181 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('src'))
182
183 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], bld.path.find_resource('include/ndn-cpp/ndn-cpp-config.h'))
184
185 headers = bld.path.ant_glob(['include/**/*.hpp', 'include/**/*.h'])
186 bld.install_files("%s" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('include'))
187
188@Configure.conf
189def add_supported_cxxflags(self, cxxflags):
190 """
191 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
192 """
193 self.start_msg('Checking allowed flags for c++ compiler')
194
195 supportedFlags = []
196 for flag in cxxflags:
197 if self.check_cxx (cxxflags=[flag], mandatory=False):
198 supportedFlags += [flag]
199
200 self.end_msg (' '.join (supportedFlags))
201 self.env.CXXFLAGS += supportedFlags
202
203# doxygen docs
204from waflib.Build import BuildContext
205class doxy (BuildContext):
206 cmd = "doxygen"
207 fun = "doxygen"
208
209def doxygen (bld):
210 if not bld.env.DOXYGEN:
211 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
212 bld (features="doxygen",
213 doxyfile='Doxyfile')
214
215# doxygen docs
216from waflib.Build import BuildContext
217class sphinx (BuildContext):
218 cmd = "sphinx"
219 fun = "sphinx"
220
221def sphinx (bld):
222 bld.load('sphinx_build', tooldir=['waf-tools'])
223
224 bld (features="sphinx",
225 outdir = "doc/html",
226 source = "doc/source/conf.py")