|
|
@@ -1,6 +1,6 @@
|
|
|
# 使用本地包 {#using-local-packages}
|
|
|
|
|
|
-## 生成本地包
|
|
|
+## 生成本地包 {#local-package-generate}
|
|
|
|
|
|
2.5.5 版本之后,我们提供了一种新的本地包打包方案,将会更加无缝地对接 `add_requires` 和 `add_packages`。
|
|
|
|
|
|
@@ -49,7 +49,7 @@ build/packages/f/foo/
|
|
|
└── xmake.lua
|
|
|
```
|
|
|
|
|
|
-## 使用本地包
|
|
|
+## 使用本地包 {#local-package-use}
|
|
|
|
|
|
我们也能够使用 `add_requires`/`add_repositories` 接口来无缝集成这个包。
|
|
|
|
|
|
@@ -80,7 +80,7 @@ target("bar")
|
|
|
-Wl,-x -lfoo -lsub -ladd -lz
|
|
|
```
|
|
|
|
|
|
-## 使用通过 CMake 查找到的包
|
|
|
+## 使用通过 CMake 查找到的包 {#local-package-cmake}
|
|
|
|
|
|
现在 cmake 已经是事实上的标准,所以 CMake 提供的 find_package 已经可以查找大量的库和模块,我们完全复用 cmake 的这部分生态来扩充 xmake 对包的集成。
|
|
|
|
|
|
@@ -117,7 +117,7 @@ $ xmake l find_package cmake::LibXml2
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-### 在项目中集成包
|
|
|
+### 在项目中集成包 {#local-package-cmake-integrate}
|
|
|
|
|
|
如果我们在 xmake.lua 项目配置中集成查找 cmake 的依赖包,通常不需要直接使用 find_package,可以用更加通用、简单的包集成方式。
|
|
|
|
|
|
@@ -131,19 +131,19 @@ target("test")
|
|
|
|
|
|
我们指定 `system = true` 告诉 xmake 强制从系统中调用 cmake 查找包,如果找不到,不再走安装逻辑,因为 cmake 没有提供类似 vcpkg/conan 等包管理器的安装功能,只提供了包查找特性。
|
|
|
|
|
|
-### 指定版本
|
|
|
+### 指定版本 {#local-package-cmake-version}
|
|
|
|
|
|
```lua
|
|
|
add_requires("cmake::OpenCV 4.1.1", {system = true})
|
|
|
```
|
|
|
|
|
|
-### 指定组件
|
|
|
+### 指定组件 {#local-package-cmake-components}
|
|
|
|
|
|
```lua
|
|
|
add_requires("cmake::Boost", {system = true, configs = {components = {"regex", "system"}})}
|
|
|
```
|
|
|
|
|
|
-### 预设开关
|
|
|
+### 预设开关 {#local-package-cmake-presets}
|
|
|
|
|
|
```lua
|
|
|
add_requires("cmake::Boost", {system = true, configs = {components = {"regex", "system"},
|
|
|
@@ -157,13 +157,13 @@ set(Boost_USE_STATIC_LIB ON) -- will be used in FindBoost.cmake
|
|
|
find_package(Boost REQUIRED COMPONENTS regex system)
|
|
|
```
|
|
|
|
|
|
-### 设置环境变量
|
|
|
+### 设置环境变量 {#local-package-cmake-envs}
|
|
|
|
|
|
```lua
|
|
|
add_requires("cmake::OpenCV", {system = true, configs = {envs = {CMAKE_PREFIX_PATH = "xxx"}}})
|
|
|
```
|
|
|
|
|
|
-### 指定自定义 FindFoo.cmake 模块脚本目录
|
|
|
+### 指定自定义 FindFoo.cmake 模块脚本目录 {#local-package-cmake-moduledirs}
|
|
|
|
|
|
mydir/cmake_modules/FindFoo.cmake
|
|
|
|
|
|
@@ -173,7 +173,7 @@ add_requires("cmake::Foo", {system = true, configs = {moduledirs = "mydir/cmake_
|
|
|
|
|
|
相关 issues: [#1632](https://github.com/xmake-io/xmake/issues/1632)
|
|
|
|
|
|
-### 指定链接项
|
|
|
+### 指定链接项 {#local-package-cmake-link-libraries}
|
|
|
|
|
|
对于 cmake 包,我们新增了 `link_libraries` 配置选项,让用户在查找使用 cmake 包的时候,可以自定义配置包依赖的链接库,甚至对 target 链接的支持。
|
|
|
|
|
|
@@ -187,7 +187,7 @@ xmake 在查找 cmake 包的时候,会自动追加下面的配置,改进对
|
|
|
target_link_libraries(test PRIVATE ABC::lib1 ABC::lib2)
|
|
|
```
|
|
|
|
|
|
-### 指定搜索模式
|
|
|
+### 指定搜索模式 {#local-package-cmake-search-mode}
|
|
|
|
|
|
另外,我们增加的搜索模式配置:
|
|
|
|