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