add build option to disable repl, use feature objects

master
Daniel Kolesa 2021-03-28 00:56:11 +01:00
parent 71f45b2f07
commit 371ef9e912
3 changed files with 48 additions and 23 deletions

View File

@ -73,8 +73,8 @@ utilized in the outside native code.
There are no dependencies (other than a suitable compiler and the standard
library).
Libostd is built using Meson. Therefore, you need to install Meson and then
you can compile it as usual. Typically, this will be something like
Libcubescript is built using `meson`. After installing it, you can do
something like this:
~~~
mkdir build && cd build
@ -82,15 +82,22 @@ meson ..
ninja all
~~~
Link the libcubescript library together with your application and everything
should just work. It also builds the REPL.
Link the `libcubescript` library together with your application and everything
should just work. It also builds the REPL by default.
The project also bundles the linenoise line editing library which has been
modified to compile cleanly as C++ (with the same flags as libcubescript).
The project also bundles the `linenoise` line editing library which has been
modified to compile cleanly as C++ (with the same flags as `libcubescript`).
It's used strictly for the REPL only (you don't need it to build libcubescript
itself). The version in the repository tracks Git revision
https://github.com/antirez/linenoise/commit/c894b9e59f02203dbe4e2be657572cf88c4230c3.
For the REPL (when not disabled with `-Drepl=disabled`) you have a choice of
two line editing libraries. The `readline` library can be used (but is always
disabled by default, so you need to enable it manually). On Unix-like systems,
`linenoise` can be used (and is fully featured) and is enabled by default; on
Windows it's disabled. There is also a fallback without any line editing, used
when you don't have either (but then there is no line editing or history).
## Licensing
See COPYING.md for licensing information.

View File

@ -1,11 +1,17 @@
option('repl',
type: 'feature',
value: 'auto',
description: 'Enable the REPL (command line tool)'
)
option('readline',
type: 'boolean',
value: false,
type: 'feature',
value: 'auto',
description: 'Use GNU readline for the REPL'
)
option('linenoise',
type: 'boolean',
value: true,
type: 'feature',
value: 'auto',
description: 'Use linenoise for the REPL'
)

View File

@ -5,18 +5,30 @@ repl_src = [
repl_deps = [libcubescript]
repl_flags = []
if get_option('readline')
repl_deps += [dependency('readline')]
repl_flags = ['-DCS_REPL_USE_READLINE']
elif get_option('linenoise')
repl_src += ['linenoise.cc']
repl_flags = ['-DCS_REPL_USE_LINENOISE']
if get_option('readline').enabled()
use_readline = true
use_linenoise = false
elif get_option('linenoise').enabled()
use_readline = false
use_linenoise = true
elif get_option('linenoise').auto()
use_readline = false
use_linenoise = (host_machine.system() != 'windows')
endif
executable('cubescript',
repl_src,
dependencies: repl_deps,
include_directories: libcubescript_includes + [include_directories('.')],
cpp_args: extra_cxxflags + repl_flags,
install: true
)
if not get_option('repl').disabled()
if use_readline
repl_deps += [dependency('readline')]
repl_flags = ['-DCS_REPL_USE_READLINE']
elif use_linenoise
repl_src += ['linenoise.cc']
repl_flags = ['-DCS_REPL_USE_LINENOISE']
endif
executable('cubescript',
repl_src,
dependencies: repl_deps,
include_directories: libcubescript_includes + [include_directories('.')],
cpp_args: extra_cxxflags + repl_flags,
install: true
)
endif