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 /manual.md | |
| parent | f4aaf167e0f2004010b7352a2e3346b8e8eac58c (diff) | |
| download | xmake-docs-f94bfa4943c7d6cc4932b38a8578d678da978730.tar.gz xmake-docs-f94bfa4943c7d6cc4932b38a8578d678da978730.zip | |
update docs
Diffstat (limited to 'manual.md')
| -rw-r--r-- | manual.md | 89 |
1 files changed, 82 insertions, 7 deletions
@@ -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 - 查找工具 |
