diff options
| author | ruki <waruqi@gmail.com> | 2018-08-11 00:45:04 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-08-10 22:30:27 +0800 |
| commit | 985a057cfd771c45d49727b15507f1a6ffbb451f (patch) | |
| tree | 08f978f7d088b51af9735a19a2d5e468adcd7437 /zh | |
| parent | f601b6c82bd122d3d923ed9333cfe0c01d73bc2d (diff) | |
| download | xmake-docs-985a057cfd771c45d49727b15507f1a6ffbb451f.tar.gz xmake-docs-985a057cfd771c45d49727b15507f1a6ffbb451f.zip | |
add is_config and has_config apis
Diffstat (limited to 'zh')
| -rw-r--r-- | zh/manual.md | 122 |
1 files changed, 102 insertions, 20 deletions
diff --git a/zh/manual.md b/zh/manual.md index cb76b946..ba5ab285 100644 --- a/zh/manual.md +++ b/zh/manual.md @@ -9,17 +9,17 @@ search: zh 接口的命名,是有按照预定义的一些规范来命名的,这样更加方便理解和易于使用,目前命名按照如下一些规则: -| 接口规则 | 描述 | -| --------------------- | ------------------------------------------------------------ | -| `is_`前缀的接口 | 表示为条件判断 | -| `set_`前缀的接口 | 表示为覆盖设置 | -| `add_`前缀的接口 | 表示为追加设置 | -| `s`后缀的接口 | 表示支持多值传入,例如:`add_files("*.c", "test.cpp")` | -| `on_`前缀的接口 | 表示为覆盖内置脚本 | -| `before_`前缀的接口 | 表示为在内置脚本运行前,执行此脚本 | -| `after_`前缀的接口 | 表示为在内置脚本运行后,执行此脚本 | -| `scope("name")`的接口 | 表示为定义一个描述域,例如:`target("xxx")`, `option("xxx")` | -| 描述域/描述设置 | 建议缩进表示 | +| 接口规则 | 描述 | +| ----------------------- | ------------------------------------------------------------ | +| `is_`, `has_`前缀的接口 | 表示为条件判断 | +| `set_`前缀的接口 | 表示为覆盖设置 | +| `add_`前缀的接口 | 表示为追加设置 | +| `s`后缀的接口 | 表示支持多值传入,例如:`add_files("*.c", "test.cpp")` | +| `on_`前缀的接口 | 表示为覆盖内置脚本 | +| `before_`前缀的接口 | 表示为在内置脚本运行前,执行此脚本 | +| `after_`前缀的接口 | 表示为在内置脚本运行后,执行此脚本 | +| `scope("name")`的接口 | 表示为定义一个描述域,例如:`target("xxx")`, `option("xxx")` | +| 描述域/描述设置 | 建议缩进表示 | ## 接口文档 @@ -28,15 +28,17 @@ search: zh 条件判断的api,一般用于必须要处理特定平台的编译逻辑的场合。。通常跟lua的if语句配合使用。 -| 接口 | 描述 | 支持版本 | -| ------------------------- | ----------------------------- | -------- | -| [is_os](#is_os) | 判断当前构建目标的操作系统 | >= 2.0.1 | -| [is_arch](#is_arch) | 判断当前编译架构 | >= 2.0.1 | -| [is_plat](#is_plat) | 判断当前编译平台 | >= 2.0.1 | -| [is_host](#is_host) | 判断当前主机环境操作系统 | >= 2.1.4 | -| [is_mode](#is_mode) | 判断当前编译模式 | >= 2.0.1 | -| [is_kind](#is_kind) | 判断当前编译类型 | >= 2.0.1 | -| [is_option](#is_option) | 判断选项是否启用 | >= 2.0.1 | +| 接口 | 描述 | 支持版本 | +| ------------------------- | ----------------------------- | ----------------------- | +| [is_os](#is_os) | 判断当前构建目标的操作系统 | >= 2.0.1 | +| [is_arch](#is_arch) | 判断当前编译架构 | >= 2.0.1 | +| [is_plat](#is_plat) | 判断当前编译平台 | >= 2.0.1 | +| [is_host](#is_host) | 判断当前主机环境操作系统 | >= 2.1.4 | +| [is_mode](#is_mode) | 判断当前编译模式 | >= 2.0.1 | +| [is_kind](#is_kind) | 判断当前编译类型 | >= 2.0.1 | +| [is_option](#is_option) | 判断选项是否启用 | >= 2.0.1 < 2.2.2 已废弃 | +| [is_config](#is_config) | 判断指定配置是否为给定的值 | >= 2.2.2 | +| [has_config](#has_config) | 判断配置是否启用或者存在 | >= 2.2.2 | ##### is_os @@ -239,6 +241,10 @@ $ xmake ###### 判断选项是否启用 +<p class="tips"> +此接口在2.2.2版本之后已经弃用,请使用[has_config](#has_config)来代替。 +</p> + 用于检测自定义的编译配置选型:`xmake f --xxxx=y` 如果某个自动检测选项、手动设置选项被启用,那么可以通过`is_option`接口来判断,例如: @@ -252,6 +258,82 @@ if is_option("demo") then end ``` +##### has_config + +###### 判断配置是否启用或者存在 + +此接口从2.2.2版本开始引入,用于检测自定义或者内置的编译配置是否存在或启用。 + +例如以下配置情况,都会返回true: + +```console +# 启用某个配置选项(如果是boolean类型配置) +$ xmake f --test1=y +$ xmake f --test1=yes +$ xmake f --test1=true + +# 设置某个配置选项的值 +$ xmake f --test2=value +``` + +```lua +-- 如果test1或者test2被设置或者启用 +if has_config("test1", "test2") then + add_defines("TEST") +end +``` + +而下面的情况则会禁用配置,返回false: + +```console +# 禁用配置(如果是boolean类型配置) +$ xmake f --test1=n +$ xmake f --test1=no +$ xmake f --test1=false +``` + +<p class="tips"> +此接口不仅能够判断内置的全局配置、本地配置,同时还可以判断通过[option](#option)定义的自定义配置选项。 +</p> + +##### is_config + +###### 判断指定配置是否为给定的值 + +此接口从2.2.2版本开始引入,用于判断指定配置是否为给定的值。 + +例如: + +```console +$ xmake f --test=hello1 +``` + +```lua +-- 自定义一个配置选项到命令行菜单 +option("test") + set_showmenu("true") + set_description("The test config option") +option_end() + +-- 如果自定义的test配置值是hello1或者hello2 +if is_config("test", "hello1", "hello2") then + add_defines("HELLO") +end +``` + +不仅如此,我们还可以设置模式匹配规则去判断值,例如: + +```lua +-- 如果自定义的test配置值带有hello前缀 +if is_config("test", "hello.*") then + add_defines("HELLO") +end +``` + +<p class="tips"> +此接口不仅能够判断通过[option](#option)定义的自定义配置选项,同时还能判断内置的全局配置、本地配置。 +</p> + #### 全局接口 全局接口影响整个工程描述,被调用后,后面被包含进来的所有子`xmake.lua`都会受影响。 |
