diff options
| author | ruki <waruqi@gmail.com> | 2019-07-27 00:17:29 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2019-07-27 00:17:29 +0800 |
| commit | 42066f46af45364f429a8ab4abd6f2ed3c9cbff1 (patch) | |
| tree | 8e31c83243fbee5aa06695c11e2396ad7d6e2cbc | |
| parent | aaeddf48841d253a97598dd38a6644a289a4ff6b (diff) | |
| download | xmake-docs-42066f46af45364f429a8ab4abd6f2ed3c9cbff1.tar.gz xmake-docs-42066f46af45364f429a8ab4abd6f2ed3c9cbff1.zip | |
update package sidebar
| -rw-r--r-- | _sidebar.md | 7 | ||||
| -rw-r--r-- | package/local_package.md | 46 | ||||
| -rw-r--r-- | package/remote_package.md (renamed from guide/package_management.md) | 167 | ||||
| -rw-r--r-- | package/system_package.md | 73 | ||||
| -rw-r--r-- | zh-cn/_sidebar.md | 7 | ||||
| -rw-r--r-- | zh-cn/package/local_package.md | 46 | ||||
| -rw-r--r-- | zh-cn/package/remote_package.md (renamed from zh-cn/guide/package_management.md) | 169 | ||||
| -rw-r--r-- | zh-cn/package/system_package.md | 73 |
8 files changed, 295 insertions, 293 deletions
diff --git a/_sidebar.md b/_sidebar.md index 063cc731..8a361d33 100644 --- a/_sidebar.md +++ b/_sidebar.md @@ -13,9 +13,14 @@ - [Project Examples](guide/project_examples.md) - [Configuration](guide/configuration.md) - [Syntax Description](guide/syntax_description.md) - - [Package Management](guide/package_management.md) - [FAQ](guide/faq.md) +- Package Management + + - [Local Package](package/local_package.md) + - [System Package](package/system_package.md) + - [Remote Package](package/remote_package.md) + - Plugin - [Plugin Development](plugin/plugin_development.md) diff --git a/package/local_package.md b/package/local_package.md new file mode 100644 index 00000000..f84f8264 --- /dev/null +++ b/package/local_package.md @@ -0,0 +1,46 @@ + +By including a dependency package directory and some binary library files in the project, it is convenient to integrate some third-party dependency libraries. This method is relatively simple and straightforward, but the disadvantages are also obvious and inconvenient to manage. + +Take the tbox project as an example. The dependency package is as follows: + +``` +- base.pkg +- zlib.pkg +- polarssl.pkg +- openssl.pkg +- mysql.pkg +- pcre.pkg +- ... +``` + +If you want the current project to recognize loading these packages, you first need to specify the package directory path, for example: + +```lua +add_packagedirs("packages") +``` + +Once specified, you can add integration package dependencies in the target scope via the [add_packages](/manual/project_target?id=targetadd_packages) interface, for example: + +```lua +target("tbox") + add_packages("zlib", "polarssl", "pcre", "mysql") +``` + +So how to generate a *.pkg package, if it is based on xmake project, the generation method is very simple, only need: + +```console +$ cd tbox +$ xmake package +``` + +You can generate a tbox.pkg cross-platform package in the build directory for use by third-party projects. I can also directly set the output directory and compile and generate it into the other project, for example: + +```console +$ cd tbox +$ xmake package -o ../test/packages +``` + +In this way, the test project can pass [add_packages](/manual/project_target?id=targetadd_packages) and [add_packagedirs](/manual/global_interfaces?id=add_packagedirs) to configure and use the tbox.pkg package. + +For a detailed description of the built-in package, you can also refer to the following related article, which is described in detail: [Dependency package addition and automatic detection mechanism](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) + diff --git a/guide/package_management.md b/package/remote_package.md index e5f003eb..5bb180fa 100644 --- a/guide/package_management.md +++ b/package/remote_package.md @@ -1,127 +1,4 @@ -## Local Package Mode - -By including a dependency package directory and some binary library files in the project, it is convenient to integrate some third-party dependency libraries. This method is relatively simple and straightforward, but the disadvantages are also obvious and inconvenient to manage. - -Take the tbox project as an example. The dependency package is as follows: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -If you want the current project to recognize loading these packages, you first need to specify the package directory path, for example: - -```lua -add_packagedirs("packages") -``` - -Once specified, you can add integration package dependencies in the target scope via the [add_packages](/manual/project_target?id=targetadd_packages) interface, for example: - -```lua -target("tbox") - add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -So how to generate a *.pkg package, if it is based on xmake project, the generation method is very simple, only need: - -```console -$ cd tbox -$ xmake package -``` - -You can generate a tbox.pkg cross-platform package in the build directory for use by third-party projects. I can also directly set the output directory and compile and generate it into the other project, for example: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -In this way, the test project can pass [add_packages](/manual/project_target?id=targetadd_packages) and [add_packagedirs](/manual/global_interfaces?id=add_packagedirs) to configure and use the tbox.pkg package. - -For a detailed description of the built-in package, you can also refer to the following related article, which is described in detail: [Dependency package addition and automatic detection mechanism](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -## System Search Mode - -If you feel that the above built-in package management method is very inconvenient, you can use the extension interface [lib.detect.find_package](/manual/extension_modules?id=detectfind_package) to find the system. Existing dependencies. - -Currently this interface supports the following package management support: - -* vcpkg -* homebrew -* pkg-config - -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 -local packages = find_packages("openssl", "zlib") -``` - -The returned results are as follows: - -```lua -{ - {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 - -The return result here can be directly passed as the parameter of `target:add`, `option:add`, which is used to dynamically increase the configuration of `target/option`: - -```lua -option("zlib") - set_showmenu(true) - before_check(function (option) - option:add(find_packages("openssl", "zlib")) - end) -``` - -```lua -target("test") - on_load(function (target) - 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. - -Another, we can also find packages from the given package manager. For example: - -```lua -find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") -``` - -For a more complete description of the usage, please refer to the [find_packages](/manual/builtin_modules?id=find_packages) interface documentation. - -### Homebrew Integration Support - -Since homebrew is generally installed directly into the system, users do not need to do any integration work, `lib.detect.find_package` has been natively seamlessly supported. - -### Vcpkg Integration Support - -Currently xmake v2.2.2 version already supports vcpkg, users only need to install vcpkg, execute `$ vcpkg integrate install`, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread. - -Of course, we can also manually specify the root path of vcpkg to support: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -Or we can set it to the global configuration to avoid repeating the settings each time we switch configurations: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -## Remote dependency mode - This has been initially supported after the 2.2.2 version, the usage is much simpler, just set the corresponding dependency package, for example: ```lua @@ -147,14 +24,14 @@ xmake will remotely pull the relevant source package, then automatically compile For more information and progress on package dependency management see the related issues: [Remote package management](https://github.com/xmake-io/xmake/issues/69) -### Currently Supported Features +## Currently Supported Features * Semantic version support, for example: ">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" * Provide multi-repository management support such as official package repository, self-built private repository, project built-in repository, etc. * Cross-platform package compilation integration support (packages of different platforms and different architectures can be installed at the same time, fast switching use) * Debug dependency package support, source code debugging -### Dependency Package Processing Mechanism +## Dependency Package Processing Mechanism Here we briefly introduce the processing mechanism of the entire dependency package: @@ -166,7 +43,7 @@ Here we briefly introduce the processing mechanism of the entire dependency pack 2. Retrieve the package matching the corresponding version, then download, compile, and install (Note: installed in a specific xmake directory, will not interfere with the system library environment) 3. Compile the project, and finally automatically link the enabled dependencies -### Semantic Version Settings +## Semantic Version Settings Xmake's dependency package management fully supports semantic version selection, for example: "~1.6.1". For a detailed description of the semantic version, see: [https://semver.org/](https://semver.org/) @@ -192,9 +69,9 @@ add_requires("tbox master") add_requires("tbox dev") ``` -### Extra Package Information Settings +## Extra Package Information Settings -#### Optional Package Settings +### Optional Package Settings If the specified dependency package is not supported by the current platform, or if the compilation and installation fails, then xmake will compile the error, which is reasonable for some projects that must rely on certain packages to work. However, if some packages are optional dependencies, they can be set to optional packages even if they are not compiled properly. @@ -203,7 +80,7 @@ However, if some packages are optional dependencies, they can be set to optional add_requires("tbox", {optional = true}) ``` -#### Disable System Library +### Disable System Library With the default settings, xmake will first check to see if the system library exists (if no version is required). If the user does not want to use the system library and the library provided by the third-party package management, then you can set: @@ -211,7 +88,7 @@ With the default settings, xmake will first check to see if the system library e add_requires("tbox", {system = false}) ``` -#### Using the debug version of the package +### Using the debug version of the package If we want to debug the dependencies at the same time, we can set them to use the debug version of the package (provided that this package supports debug compilation): @@ -230,7 +107,7 @@ package("openssl") end) ``` -#### Passing additional compilation information to the package +### Passing additional compilation information to the package Some packages have various compile options at compile time, and we can pass them in. Of course, the package itself supports: @@ -240,11 +117,11 @@ add_requires("tbox", {configs = {small=true}}) Pass `--small=true` to the tbox package so that compiling the installed tbox package is enabled. -### Install third-party packages +## Install third-party packages After version 2.2.5, xmake supports support for dependency libraries in third-party package managers, such as: conan, brew, vcpkg, clib and etc. -#### Add a homebrew dependency package +### Add a homebrew dependency package ```lua add_requires("brew::zlib", {alias = "zlib"}}) @@ -256,7 +133,7 @@ target("test") add_packages("pcre2", "zlib") ``` -#### Add a vcpkg dependency package +### Add a vcpkg dependency package ```lua add_requires("vcpkg::zlib", "vcpkg::pcre2") @@ -267,7 +144,7 @@ target("test") add_packages("vcpkg::zlib", "vcpkg::pcre2") ``` -#### Add a conan dependency package +### Add a conan dependency package ```lua add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) @@ -299,7 +176,7 @@ please input: y (y/n) [100%]: linking.release test ``` -#### Add a clib dependency package +### Add a clib dependency package Clib is a source-based dependency package manager. The dependent package is downloaded directly to the corresponding library source code, integrated into the project to compile, rather than binary library dependencies. @@ -315,7 +192,7 @@ target("test") add_packages("bytes") ``` -### Using self-built private package repository +## Using self-built private package repository If the required package is not in the official repository [xmake-repo](https://github.com/xmake-io/xmake-repo), we can submit the contribution code to the repository for support. But if some packages are only for personal or private projects, we can create a private repository repo. The repository organization structure can be found at: [xmake-repo](https://github.com/xmake-io/xmake-repo) @@ -391,11 +268,11 @@ target("test") add_packages("libjpeg") ``` -### Package Management Command +## Package Management Command The package management command `$ xmake require` can be used to manually display the download, install, uninstall, retrieve, and view package information. -#### Install the specified package +### Install the specified package ```console $ xmake require tbox @@ -421,7 +298,7 @@ $ xmake require --extra="debug=true,config={small=true}" tbox Install the debug package and pass the compilation configuration information of `small=true` to the package. -#### Uninstall the specified package +### Uninstall the specified package ```console $ xmake require --uninstall tbox @@ -429,13 +306,13 @@ $ xmake require --uninstall tbox This will completely uninstall the removal package file. -#### Show package information +### Show package information ```console $ xmake require --info tbox ``` -#### Search for packages in the current repository +### Search for packages in the current repository ```console $ xmake require --search tbox @@ -449,13 +326,13 @@ $ xmake require --search pcr Will also search for pcre, pcre2 and other packages. -#### List the currently installed packages +### List the currently installed packages ```console $ xmake require --list ``` -### Repository Management Command +## Repository Management Command As mentioned above, adding a private repository is available (supporting local path addition): @@ -481,7 +358,7 @@ If the remote repository has updates, you can manually perform a repository upda $ xmake repo -u ``` -### Submit package to the official repository +## Submit package to the official repository If you need a package that is not supported by the current official repository, you can commit it to the official repository after local tuning: [xmake-repo](https://github.com/xmake-io/xmake-repo) diff --git a/package/system_package.md b/package/system_package.md new file mode 100644 index 00000000..a1650c73 --- /dev/null +++ b/package/system_package.md @@ -0,0 +1,73 @@ + +If you feel that the above built-in package management method is very inconvenient, you can use the extension interface [lib.detect.find_package](/manual/extension_modules?id=detectfind_package) to find the system. Existing dependencies. + +Currently this interface supports the following package management support: + +* vcpkg +* homebrew +* pkg-config + +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 +local packages = find_packages("openssl", "zlib") +``` + +The returned results are as follows: + +```lua +{ + {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 + +The return result here can be directly passed as the parameter of `target:add`, `option:add`, which is used to dynamically increase the configuration of `target/option`: + +```lua +option("zlib") + set_showmenu(true) + before_check(function (option) + option:add(find_packages("openssl", "zlib")) + end) +``` + +```lua +target("test") + on_load(function (target) + 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. + +Another, we can also find packages from the given package manager. For example: + +```lua +find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") +``` + +For a more complete description of the usage, please refer to the [find_packages](/manual/builtin_modules?id=find_packages) interface documentation. + +## Homebrew Integration Support + +Since homebrew is generally installed directly into the system, users do not need to do any integration work, `lib.detect.find_package` has been natively seamlessly supported. + +## Vcpkg Integration Support + +Currently xmake v2.2.2 version already supports vcpkg, users only need to install vcpkg, execute `$ vcpkg integrate install`, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread. + +Of course, we can also manually specify the root path of vcpkg to support: + +```console +$ xmake f --vcpkg=f:\vcpkg +``` + +Or we can set it to the global configuration to avoid repeating the settings each time we switch configurations: + +```console +$ xmake g --vcpkg=f:\vcpkg +``` + diff --git a/zh-cn/_sidebar.md b/zh-cn/_sidebar.md index f4b9cfe9..915e813d 100644 --- a/zh-cn/_sidebar.md +++ b/zh-cn/_sidebar.md @@ -13,9 +13,14 @@ - [工程例子](zh-cn/guide/project_examples.md) - [配置说明](zh-cn/guide/configuration.md) - [语法描述](zh-cn/guide/syntax_description.md) - - [包依赖管理](zh-cn/guide/package_management.md) - [问答](zh-cn/guide/faq.md) +- 包依赖管理 + + - [使用本地包](zh-cn/package/local_package.md) + - [使用系统包](zh-cn/package/system_package.md) + - [使用远程包](zh-cn/package/remote_package.md) + - 插件介绍 - [插件开发](zh-cn/plugin/plugin_development.md) diff --git a/zh-cn/package/local_package.md b/zh-cn/package/local_package.md new file mode 100644 index 00000000..9a24dfb8 --- /dev/null +++ b/zh-cn/package/local_package.md @@ -0,0 +1,46 @@ + +通过在项目中内置依赖包目录以及二进制包文件,可以方便的集成一些第三方的依赖库,这种方式比较简单直接,但是缺点也很明显,不方便管理。 + +以tbox工程为例,其依赖包如下: + +``` +- base.pkg +- zlib.pkg +- polarssl.pkg +- openssl.pkg +- mysql.pkg +- pcre.pkg +- ... +``` + +如果要让当前工程识别加载这些包,首先要指定包目录路径,例如: + +```lua +add_packagedirs("packages") +``` + +指定好后,就可以在target作用域中,通过[add_packages](/zh-cn/manual/project_target?id=targetadd_packages)接口,来添加集成包依赖了,例如: + +```lua +target("tbox") + add_packages("zlib", "polarssl", "pcre", "mysql") +``` + +那么如何去生成一个*.pkg的包呢,如果是基于xmake的工程,生成方式很简单,只需要: + +```console +$ cd tbox +$ xmake package +``` + +即可在build目录下生成一个tbox.pkg的跨平台包,给第三方项目使用,我也可以直接设置输出目录,编译生成到对方项目中去,例如: + +```console +$ cd tbox +$ xmake package -o ../test/packages +``` + +这样,test工程就可以通过[add_packages]((/zh-cn/manual/project_target?id=targetadd_packages)和[add_packagedirs](/zh-cn/manual/global_interfaces?id=add_packagedirs)去配置和使用tbox.pkg包了。 + +关于内置包的详细描述,还可以参考下相关文章,这里面有详细介绍:[依赖包的添加和自动检测机制](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) + diff --git a/zh-cn/guide/package_management.md b/zh-cn/package/remote_package.md index 0be1fdf1..1d736c25 100644 --- a/zh-cn/guide/package_management.md +++ b/zh-cn/package/remote_package.md @@ -1,127 +1,4 @@ -## 本地内置模式 - -通过在项目中内置依赖包目录以及二进制包文件,可以方便的集成一些第三方的依赖库,这种方式比较简单直接,但是缺点也很明显,不方便管理。 - -以tbox工程为例,其依赖包如下: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -如果要让当前工程识别加载这些包,首先要指定包目录路径,例如: - -```lua -add_packagedirs("packages") -``` - -指定好后,就可以在target作用域中,通过[add_packages](/zh-cn/manual/project_target?id=targetadd_packages)接口,来添加集成包依赖了,例如: - -```lua -target("tbox") - add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -那么如何去生成一个*.pkg的包呢,如果是基于xmake的工程,生成方式很简单,只需要: - -```console -$ cd tbox -$ xmake package -``` - -即可在build目录下生成一个tbox.pkg的跨平台包,给第三方项目使用,我也可以直接设置输出目录,编译生成到对方项目中去,例如: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -这样,test工程就可以通过[add_packages]((/zh-cn/manual/project_target?id=targetadd_packages)和[add_packagedirs](/zh-cn/manual/global_interfaces?id=add_packagedirs)去配置和使用tbox.pkg包了。 - -关于内置包的详细描述,还可以参考下相关文章,这里面有详细介绍:[依赖包的添加和自动检测机制](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -## 系统查找模式 - -如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 - -目前此接口支持以下一些包管理支持: - -* vcpkg -* homebrew -* pkg-config - -并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: - -```lua -local packages = find_packages("openssl", "zlib") -``` - -返回的结果如下: - -```lua -{ - {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, - {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -} -``` - -如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil - -这里的返回结果可以直接作为`target:add`, `option:add`的参数传入,用于动态增加`target/option`的配置: - -```lua -option("zlib") - set_showmenu(true) - before_check(function (option) - option:add(find_packages("openssl", "zlib")) - end) -``` - -```lua -target("test") - on_load(function (target) - target:add(find_package("openssl", "zlib")) - end) -``` - -如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 - -另外,我们也可以从指定的包管理器查找包: - -```lua -find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") -``` - -更完整的使用描述,请参考:[find_packages](/zh-cn/manual/builtin_modules?id=find_packages)接口文档。 - -### homebrew集成支持 - -由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 - -### vcpkg集成支持 - -目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。 - -当然,我们也可以手动指定vcpkg的根路径来支持: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -## 远程依赖模式 - 这个在2.2.2版本后已经初步支持,用法上更加的简单,只需要设置对应的依赖包就行了,例如: ```lua @@ -147,14 +24,14 @@ xmake会去远程拉取相关源码包,然后自动编译安装,最后编译 关于包依赖管理的更多相关信息和进展见相关issues:[Remote package management](https://github.com/xmake-io/xmake/issues/69) -### 目前支持的特性 +## 目前支持的特性 * 语义版本支持,例如:">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" * 提供官方包仓库、自建私有仓库、项目内置仓库等多仓库管理支持 * 跨平台包编译集成支持(不同平台、不同架构的包可同时安装,快速切换使用) * debug依赖包支持,实现源码调试 -### 依赖包处理机制 +## 依赖包处理机制 这里我们简单介绍下整个依赖包的处理机制: @@ -164,7 +41,7 @@ xmake会去远程拉取相关源码包,然后自动编译安装,最后编译 2. 检索匹配对应版本的包,然后下载、编译、安装(注:安装在特定xmake目录,不会干扰系统库环境) 3. 编译项目,最后自动链接启用的依赖包 -### 快速上手 +## 快速上手 新建一个依赖tbox库的空工程: @@ -193,7 +70,7 @@ $ xmake f -p android [--ndk=~/android-ndk-r16b] $ xmake ``` -### 语义版本设置 +## 语义版本设置 xmake的依赖包管理是完全支持语义版本选择的,例如:"~1.6.1",对于语义版本的具体描述见:[https://semver.org/](https://semver.org/) @@ -219,9 +96,9 @@ add_requires("tbox master") add_requires("tbox dev") ``` -### 额外的包信息设置 +## 额外的包信息设置 -#### 可选包设置 +### 可选包设置 如果指定的依赖包当前平台不支持,或者编译安装失败了,那么xmake会编译报错,这对于有些必须要依赖某些包才能工作的项目,这是合理的。 但是如果有些包是可选的依赖,即使没有也可以正常编译使用的话,可以设置为可选包: @@ -230,7 +107,7 @@ add_requires("tbox dev") add_requires("tbox", {optional = true}) ``` -#### 禁用系统库 +### 禁用系统库 默认的设置,xmake会去优先检测系统库是否存在(如果没设置版本要求),如果用户完全不想使用系统库以及第三方包管理提供的库,那么可以设置: @@ -238,7 +115,7 @@ add_requires("tbox", {optional = true}) add_requires("tbox", {system = false}) ``` -#### 使用调试版本的包 +### 使用调试版本的包 如果我们想同时源码调试依赖包,那么可以设置为使用debug版本的包(当然前提是这个包支持debug编译): @@ -257,7 +134,7 @@ package("openssl") end) ``` -#### 传递额外的编译信息到包 +### 传递额外的编译信息到包 某些包在编译时候有各种编译选项,我们也可以传递进来,当然包本身得支持: @@ -267,11 +144,11 @@ add_requires("tbox", {configs = {small=true}}) 传递`--small=true`给tbox包,使得编译安装的tbox包是启用此选项的。 -### 第三方依赖包安装 +## 第三方依赖包安装 2.2.5版本之后,xmake支持对对第三方包管理器里面的依赖库安装支持,例如:conan,brew, vcpkg等 -#### 添加homebrew的依赖包 +### 添加homebrew的依赖包 ```lua add_requires("brew::zlib", {alias = "zlib"}}) @@ -283,7 +160,7 @@ target("test") add_packages("pcre2", "zlib") ``` -#### 添加vcpkg的依赖包 +### 添加vcpkg的依赖包 ```lua add_requires("vcpkg::zlib", "vcpkg::pcre2") @@ -294,7 +171,7 @@ target("test") add_packages("vcpkg::zlib", "vcpkg::pcre2") ``` -#### 添加conan的依赖包 +### 添加conan的依赖包 ```lua add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) @@ -326,7 +203,7 @@ please input: y (y/n) [100%]: linking.release test ``` -#### 添加clib的依赖包 +### 添加clib的依赖包 clib是一款基于源码的依赖包管理器,拉取的依赖包是直接下载对应的库源码,集成到项目中编译,而不是二进制库依赖。 @@ -342,7 +219,7 @@ target("test") add_packages("bytes") ``` -### 使用自建私有包仓库 +## 使用自建私有包仓库 如果需要的包不在官方仓库[xmake-repo](https://github.com/xmake-io/xmake-repo)中,我们可以提交贡献代码到仓库进行支持。 但如果有些包仅用于个人或者私有项目,我们可以建立一个私有仓库repo,仓库组织结构可参考:[xmake-repo](https://github.com/xmake-io/xmake-repo) @@ -412,11 +289,11 @@ target("test") add_packages("libjpeg") ``` -### 包管理命令使用 +## 包管理命令使用 包管理命令`$ xmake require` 可用于手动显示的下载编译安装、卸载、检索、查看包信息。 -#### 安装指定包 +### 安装指定包 ```console $ xmake require tbox @@ -442,7 +319,7 @@ $ xmake require --extra="debug=true,config={small=true}" tbox 安装debug包,并且传递`small=true`的编译配置信息到包中去。 -#### 卸载指定包 +### 卸载指定包 ```console $ xmake require --uninstall tbox @@ -450,13 +327,13 @@ $ xmake require --uninstall tbox 这会完全卸载删除包文件。 -#### 查看包详细信息 +### 查看包详细信息 ```console $ xmake require --info tbox ``` -#### 在当前仓库中搜索包 +### 在当前仓库中搜索包 ```console $ xmake require --search tbox @@ -470,13 +347,13 @@ $ xmake require --search pcr 会同时搜索到pcre, pcre2等包。 -#### 列举当前已安装的包 +### 列举当前已安装的包 ```console $ xmake require --list ``` -### 仓库管理命令使用 +## 仓库管理命令使用 上文已经简单讲过,添加私有仓库可以用(支持本地路径添加): @@ -508,7 +385,7 @@ $ xmake repo --list $ xmake repo -u ``` -### 提交包到官方仓库 +## 提交包到官方仓库 目前这个特性刚完成不久,目前官方仓库的包还不是很多,有些包也许还不支持部分平台,不过这并不是太大问题,后期迭代几个版本后,我会不断扩充完善包仓库。 diff --git a/zh-cn/package/system_package.md b/zh-cn/package/system_package.md new file mode 100644 index 00000000..eda893e9 --- /dev/null +++ b/zh-cn/package/system_package.md @@ -0,0 +1,73 @@ + +如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 + +目前此接口支持以下一些包管理支持: + +* vcpkg +* homebrew +* pkg-config + +并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: + +```lua +local packages = find_packages("openssl", "zlib") +``` + +返回的结果如下: + +```lua +{ + {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, + {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} +} +``` + +如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil + +这里的返回结果可以直接作为`target:add`, `option:add`的参数传入,用于动态增加`target/option`的配置: + +```lua +option("zlib") + set_showmenu(true) + before_check(function (option) + option:add(find_packages("openssl", "zlib")) + end) +``` + +```lua +target("test") + on_load(function (target) + target:add(find_package("openssl", "zlib")) + end) +``` + +如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 + +另外,我们也可以从指定的包管理器查找包: + +```lua +find_packages("brew::pcre2/libpcre2-8", "vcpkg::zlib") +``` + +更完整的使用描述,请参考:[find_packages](/zh-cn/manual/builtin_modules?id=find_packages)接口文档。 + +## homebrew集成支持 + +由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 + +## vcpkg集成支持 + +目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。 + +当然,我们也可以手动指定vcpkg的根路径来支持: + +```console +$ xmake f --vcpkg=f:\vcpkg +``` + +或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置: + +```console +$ xmake g --vcpkg=f:\vcpkg +``` + |
