ruki 3 лет назад
Родитель
Сommit
0ebb5954f0
5 измененных файлов с 39 добавлено и 189 удалено
  1. 1 1
      _sidebar.md
  2. 16 91
      package/system_package.md
  3. 1 1
      zh-cn/_sidebar.md
  4. 1 1
      zh-cn/manual/helper_interfaces.md
  5. 20 95
      zh-cn/package/system_package.md

+ 1 - 1
_sidebar.md

@@ -22,8 +22,8 @@
 
   - [Local Package (Old)](package/local_package_old.md)
   - [Local Package (New)](package/local_package.md)
-  - [System Package](package/system_package.md)
   - [Remote Package](package/remote_package.md)
+  - [System Package](package/system_package.md)
   - [Local 3rd source code library](package/local_3rd_source_library.md)
   - [Xrepo C/C++ Package Manager](https://xrepo.xmake.io/#/getting_started)
 

+ 16 - 91
package/system_package.md

@@ -1,97 +1,24 @@
-## Find System Package
+## Find using system packages
 
-If you feel that the above built-in package management method is very inconvenient, you can use the built-in interface `find_packages` provided by xmake.
+Xmake unifies the use of remote packages and system packages, and all use the `add_requires("zlib")` interface to describe the integration, and the default configuration method, it will first find the library from the system, if not, it will automatically download and install integrated.
 
-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:
+And if we just want to find and use the system library and don't want to download it remotely, we can configure it like this:
 
 ```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)
-```
+add_requires("zlib", {system = false})
 
-```lua
 target("test")
-    on_load(function (target)
-        target:add(find_packages("openssl", "zlib"))
-    end)
-```
-
-Currently this interface supports the following package management support:
-
-* conan
-* vcpkg
-* homebrew
-* pkg-config
-
-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 [find_packages](/manual/builtin_modules?id=find_packages) interface documentation.
-
-Of course, if you feel that integrating third-party dependencies by looking for packages is not enough, you can also directly integrate remote dependencies through `add_requires`. 
-For details, see the documentation: [Using Remote Dependencies](/package/remote_package)
-
-## Find homebrew package
-
-Alternatively, we can also find the package from the manually specified package manager:
-
-```lua
-find_packages("brew::pcre2/libpcre2-8", "brew::x264")
-```
-
-We only need to add the `brew::` prefix, you can explicitly specify the package source from homebrew to find the package, if there are multiple pkgconfig files in `brew::pcre2`, for example: libpcre2-8.pc, libpcre2-16. Pc, libpcre2-32.pc
-
-Then we can use `brew::pcre2/libpcre2-16` to select the link library information specified by the corresponding pkgconfig file.
-
-Since homebrew is generally installed directly into the system, users do not need to do any integration work, `find_packages` has been natively seamlessly supported.
-
-## Find vcpkg package
-
-Currently xmake v2.2.2 version has already supported 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 the configuration is switched:
-
-```console
-$ xmake g --vcpkg=f:\vcpkg
-```
-
-Then, we can specify the dependency package in vcpkg by using the `vcpkg::` prefix:
-
-```lua
-find_packages("vcpkg::zlib", "vcpkg::openssl")
+     set_kind("binary")
+     add_files("src/*.c")
+     add_packages("zlib")
 ```
 
-## Find the conan package
+Remote download can be forcibly disabled by `{system = false}`. At this time, it is equivalent to `find_package` of Xmake/CMake, but it is simpler and easier to use, and it is exactly the same as the use of remote packages.
 
-Xmake v2.2.6 and later versions also support finding the specified package from the conan:
+By default, if the system library is not found, it will prompt failure. If the package is optional, you can additionally configure the `{optional = true}` option.
 
 ```lua
-find_packages("conan::openssl/1.1.1g")
+add_requires("zlib", {system = false, optional = true})
 ```
 
 ## Test command for finding package
@@ -99,27 +26,25 @@ find_packages("conan::openssl/1.1.1g")
 We can use the following command to quickly detect the package information specified on the system:
 
 ```console
-$ xmake l find_packages x264
+$ xmake l find_package x264
 {
-   {
-     Links = {
+     links = {
        "x264"
      },
-     Linkdirs = {
+     linkdirs = {
        "/usr/local/Cellar/x264/r2699/lib"
      },
-     Version = "0.148.2699 a5e06b9",
-     Includeirs = {
+     version = "0.148.2699 a5e06b9",
+     includeirs = {
        "/usr/local/Cellar/x264/r2699/include"
      }
-   }
 }
 ```
 
 We can also add a third-party package manager prefix to test:
 
 ```console
-xmake l find_packages conan::OpenSSL/1.0.2n@conan/stable
+xmake l find_package conan::OpenSSL/1.0.2g
 ```
 
 !> It should be noted that if the find_package command is executed in the project directory with xmake.lua, there will be a cache. If the search fails, the next lookup will also use the cached result. If you want to force a retest every time, Please switch to the non-project directory to execute the above command.

+ 1 - 1
zh-cn/_sidebar.md

@@ -24,8 +24,8 @@
 
   - [使用本地包 (Old)](zh-cn/package/local_package_old.md)
   - [使用本地包 (New)](zh-cn/package/local_package.md)
-  - [使用系统包](zh-cn/package/system_package.md)
   - [使用远程包](zh-cn/package/remote_package.md)
+  - [使用系统包](zh-cn/package/system_package.md)
   - [集成本地第三方源码库](zh-cn/package/local_3rd_source_library.md)
   - [Xrepo C/C++ 包管理器](https://xrepo.xmake.io/#/zh-cn/getting_started)
 

+ 1 - 1
zh-cn/manual/helper_interfaces.md

@@ -157,7 +157,7 @@ config.h
 
 v2.5.7 之后对 check_csnippets 做了改进,新增 `tryrun` 和 `output` 参数去尝试运行和捕获输出。
 
-````lua
+```lua
 includes("check_csnippets.lua")
 
 target("test")

+ 20 - 95
zh-cn/package/system_package.md

@@ -1,97 +1,24 @@
+## 查找使用系统包
 
-## 查找系统包
+Xmake 对远程包和系统包的使用进行了统一,全部使用 `add_requires("zlib")` 接口来描述集成,而默认的配置方式,它会优先从系统上查找库,如果没有,会自动下载安装集成。
 
-如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。
-
-并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包:
+而如果我们仅仅想查找使用系统库,不想远程下载,可以这么配置:
 
 ```lua
-local packages = find_packages("openssl", "zlib")
-```
-
-返回的结果如下:
+add_requires("zlib", {system = false})
 
-```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_packages("openssl", "zlib"))
-    end)
-```
-
-目前此接口支持以下一些包管理支持:
-
-* conan
-* vcpkg
-* homebrew
-* pkg-config
-
-如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。
-
-更完整的使用描述,请参考:[find_packages](/zh-cn/manual/builtin_modules?id=find_packages)接口文档。
-
-当然,如果觉得通过查找包的方式来集成第三方依赖包还不能满足需求,也可以通过`add_requires`来直接集成远程依赖包,具体请查看文档:[使用远程依赖包](https://xmake.io/#/zh-cn/package/remote_package)
-
-## 查找homebrew包
-
-另外,我们也可以从手动指定的包管理器查找包:
-
-```lua
-find_packages("brew::pcre2/libpcre2-8", "brew::x264")
+    set_kind("binary")
+    add_files("src/*.c")
+    add_packages("zlib")
 ```
 
-我们只需要添加`brew::`前缀,就可以显式指定从homebrew的包源来查找包,如果`brew::pcre2`存在多个pkgconfig文件,例如:libpcre2-8.pc, libpcre2-16.pc, libpcre2-32.pc
-
-那么我们可以通过`brew::pcre2/libpcre2-16`来选择对应的pkgconfig文件指定的链接库信息。
-
-由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。
-
-## 查找vcpkg包
-
-目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。
-
-当然,我们也可以手动指定vcpkg的根路径来支持:
-
-```console
-$ xmake f --vcpkg=f:\vcpkg
-```
+通过 `{system = false}` 就可以强制禁用远程下载,这时候,他就等价于 Xmake/CMake 的 `find_package`,但是更加简单易用,并且和远程包使用方式完全一致。
 
-或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置:
-
-```console
-$ xmake g --vcpkg=f:\vcpkg
-```
-
-然后,我们就可以通过`vcpkg::`前缀,来指定查找vcpkg中的依赖包了:
-
-```lua
-find_packages("vcpkg::zlib", "vcpkg::openssl")
-```
-
-## 查找conan包
-
-xmake v2.2.6以后的版本,也支持从conan中查找指定的包:
+默认情况下,如果找不到系统库,就是提示失败,如果这个包是可选的,那么可以额外配置 `{optional = true}` 选项。
 
 ```lua
