diff options
| author | ruki <waruqi@gmail.com> | 2019-03-31 23:44:59 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2019-03-31 23:44:59 +0800 |
| commit | f94bfa4943c7d6cc4932b38a8578d678da978730 (patch) | |
| tree | c9be9457dbf8e8d7fe00703ff15df081a7c44d38 | |
| parent | f4aaf167e0f2004010b7352a2e3346b8e8eac58c (diff) | |
| download | xmake-docs-f94bfa4943c7d6cc4932b38a8578d678da978730.tar.gz xmake-docs-f94bfa4943c7d6cc4932b38a8578d678da978730.zip | |
update docs
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | manual.md | 89 | ||||
| -rw-r--r-- | zh/README.md | 21 | ||||
| -rw-r--r-- | zh/manual.md | 87 |
4 files changed, 182 insertions, 32 deletions
@@ -991,15 +991,16 @@ Currently this interface supports the following package management support: And through the system and third-party package management tools for the installation of the dependency package, and then integrated with xmake, for example, we look for an openssl package: ```lua -import("lib.detect.find_package") - -local package = find_package("openssl") +local packages = find_packages("openssl", "zlib") ``` The returned results are as follows: ```lua -{links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +{ + {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, + {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +} ``` If the search is successful, return a table containing all the package information, if it fails, return nil @@ -1010,22 +1011,20 @@ The return result here can be directly passed as the parameter of `target:add`, option("zlib") set_showmenu(true) before_check(function (option) - import("lib.detect.find_package") - option:add(find_package("zlib")) + option:add(find_packages("openssl", "zlib")) end) ``` ```lua target("test") on_load(function (target) - import("lib.detect.find_package") - target:add(find_package("zlib")) + target:add(find_packages("openssl", "zlib")) end) ``` If third-party tools such as `homebrew`, `pkg-config` are installed on the system, then this interface will try to use them to improve the search results. -For a more complete description of the usage, please refer to the [lib.detect.find_package](https://xmake.io/#/en/manual?id=detect-find_package) interface documentation. +For a more complete description of the usage, please refer to the [find_packages](https://xmake.io/#/en/manual?id=find_packages) interface documentation. ##### Homebrew Integration Support @@ -321,7 +321,7 @@ but also the custom options defined through the [option](#option). This interface is introduced from version 2.2.3 to detect whether a dependent package exists or is enabled. -It is usually used to [ add_requires](#add_requires). +It is usually used to [add_requires](#add_requires). ```lua add_requires("tbox", {optional = true}) @@ -682,17 +682,64 @@ target("test") add_packages("openssl", "mbedtls") ``` -For example, above, so relying on two ssl packages at the same time, in fact only will enable the ssl package that is valid for the actual installation, and will not link two dependent packages at the same time. +After version 2.2.5, xmake supports support for dependency libraries in third-party package managers, such as: conan, brew, vcpkg, etc. -We also added the `on_load` parameter, which will be called after the dependency package is loaded successfully, providing the user with a chance to set some other flags, for example: +Add a homebrew dependency package: ```lua -add_requires("tbox", {on_load = function (package) - package:add("defines_h", "PACKAGE_HAVE_TBOX") -end}) +add_requires("brew::zlib", {alias = "zlib"}}) +add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("pcre2", "zlib") +``` + +Add a dependency package for vcpkg: + +```lua +add_requires("vcpkg::zlib", "vcpkg::pcre2") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("vcpkg::zlib", "vcpkg::pcre2") +``` + +Add a conan dependency package: + +```lua +add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) +add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", + configs = {options = "OpenSSL:shared=True"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("openssl", "zlib") +``` + +After executing xmake to compile: + +```console +ruki:test_package ruki$ xmake +checking for the architecture ... x86_64 +checking for the Xcode directory ... /Applications/Xcode.app +checking for the SDK version of Xcode ... 10.14 +note: try installing these packages (pass -y to skip confirm)? + -> CONAN::zlib/1.2.11@conan/stable (debug) + -> CONAN::OpenSSL/1.0.2n@conan/stable +please input: y (y/n) + + => installing CONAN::zlib/1.2.11@conan/stable .. ok + => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok + +[ 0%]: ccache compiling.release src/main.c +[100%]: linking.release test ``` -After the dependent package tbox is loaded, add the `PACKAGE_HAVE_TBOX` macro to `config.h`. +We can see https://github.com/xmake-io/xmake/issues/339 to know more details. ##### add_repositories @@ -4960,6 +5007,7 @@ end) | [string](#string) | 字符串操作模块 | 描述域、脚本域 | >= 2.0.1 | | [process](#process) | 进程操作模块 | 脚本域 | >= 2.0.1 | | [coroutine](#coroutine) | 协程操作模块 | 脚本域 | >= 2.0.1 | +| [find_packages](#find_packages) | 查找依赖包 | 脚本域 | >= 2.2.5 | 在描述域使用接口调用的实例如下,一般仅用于条件控制: @@ -5537,6 +5585,21 @@ if (errors) raise(errors) 如果在try块中抛出异常,就会在catch和finally中进行errors信息捕获,具体见:[try-catch](#try-catch-finally) +##### find_packages + +###### 查找依赖包 + +此接口是对[lib.detect.find_package](#detect-find_package)接口的封装,提供多个依赖包的查找支持,例如: + +```lua +target("test") + set_kind("binary") + add_files("src/*.c") + on_load(function (target) + target:add(find_packages("openssl", "zlib")) + end) +``` + ##### os 系统操作模块,属于内置模块,无需使用[import](#import)导入,可直接脚本域调用其接口。 @@ -7857,6 +7920,18 @@ end 我们也可以通过`xmake lua lib.detect.find_package openssl` 来快速测试。 +2.2.5版本之后,新增了内置接口[find_packages](#find_packages),可以同时查找多个包,并且不需要通过import导入即可直接使用。 + +并且此版本之后,支持显式的从指定第三方包管理器中查找包,例如: + +```lua +find_package("brew::pcre2/libpcre2-8") +``` + +由于每个第三方包管理器的包名不完全一致,比如pcre2在homebrew中有三个库版本,我们可以通过上面的方式,指定查找对应libpcre2-8版本的库。 + +另外,对于vcpkg, conan也可以通过加上`vcpkg::`, `conan::`包命名空间来指定查找里面的库。 + ###### detect.find_tool - 查找工具 diff --git a/zh/README.md b/zh/README.md index 3bfb283c..70f5bcae 100644 --- a/zh/README.md +++ b/zh/README.md @@ -1041,7 +1041,7 @@ $ xmake package -o ../test/packages #### 系统查找模式 -如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的扩展接口[lib.detect.find_package](https://xmake.io/#/zh/manual?id=detect-find_package)去查找系统已有的依赖包。 +如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 目前此接口支持以下一些包管理支持: @@ -1052,15 +1052,16 @@ $ xmake package -o ../test/packages 并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: ```lua -import("lib.detect.find_package") - -local package = find_package("openssl") +local packages = find_packages("openssl", "zlib") ``` 返回的结果如下: ```lua -{links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +{ + {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, + {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +} ``` 如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil @@ -1071,26 +1072,24 @@ local package = find_package("openssl") option("zlib") set_showmenu(true) before_check(function (option) - import("lib.detect.find_package") - option:add(find_package("zlib")) + option:add(find_packages("openssl", "zlib")) end) ``` ```lua target("test") on_load(function (target) - import("lib.detect.find_package") - target:add(find_package("zlib")) + target:add(find_package("openssl", "zlib")) end) ``` 如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 -更完整的使用描述,请参考:[lib.detect.find_package](https://xmake.io/#/zh/manual?id=detect-find_package)接口文档。 +更完整的使用描述,请参考:[find_packages](https://xmake.io/#/zh/manual?id=find_packages)接口文档。 ##### homebrew集成支持 -由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`lib.detect.find_package`就已经原生无缝支持。 +由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 ##### vcpkg集成支持 diff --git a/zh/manual.md b/zh/manual.md index 72bbcd2b..e8508468 100644 --- a/zh/manual.md +++ b/zh/manual.md @@ -709,15 +709,64 @@ target("test") 例如上面,所以同时依赖两个ssl包,实际上只会启用生效实际安装成功的那一个ssl包,并不会同时链接两个依赖包。 -我们还新增了`on_load`参数,在依赖包加载成功后,会被调用,提供用户一个机会去设置一些其他的flags,例如: +2.2.5版本之后,xmake支持对对第三方包管理器里面的依赖库安装支持,例如:conan,brew, vcpkg等 + +添加homebrew的依赖包: ```lua -add_requires("tbox", {on_load = function (package) - package:add("defines_h", "PACKAGE_HAVE_TBOX") -end}) +add_requires("brew::zlib", {alias = "zlib"}}) +add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("pcre2", "zlib") +``` + +添加vcpkg的依赖包: + +```lua +add_requires("vcpkg::zlib", "vcpkg::pcre2") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("vcpkg::zlib", "vcpkg::pcre2") +``` + +添加conan的依赖包: + +```lua +add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) +add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", + configs = {options = "OpenSSL:shared=True"}}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("openssl", "zlib") +``` + +执行xmake进行编译后: + +```console +ruki:test_package ruki$ xmake +checking for the architecture ... x86_64 +checking for the Xcode directory ... /Applications/Xcode.app +checking for the SDK version of Xcode ... 10.14 +note: try installing these packages (pass -y to skip confirm)? + -> CONAN::zlib/1.2.11@conan/stable (debug) + -> CONAN::OpenSSL/1.0.2n@conan/stable +please input: y (y/n) + + => installing CONAN::zlib/1.2.11@conan/stable .. ok + => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok + +[ 0%]: ccache compiling.release src/main.c +[100%]: linking.release test ``` -当依赖包tbox生效加载后,添加`PACKAGE_HAVE_TBOX`宏到`config.h`中去。 +关于这块的更多详情见:https://github.com/xmake-io/xmake/issues/339 ##### add_repositories @@ -5031,6 +5080,7 @@ end) | [string](#string) | 字符串操作模块 | 描述域、脚本域 | >= 2.0.1 | | [process](#process) | 进程操作模块 | 脚本域 | >= 2.0.1 | | [coroutine](#coroutine) | 协程操作模块 | 脚本域 | >= 2.0.1 | +| [find_packages](#find_packages) | 查找依赖包 | 脚本域 | >= 2.2.5 | 在描述域使用接口调用的实例如下,一般仅用于条件控制: @@ -5608,6 +5658,21 @@ if (errors) raise(errors) 如果在try块中抛出异常,就会在catch和finally中进行errors信息捕获,具体见:[try-catch](#try-catch-finally) +##### find_packages + +###### 查找依赖包 + +此接口是对[lib.detect.find_package](#detect-find_package)接口的封装,提供多个依赖包的查找支持,例如: + +```lua +target("test") + set_kind("binary") + add_files("src/*.c") + on_load(function (target) + target:add(find_packages("openssl", "zlib")) + end) +``` + ##### os 系统操作模块,属于内置模块,无需使用[import](#import)导入,可直接脚本域调用其接口。 @@ -7934,6 +7999,18 @@ end 我们也可以通过`xmake lua lib.detect.find_package openssl` 来快速测试。 +2.2.5版本之后,新增了内置接口[find_packages](#find_packages),可以同时查找多个包,并且不需要通过import导入即可直接使用。 + +并且此版本之后,支持显式的从指定第三方包管理器中查找包,例如: + +```lua +find_package("brew::pcre2/libpcre2-8") +``` + +由于每个第三方包管理器的包名不完全一致,比如pcre2在homebrew中有三个库版本,我们可以通过上面的方式,指定查找对应libpcre2-8版本的库。 + +另外,对于vcpkg, conan也可以通过加上`vcpkg::`, `conan::`包命名空间来指定查找里面的库。 + ###### detect.find_tool - 查找工具 |
