Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 1 | # encoding: utf-8 |
| 2 | |
| 3 | from waflib import Options, Logs, Errors |
| 4 | from waflib.Configure import conf |
| 5 | |
| 6 | import re |
| 7 | |
| 8 | def addWebsocketOptions(self, opt): |
| 9 | opt.add_option('--without-websocket', action='store_false', default=True, |
| 10 | dest='with_websocket', |
| 11 | help='Disable WebSocket face support') |
| 12 | setattr(Options.OptionsContext, "addWebsocketOptions", addWebsocketOptions) |
| 13 | |
| 14 | @conf |
| 15 | def 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 | |
Steve DiBenedetto | ef04f27 | 2014-06-04 14:28:31 -0600 | [diff] [blame] | 62 | |
| 63 | self.env['INCLUDES_WEBSOCKET'] = websocketDir.parent.abspath() |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 64 | 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') |
| 74 | Logs.warn(' curl -L -O https://github.com/zaphoyd/websocketpp/archive/0.3.0-alpha4.tar.gz') |
| 75 | Logs.warn(' tar zxf 0.3.0-alpha4.tar.gz -C websocketpp/ --strip 1') |
| 76 | Logs.warn('Alternatively, Websocket support can be disabled with --without-websocket') |
| 77 | self.fatal("The configuration failed") |
| 78 | else: |
| 79 | self.end_msg(str(error)) |