blob: 33a1ff6bab8e7b4e917c4463cf5bca9e4bc4a864 [file] [log] [blame]
Davide Pesavento67f30272016-08-10 01:55:16 +00001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Wentao Shang53df1632014-04-21 12:01:32 -07002
Davide Pesavento67f30272016-08-10 01:55:16 +00003from waflib import Options, Logs, Errors, Configure
Wentao Shang53df1632014-04-21 12:01:32 -07004import re
5
6def addWebsocketOptions(self, opt):
7 opt.add_option('--without-websocket', action='store_false', default=True,
Davide Pesavento67f30272016-08-10 01:55:16 +00008 dest='with_websocket', help='Disable WebSocket face support')
Davide Pesavento0064c1d2018-03-03 18:43:53 -05009
10setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions)
Wentao Shang53df1632014-04-21 12:01:32 -070011
Davide Pesavento67f30272016-08-10 01:55:16 +000012@Configure.conf
Wentao Shang53df1632014-04-21 12:01:32 -070013def checkWebsocket(self, **kw):
14 if not self.options.with_websocket:
15 return
16
17 isMandatory = kw.get('mandatory', True)
18
Davide Pesavento0064c1d2018-03-03 18:43:53 -050019 self.start_msg('Checking for WebSocket++ includes')
Wentao Shang53df1632014-04-21 12:01:32 -070020
21 try:
22 websocketDir = self.path.find_dir('websocketpp/websocketpp')
23 if not websocketDir:
24 raise Errors.WafError('Not found')
25
26 versionFile = websocketDir.find_node('version.hpp')
27 if not websocketDir:
Davide Pesavento0064c1d2018-03-03 18:43:53 -050028 raise Errors.WafError('WebSocket++ version file not found')
Wentao Shang53df1632014-04-21 12:01:32 -070029
30 try:
31 txt = versionFile.read()
32 except (OSError, IOError):
Davide Pesavento0064c1d2018-03-03 18:43:53 -050033 raise Errors.WafError('Cannot read WebSocket++ version file')
Wentao Shang53df1632014-04-21 12:01:32 -070034
Davide Pesavento0064c1d2018-03-03 18:43:53 -050035 version = [None, None, None]
Wentao Shang53df1632014-04-21 12:01:32 -070036 # Looking for the following:
37 # static int const major_version = 0;
Eric Newberry25a84072016-06-20 18:38:15 -070038 # static int const minor_version = 7;
39 # static int const patch_version = 0;
Wentao Shang53df1632014-04-21 12:01:32 -070040 majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M)
41 version[0] = majorVersion.search(txt)
Wentao Shang53df1632014-04-21 12:01:32 -070042 minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M)
43 version[1] = minorVersion.search(txt)
Wentao Shang53df1632014-04-21 12:01:32 -070044 patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M)
45 version[2] = patchVersion.search(txt)
46
47 if not version[0] or not version[1] or not version[2]:
Davide Pesavento0064c1d2018-03-03 18:43:53 -050048 raise Errors.WafError('Cannot detect WebSocket++ version')
Wentao Shang53df1632014-04-21 12:01:32 -070049
Davide Pesavento0064c1d2018-03-03 18:43:53 -050050 self.env.WEBSOCKET_VERSION = [i.group(1) for i in version]
Wentao Shang53df1632014-04-21 12:01:32 -070051
52 # todo: version checking, if necessary
53
Davide Pesavento0064c1d2018-03-03 18:43:53 -050054 self.end_msg('.'.join(self.env.WEBSOCKET_VERSION))
Wentao Shang53df1632014-04-21 12:01:32 -070055
Davide Pesavento0064c1d2018-03-03 18:43:53 -050056 self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
57 self.env.HAVE_WEBSOCKET = True
Wentao Shang53df1632014-04-21 12:01:32 -070058 self.define('HAVE_WEBSOCKET', 1)
Wentao Shang306df5e2014-10-31 15:46:00 -070059 self.define('_WEBSOCKETPP_CPP11_STL_', 1)
Wentao Shang53df1632014-04-21 12:01:32 -070060
61 except Errors.WafError as error:
62 if isMandatory:
63 self.end_msg(str(error), color='RED')
Davide Pesavento9be99802018-11-10 14:40:26 -050064 Logs.warn('If you are using NFD from the git repository, checkout the websocketpp submodule: ')
Davide Pesavento5f35f642018-05-10 19:36:03 -040065 Logs.warn(' git submodule update --init')
Davide Pesavento9be99802018-11-10 14:40:26 -050066 Logs.warn('Otherwise, manually download and extract the websocketpp library:')
67 Logs.warn(' mkdir -p websocketpp')
68 Logs.warn(' curl -L https://github.com/zaphoyd/websocketpp/archive/0.8.1.tar.gz > websocketpp.tar.gz')
69 Logs.warn(' tar xf websocketpp.tar.gz -C websocketpp/ --strip 1')
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070070 Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket')
Davide Pesavento9be99802018-11-10 14:40:26 -050071 self.fatal('WebSocket++ not found')
Wentao Shang53df1632014-04-21 12:01:32 -070072 else:
73 self.end_msg(str(error))