blob: 2c500c7670beedf80f60d5c5e24706a98d10190d [file] [log] [blame]
Wentao Shang53df1632014-04-21 12:01:32 -07001# encoding: utf-8
2
3from waflib import Options, Logs, Errors
4from waflib.Configure import conf
5
6import re
7
8def addWebsocketOptions(self, opt):
9 opt.add_option('--without-websocket', action='store_false', default=True,
10 dest='with_websocket',
11 help='Disable WebSocket face support')
12setattr(Options.OptionsContext, "addWebsocketOptions", addWebsocketOptions)
13
14@conf
15def checkWebsocket(self, **kw):
16 if not self.options.with_websocket:
17 return
18
19 isMandatory = kw.get('mandatory', True)
20
21 self.start_msg('Checking for Websocket includes')
22
23 try:
24 websocketDir = self.path.find_dir('websocketpp/websocketpp')
25 if not websocketDir:
26 raise Errors.WafError('Not found')
27
28 versionFile = websocketDir.find_node('version.hpp')
29 if not websocketDir:
30 raise Errors.WafError('Corrupted: Websocket version file not found')
31
32 try:
33 txt = versionFile.read()
34 except (OSError, IOError):
35 raise Errors.WafError('Corrupted: cannot read Websocket version file')
36
37 # Looking for the following:
38 # static int const major_version = 0;
39 # static int const minor_version = 3;
40 # static int const patch_version = 0;
41
42 version = [None, None, None]
43
44 majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M)
45 version[0] = majorVersion.search(txt)
46
47 minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M)
48 version[1] = minorVersion.search(txt)
49
50 patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M)
51 version[2] = patchVersion.search(txt)
52
53 if not version[0] or not version[1] or not version[2]:
54 raise Errors.WafError('Corrupted: cannot detect websocket version')
55
56 self.env['WEBSOCKET_VERSION'] = [i.group(1) for i in version]
57
58 # todo: version checking, if necessary
59
60 self.end_msg('.'.join(self.env['WEBSOCKET_VERSION']))
61
62 self.env['HAVE_WEBSOCKET'] = True
63 self.define('HAVE_WEBSOCKET', 1)
64
65 except Errors.WafError as error:
66 if isMandatory:
67 self.end_msg(str(error), color='RED')
68 Logs.warn('If you are using git NFD repository, checkout websocketpp submodule: ')
69 Logs.warn(' git submodule init && git submodule update')
70 Logs.warn('Otherwise, manually download and extract websocketpp library:')
71 Logs.warn(' mkdir websocketpp')
72 Logs.warn(' curl -L -O https://github.com/zaphoyd/websocketpp/archive/0.3.0-alpha4.tar.gz')
73 Logs.warn(' tar zxf 0.3.0-alpha4.tar.gz -C websocketpp/ --strip 1')
74 Logs.warn('Alternatively, Websocket support can be disabled with --without-websocket')
75 self.fatal("The configuration failed")
76 else:
77 self.end_msg(str(error))