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 | |
Alexander Afanasyev | 2fdbe86 | 2014-07-25 12:14:49 -0700 | [diff] [blame] | 21 | self.start_msg('Checking for WebSocket includes') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 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: |
Alexander Afanasyev | 2fdbe86 | 2014-07-25 12:14:49 -0700 | [diff] [blame] | 30 | raise Errors.WafError('Corrupted: WebSocket version file not found') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 31 | |
| 32 | try: |
| 33 | txt = versionFile.read() |
| 34 | except (OSError, IOError): |
Alexander Afanasyev | 2fdbe86 | 2014-07-25 12:14:49 -0700 | [diff] [blame] | 35 | raise Errors.WafError('Corrupted: cannot read WebSocket version file') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 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 | self.env['INCLUDES_WEBSOCKET'] = websocketDir.parent.abspath() |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 63 | self.env['HAVE_WEBSOCKET'] = True |
| 64 | self.define('HAVE_WEBSOCKET', 1) |
Wentao Shang | 306df5e | 2014-10-31 15:46:00 -0700 | [diff] [blame^] | 65 | self.define('_WEBSOCKETPP_CPP11_STL_', 1) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 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') |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 74 | Logs.warn(' curl -L https://github.com/zaphoyd/websocketpp/tarball/4309749dd98937b8a7be5dc0bfe679ba201c5512 > websocket.tar.gz') |
Alexander Afanasyev | 2fdbe86 | 2014-07-25 12:14:49 -0700 | [diff] [blame] | 75 | Logs.warn(' tar zxf websocket.tar.gz -C websocketpp/ --strip 1') |
| 76 | Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 77 | self.fatal("The configuration failed") |
| 78 | else: |
| 79 | self.end_msg(str(error)) |