blob: afb7e70a58cc791da92c23075127fb77090ab935 [file] [log] [blame]
Davide Pesavento67f30272016-08-10 01:55:16 +00001from waflib import Options, Logs, Errors, Configure
Wentao Shang53df1632014-04-21 12:01:32 -07002import re
3
4def addWebsocketOptions(self, opt):
5 opt.add_option('--without-websocket', action='store_false', default=True,
Davide Pesavento67f30272016-08-10 01:55:16 +00006 dest='with_websocket', help='Disable WebSocket face support')
Davide Pesavento0064c1d2018-03-03 18:43:53 -05007
8setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions)
Wentao Shang53df1632014-04-21 12:01:32 -07009
Davide Pesavento67f30272016-08-10 01:55:16 +000010@Configure.conf
Wentao Shang53df1632014-04-21 12:01:32 -070011def checkWebsocket(self, **kw):
12 if not self.options.with_websocket:
13 return
14
15 isMandatory = kw.get('mandatory', True)
16
Davide Pesavento0064c1d2018-03-03 18:43:53 -050017 self.start_msg('Checking for WebSocket++ includes')
Wentao Shang53df1632014-04-21 12:01:32 -070018
19 try:
20 websocketDir = self.path.find_dir('websocketpp/websocketpp')
21 if not websocketDir:
22 raise Errors.WafError('Not found')
23
24 versionFile = websocketDir.find_node('version.hpp')
25 if not websocketDir:
Davide Pesavento0064c1d2018-03-03 18:43:53 -050026 raise Errors.WafError('WebSocket++ version file not found')
Wentao Shang53df1632014-04-21 12:01:32 -070027
28 try:
29 txt = versionFile.read()
30 except (OSError, IOError):
Davide Pesavento0064c1d2018-03-03 18:43:53 -050031 raise Errors.WafError('Cannot read WebSocket++ version file')
Wentao Shang53df1632014-04-21 12:01:32 -070032
Davide Pesavento0064c1d2018-03-03 18:43:53 -050033 version = [None, None, None]
Wentao Shang53df1632014-04-21 12:01:32 -070034 # Looking for the following:
35 # static int const major_version = 0;
Eric Newberry25a84072016-06-20 18:38:15 -070036 # static int const minor_version = 7;
37 # static int const patch_version = 0;
Wentao Shang53df1632014-04-21 12:01:32 -070038 majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M)
39 version[0] = majorVersion.search(txt)
Wentao Shang53df1632014-04-21 12:01:32 -070040 minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M)
41 version[1] = minorVersion.search(txt)
Wentao Shang53df1632014-04-21 12:01:32 -070042 patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M)
43 version[2] = patchVersion.search(txt)
44
45 if not version[0] or not version[1] or not version[2]:
Davide Pesavento0064c1d2018-03-03 18:43:53 -050046 raise Errors.WafError('Cannot detect WebSocket++ version')
Wentao Shang53df1632014-04-21 12:01:32 -070047
Davide Pesavento0064c1d2018-03-03 18:43:53 -050048 self.env.WEBSOCKET_VERSION = [i.group(1) for i in version]
Wentao Shang53df1632014-04-21 12:01:32 -070049
50 # todo: version checking, if necessary
51
Davide Pesavento0064c1d2018-03-03 18:43:53 -050052 self.end_msg('.'.join(self.env.WEBSOCKET_VERSION))
Wentao Shang53df1632014-04-21 12:01:32 -070053
Davide Pesavento264af772021-02-09 21:48:24 -050054 self.env.append_unique('DEFINES', ['_WEBSOCKETPP_CPP11_STL_'])
Davide Pesavento0064c1d2018-03-03 18:43:53 -050055 self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath()
56 self.env.HAVE_WEBSOCKET = True
Wentao Shang53df1632014-04-21 12:01:32 -070057 self.define('HAVE_WEBSOCKET', 1)
58
59 except Errors.WafError as error:
60 if isMandatory:
61 self.end_msg(str(error), color='RED')
Davide Pesavento9be99802018-11-10 14:40:26 -050062 Logs.warn('If you are using NFD from the git repository, checkout the websocketpp submodule: ')
Davide Pesavento5f35f642018-05-10 19:36:03 -040063 Logs.warn(' git submodule update --init')
Davide Pesavento9be99802018-11-10 14:40:26 -050064 Logs.warn('Otherwise, manually download and extract the websocketpp library:')
65 Logs.warn(' mkdir -p websocketpp')
Alexander Afanasyeva6bd7da2019-04-25 17:26:11 -040066 Logs.warn(' curl -L https://github.com/cawka/websocketpp/archive/0.8.1-hotfix.tar.gz > websocketpp.tar.gz')
Davide Pesavento9be99802018-11-10 14:40:26 -050067 Logs.warn(' tar xf websocketpp.tar.gz -C websocketpp/ --strip 1')
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070068 Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket')
Davide Pesavento9be99802018-11-10 14:40:26 -050069 self.fatal('WebSocket++ not found')
Wentao Shang53df1632014-04-21 12:01:32 -070070 else:
71 self.end_msg(str(error))