blob: 1cf54d73f8af9a03aa3c63b023ca3c6f0402c34d [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
145 bld (features = "subst",
146 source = "libndn-cpp-dev.pc.in",
147 target = "libndn-cpp-dev.pc",
148 install_path = "${LIBDIR}/pkgconfig",
149 )
150
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800151 # Unit tests
152 if bld.env['WITH_TESTS']:
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800153 bld.recurse('tests')
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800154
Alexander Afanasyevd409d592014-01-28 18:36:38 -0800155 bld.recurse("tools examples")
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -0800156
157 headers = bld.path.ant_glob(['src/**/*.hpp',
158 'src/**/*.h'])
159 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('src'))
160
161 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], bld.path.find_resource('include/ndn-cpp/ndn-cpp-config.h'))
162
163 headers = bld.path.ant_glob(['include/**/*.hpp', 'include/**/*.h'])
164 bld.install_files("%s" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('include'))
165
166@Configure.conf
167def add_supported_cxxflags(self, cxxflags):
168 """
169 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
170 """
171 self.start_msg('Checking allowed flags for c++ compiler')
172
173 supportedFlags = []
174 for flag in cxxflags:
175 if self.check_cxx (cxxflags=[flag], mandatory=False):
176 supportedFlags += [flag]
177
178 self.end_msg (' '.join (supportedFlags))
179 self.env.CXXFLAGS += supportedFlags
180
181# doxygen docs
182from waflib.Build import BuildContext
183class doxy (BuildContext):
184 cmd = "doxygen"
185 fun = "doxygen"
186
187def doxygen (bld):
188 if not bld.env.DOXYGEN:
189 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
190 bld (features="doxygen",
191 doxyfile='Doxyfile')
192
193# doxygen docs
194from waflib.Build import BuildContext
195class sphinx (BuildContext):
196 cmd = "sphinx"
197 fun = "sphinx"
198
199def sphinx (bld):
200 bld.load('sphinx_build', tooldir=['waf-tools'])
201
202 bld (features="sphinx",
203 outdir = "doc/html",
204 source = "doc/source/conf.py")