-find_packages("conan::openssl/1.1.1g")
+add_requires("zlib", {system = false, optional = true})
 ```
 
 ## 查找包快速测试
@@ -99,27 +26,25 @@ find_packages("conan::openssl/1.1.1g")
 我们可以使用下面的命令,快速检测系统上指定的包信息:
 
 ```console
-$ xmake l find_packages x264
-{ 
-  { 
-    links = { 
-      "x264" 
+$ xmake l find_package x264
+{
+    links = {
+      "x264"
     },
-    linkdirs = { 
-      "/usr/local/Cellar/x264/r2699/lib" 
+    linkdirs = {
+      "/usr/local/Cellar/x264/r2699/lib"
     },
     version = "0.148.2699 a5e06b9",
-    includedirs = { 
-      "/usr/local/Cellar/x264/r2699/include" 
-    } 
-  } 
+    includedirs = {
+      "/usr/local/Cellar/x264/r2699/include"
+    }
 }
 ```
 
 我们也可以追加第三方包管理器前缀来测试:
 
 ```console
-xmake l find_packages conan::OpenSSL/1.0.2n@conan/stable
+xmake l find_package conan::OpenSSL/1.0.2g
 ```
 
 !> 需要注意的是,find_package命令如果在带有xmake.lua的工程目录下执行,是会有缓存的,如果查找失败,下次查找也会使用缓存的结果,如果要每次强制重新检测,请切换到非工程目录下执行上面的命令。