blob: b381eaa695944bb958e4cfd692147b01e6a218f3 [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)
75
76 conf.define ("PACKAGE_BUGREPORT", "ndn-lib@lists.cs.ucla.edu")
77 conf.define ("PACKAGE_NAME", NAME)
78 conf.define ("PACKAGE_VERSION", VERSION)
79 conf.define ("PACKAGE_URL", "https://github.com/named-data/ndn-cpp")
80
81 conf.check_cfg(package='sqlite3', args=['--cflags', '--libs'], uselib_store='SQLITE3', mandatory=True)
82
83 if conf.options.log4cxx:
84 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
85 conf.define ("HAVE_LOG4CXX", 1)
86
87 conf.check_cryptopp(path=conf.options.cryptopp_dir, mandatory=True)
88
89 if conf.options.use_cxx11:
90 conf.add_supported_cxxflags(cxxflags = ['-std=c++11', '-std=c++0x'])
91
92 conf.check(msg='Checking for type std::shared_ptr',
93 type_name="std::shared_ptr<int>", header_name="memory", define_name='HAVE_STD_SHARED_PTR')
94 conf.check(msg='Checking for type std::function',
95 type_name="std::function<void()>", header_name="functional", define_name='HAVE_STD_FUNCTION')
96 conf.define('HAVE_CXX11', 1)
97 else:
98 if conf.options.use_system_boost:
99 USED_BOOST_LIBS = 'system filesystem iostreams'
100 if conf.env['WITH_TESTS']:
101 USED_BOOST_LIBS += " unit_test_framework"
102
103 conf.check_boost(lib=USED_BOOST_LIBS)
104
105 boost_version = conf.env.BOOST_VERSION.split('_')
106 if int(boost_version[0]) > 1 or (int(boost_version[0]) == 1 and int(boost_version[1]) >= 46):
107 conf.env['USE_SYSTEM_BOOST'] = True
108 conf.define('USE_SYSTEM_BOOST', 1)
109
110 conf.write_config_header('include/ndn-cpp/ndn-cpp-config.h', define_prefix='NDN_CPP_')
111
112def build (bld):
113 libndn_cpp = bld (
114 target="ndn-cpp-dev",
115 vnum = "0.3.0",
116 features=['cxx', 'cxxshlib', 'cxxstlib'],
117 source = bld.path.ant_glob(['src/**/*.cpp',
118 'new/**/*.cpp']),
119 use = 'BOOST OPENSSL LOG4CXX CRYPTOPP SQLITE3',
120 includes = ". include",
121 )
122
123 if Utils.unversioned_sys_platform () == "darwin":
124 libndn_cpp.mac_app = True
125 libndn_cpp.use += " OSX_COREFOUNDATION"
126
127 # Unit tests
128 if bld.env['WITH_TESTS']:
129 unittests = bld.program (
130 target="unit-tests",
131 features = "cxx cxxprogram",
132 source = bld.path.ant_glob(['tests_boost/*.cpp']),
133 use = 'ndn-cpp-dev',
134 includes = ".",
135 install_prefix = None,
136 )
137
138 bld.recurse("tools examples tests")
139
140 headers = bld.path.ant_glob(['src/**/*.hpp',
141 'src/**/*.h'])
142 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('src'))
143
144 bld.install_files("%s/ndn-cpp" % bld.env['INCLUDEDIR'], bld.path.find_resource('include/ndn-cpp/ndn-cpp-config.h'))
145
146 headers = bld.path.ant_glob(['include/**/*.hpp', 'include/**/*.h'])
147 bld.install_files("%s" % bld.env['INCLUDEDIR'], headers, relative_trick=True, cwd=bld.path.find_node('include'))
148
149@Configure.conf
150def add_supported_cxxflags(self, cxxflags):
151 """
152 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
153 """
154 self.start_msg('Checking allowed flags for c++ compiler')
155
156 supportedFlags = []
157 for flag in cxxflags:
158 if self.check_cxx (cxxflags=[flag], mandatory=False):
159 supportedFlags += [flag]
160
161 self.end_msg (' '.join (supportedFlags))
162 self.env.CXXFLAGS += supportedFlags
163
164# doxygen docs
165from waflib.Build import BuildContext
166class doxy (BuildContext):
167 cmd = "doxygen"
168 fun = "doxygen"
169
170def doxygen (bld):
171 if not bld.env.DOXYGEN:
172 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
173 bld (features="doxygen",
174 doxyfile='Doxyfile')
175
176# doxygen docs
177from waflib.Build import BuildContext
178class sphinx (BuildContext):
179 cmd = "sphinx"
180 fun = "sphinx"
181
182def sphinx (bld):
183 bld.load('sphinx_build', tooldir=['waf-tools'])
184
185 bld (features="sphinx",
186 outdir = "doc/html",
187 source = "doc/source/conf.py")