blob: 77de3737c310ed0eff3e861c6b908a63aafac031 [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
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070021 self.start_msg('Checking for WebSocket includes')
Wentao Shang53df1632014-04-21 12:01:32 -070022
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:
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070030 raise Errors.WafError('Corrupted: WebSocket version file not found')
Wentao Shang53df1632014-04-21 12:01:32 -070031
32 try:
33 txt = versionFile.read()
34 except (OSError, IOError):
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070035 raise Errors.WafError('Corrupted: cannot read WebSocket version file')
Wentao Shang53df1632014-04-21 12:01:32 -070036
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
Steve DiBenedettoef04f272014-06-04 14:28:31 -060062
63 self.env['INCLUDES_WEBSOCKET'] = websocketDir.parent.abspath()
Wentao Shang53df1632014-04-21 12:01:32 -070064 self.env['HAVE_WEBSOCKET'] = True
65 self.define('HAVE_WEBSOCKET', 1)
66
67 except Errors.WafError as error:
68 if isMandatory:
69 self.end_msg(str(error), color='RED')
70 Logs.warn('If you are using git NFD repository, checkout websocketpp submodule: ')
71 Logs.warn(' git submodule init && git submodule update')
72 Logs.warn('Otherwise, manually download and extract websocketpp library:')
73 Logs.warn(' mkdir websocketpp')
Wentao Shangb1c1a832014-09-16 11:58:54 -070074 Logs.warn(' curl -L https://github.com/zaphoyd/websocketpp/tarball/e203dbed45409111c2e95cb3e4a1d178ee57d2bc > websocket.tar.gz')
Alexander Afanasyev2fdbe862014-07-25 12:14:49 -070075 Logs.warn(' tar zxf websocket.tar.gz -C websocketpp/ --strip 1')
76 Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket')
Wentao Shang53df1632014-04-21 12:01:32 -070077 self.fatal("The configuration failed")
78 else:
79 self.end_msg(str(error))