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') |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 9 | |
| 10 | setattr(Options.OptionsContext, 'addWebsocketOptions', addWebsocketOptions) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 11 | |
Davide Pesavento | 67f3027 | 2016-08-10 01:55:16 +0000 | [diff] [blame] | 12 | @Configure.conf |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 13 | def checkWebsocket(self, **kw): |
| 14 | if not self.options.with_websocket: |
| 15 | return |
| 16 | |
| 17 | isMandatory = kw.get('mandatory', True) |
| 18 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 19 | self.start_msg('Checking for WebSocket++ includes') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 20 | |
| 21 | try: |
| 22 | websocketDir = self.path.find_dir('websocketpp/websocketpp') |
| 23 | if not websocketDir: |
| 24 | raise Errors.WafError('Not found') |
| 25 | |
| 26 | versionFile = websocketDir.find_node('version.hpp') |
| 27 | if not websocketDir: |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 28 | raise Errors.WafError('WebSocket++ version file not found') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 29 | |
| 30 | try: |
| 31 | txt = versionFile.read() |
| 32 | except (OSError, IOError): |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 33 | raise Errors.WafError('Cannot read WebSocket++ version file') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 35 | version = [None, None, None] |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 36 | # Looking for the following: |
| 37 | # static int const major_version = 0; |
Eric Newberry | 25a8407 | 2016-06-20 18:38:15 -0700 | [diff] [blame] | 38 | # static int const minor_version = 7; |
| 39 | # static int const patch_version = 0; |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 40 | majorVersion = re.compile('^static int const major_version = (\\d+);$', re.M) |
| 41 | version[0] = majorVersion.search(txt) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 42 | minorVersion = re.compile('^static int const minor_version = (\\d+);$', re.M) |
| 43 | version[1] = minorVersion.search(txt) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 44 | patchVersion = re.compile('^static int const patch_version = (\\d+);$', re.M) |
| 45 | version[2] = patchVersion.search(txt) |
| 46 | |
| 47 | if not version[0] or not version[1] or not version[2]: |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 48 | raise Errors.WafError('Cannot detect WebSocket++ version') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 49 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 50 | self.env.WEBSOCKET_VERSION = [i.group(1) for i in version] |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 51 | |
| 52 | # todo: version checking, if necessary |
| 53 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 54 | self.end_msg('.'.join(self.env.WEBSOCKET_VERSION)) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 55 | |
Davide Pesavento | 0064c1d | 2018-03-03 18:43:53 -0500 | [diff] [blame] | 56 | self.env.INCLUDES_WEBSOCKET = websocketDir.parent.abspath() |
| 57 | self.env.HAVE_WEBSOCKET = True |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 58 | self.define('HAVE_WEBSOCKET', 1) |
Wentao Shang | 306df5e | 2014-10-31 15:46:00 -0700 | [diff] [blame] | 59 | self.define('_WEBSOCKETPP_CPP11_STL_', 1) |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 60 | |
| 61 | except Errors.WafError as error: |
| 62 | if isMandatory: |
| 63 | self.end_msg(str(error), color='RED') |
Davide Pesavento | 9be9980 | 2018-11-10 14:40:26 -0500 | [diff] [blame] | 64 | Logs.warn('If you are using NFD from the git repository, checkout the websocketpp submodule: ') |
Davide Pesavento | 5f35f64 | 2018-05-10 19:36:03 -0400 | [diff] [blame] | 65 | Logs.warn(' git submodule update --init') |
Davide Pesavento | 9be9980 | 2018-11-10 14:40:26 -0500 | [diff] [blame] | 66 | Logs.warn('Otherwise, manually download and extract the websocketpp library:') |
| 67 | Logs.warn(' mkdir -p websocketpp') |
Alexander Afanasyev | a6bd7da | 2019-04-25 17:26:11 -0400 | [diff] [blame] | 68 | Logs.warn(' curl -L https://github.com/cawka/websocketpp/archive/0.8.1-hotfix.tar.gz > websocketpp.tar.gz') |
Davide Pesavento | 9be9980 | 2018-11-10 14:40:26 -0500 | [diff] [blame] | 69 | Logs.warn(' tar xf websocketpp.tar.gz -C websocketpp/ --strip 1') |
Alexander Afanasyev | 2fdbe86 | 2014-07-25 12:14:49 -0700 | [diff] [blame] | 70 | Logs.warn('Alternatively, WebSocket support can be disabled with --without-websocket') |
Davide Pesavento | 9be9980 | 2018-11-10 14:40:26 -0500 | [diff] [blame] | 71 | self.fatal('WebSocket++ not found') |
Wentao Shang | 53df163 | 2014-04-21 12:01:32 -0700 | [diff] [blame] | 72 | else: |
| 73 | self.end_msg(str(error)) |