|
|
@@ -848,6 +848,7 @@ target("test2")
|
|
|
| [add_tools](#targetadd_tools) | Add toolchains | >= 2.2.1 |
|
|
|
| [set_values](#targetset_values) | Set custom configuartion values | >= 2.2.1 |
|
|
|
| [add_values](#targetadd_values) | Add custom configuartion values | >= 2.2.1 |
|
|
|
+| [set_installdir](#targetset_installdir) | Set the installation directory | >= 2.2.5 |
|
|
|
|
|
|
##### target
|
|
|
|
|
|
@@ -2809,6 +2810,13 @@ target("test")
|
|
|
|
|
|
用法跟[target:set_values](#targetset_tools)类似,区别就是这个接口是追加设置,而不会每次覆盖设置。
|
|
|
|
|
|
+##### target:set_installdir
|
|
|
+
|
|
|
+###### Set the installation directory
|
|
|
+
|
|
|
+默认情况下执行`xmake install`会安装到系统`/usr/local`目录,我们除了可以通过`xmake install -o /usr/local`指定其他安装目录外,
|
|
|
+还可以在xmake.lua中针对target设置不同的安装目录来替代默认目录。
|
|
|
+
|
|
|
#### Configuration Option
|
|
|
|
|
|
定义和设置选项开关,每个`option`对应一个选项,可用于自定义编译配置选项、开关设置。
|
|
|
@@ -4517,325 +4525,6 @@ package("libxml2")
|
|
|
end)
|
|
|
```
|
|
|
|
|
|
-#### Extension Platforms
|
|
|
-
|
|
|
-xmake除了内置的一些构建平台,还可以自己扩展自定义构建平台,可以将自己实现的平台放置在以下目录即可, xmake会自动检测并且加载他们:
|
|
|
-
|
|
|
-| 平台目录 | 描述 |
|
|
|
-| --------------------------- | ------------------------------------ |
|
|
|
-| projectdir/.xmake/platforms | 当前工程的平台目录, 只对当前工程有效 |
|
|
|
-| globaldir/.xmake/platforms | 全局配置的平台目录,当前主机全局有效 |
|
|
|
-| installdir/xmake/platforms | xmake安装后内置的平台目录 |
|
|
|
-
|
|
|
-用户可根据不同需求,将自定义的平台放置在对应的目录中。
|
|
|
-
|
|
|
-<p class="warning">
|
|
|
-平台的扩展定义,尽量不要放到工程`xmake.lua`中去,新建一个单独的平台目录放置相关描述实现。
|
|
|
-</p>
|
|
|
-
|
|
|
-平台描述的目录结构:
|
|
|
-
|
|
|
-```
|
|
|
-platforms
|
|
|
-
|
|
|
- - myplat1
|
|
|
- - xmake.lua
|
|
|
-
|
|
|
- - myplat2
|
|
|
- - xmake.lua
|
|
|
-```
|
|
|
-
|
|
|
-其中`xmake.lua`为每个平台的主描述文件,相当于入口描述。
|
|
|
-
|
|
|
-| 接口 | 描述 | 支持版本 |
|
|
|
-| ----------------------------------------------- | -------------------------------------------- | -------- |
|
|
|
-| [platform](#platform) | 定义平台 | >= 2.0.1 |
|
|
|
-| [platform_end](#platform_end) | 结束定义平台 | >= 2.1.1 |
|
|
|
-| [set_os](#platformset_os) | 设置平台系统 | >= 2.0.1 |
|
|
|
-| [set_menu](#platformset_menu) | 设置平台菜单 | >= 2.0.1 |
|
|
|
-| [set_hosts](#platformset_hosts) | 设置平台支持的主机环境 | >= 2.0.1 |
|
|
|
-| [set_archs](#platformset_archs) | 设置平台支持的架构环境 | >= 2.0.1 |
|
|
|
-| [set_tooldirs](#platformset_tooldirs) | 设置平台工具的搜索目录 | >= 2.0.1 |
|
|
|
-| [on_load](#platformon_load) | 设置加载平台环境配置脚本 | >= 2.0.1 |
|
|
|
-| [on_check](#platformon_check) | 设置平台工具的检测脚本 | >= 2.0.1 |
|
|
|
-| [on_install](#platformon_install) | 设置平台相关的工程目标安装脚本 | >= 2.0.5 |
|
|
|
-| [on_uninstall](#platformon_uninstall) | 设置平台相关的工程目标卸载脚本 | >= 2.0.5 |
|
|
|
-
|
|
|
-##### platform
|
|
|
-
|
|
|
-###### 定义平台
|
|
|
-
|
|
|
-自定义一个平台域,例如:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("iphoneos")
|
|
|
-
|
|
|
- -- 设置操作系统
|
|
|
- set_os("ios")
|
|
|
-
|
|
|
- -- 设置主机环境
|
|
|
- set_hosts("macosx")
|
|
|
-
|
|
|
- -- 设置支持的架构
|
|
|
- set_archs("armv7", "armv7s", "arm64", "i386", "x86_64")
|
|
|
-
|
|
|
- -- 设置gcc, clang等平台相关工具的搜索目录
|
|
|
- set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin")
|
|
|
-
|
|
|
- -- 设置gcc,clang等工具的检测脚本文件
|
|
|
- on_check("check")
|
|
|
-
|
|
|
- -- 设置平台初始化加载脚本文件,如果实现不复杂的话,可以使用内嵌函数
|
|
|
- on_load("load")
|
|
|
-
|
|
|
- -- 设置平台的帮助菜单
|
|
|
- set_menu {
|
|
|
- config =
|
|
|
- {
|
|
|
- {}
|
|
|
- , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" }
|
|
|
- , {nil, "xcode_sdkver", "kv", "auto", "the sdk version for xcode" }
|
|
|
- , {nil, "target_minver", "kv", "auto", "the target minimal version" }
|
|
|
- , {}
|
|
|
- , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
|
|
|
- , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
|
|
|
- , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
|
|
|
- }
|
|
|
-
|
|
|
- , global =
|
|
|
- {
|
|
|
- {}
|
|
|
- , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" }
|
|
|
- , {}
|
|
|
- , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
|
|
|
- , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
|
|
|
- , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-```
|
|
|
-
|
|
|
-<p class="warning">
|
|
|
-是在`platforms`目录相关平台的`xmake.lua`中编写,而不是在工程目录的`xmake.lua`中。
|
|
|
-</p>
|
|
|
-
|
|
|
-##### platform_end
|
|
|
-
|
|
|
-###### 结束定义平台
|
|
|
-
|
|
|
-这是一个可选api,显示离开选项作用域,用法和[target_end](#target_end)类似。
|
|
|
-
|
|
|
-##### set_os
|
|
|
-
|
|
|
-###### 设置平台系统
|
|
|
-
|
|
|
-设置目标平台的操作系统,例如:`ios`, `android`, `linux`, `windows` 等
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("iphoneos")
|
|
|
- set_os("ios")
|
|
|
-```
|
|
|
-
|
|
|
-这个一般用于在自定义脚本和插件开发中,[core.platform.platform](#core-platform-platform)模块中进行访问,获取当前平台的操作系统。
|
|
|
-
|
|
|
-##### set_menu
|
|
|
-
|
|
|
-###### 设置平台菜单
|
|
|
-
|
|
|
-先给个设置的例子:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("iphoneos")
|
|
|
- ...
|
|
|
-
|
|
|
- -- 设置平台的帮助菜单
|
|
|
- set_menu {
|
|
|
- config =
|
|
|
- {
|
|
|
- {}
|
|
|
- , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" }
|
|
|
- , {nil, "xcode_sdkver", "kv", "auto", "the sdk version for xcode" }
|
|
|
- , {nil, "target_minver", "kv", "auto", "the target minimal version" }
|
|
|
- , {}
|
|
|
- , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
|
|
|
- , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
|
|
|
- , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
|
|
|
- }
|
|
|
-
|
|
|
- , global =
|
|
|
- {
|
|
|
- {}
|
|
|
- , {nil, "xcode_dir", "kv", "auto", "the xcode application directory" }
|
|
|
- , {}
|
|
|
- , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
|
|
|
- , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
|
|
|
- , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
|
|
|
- }
|
|
|
- }
|
|
|
-```
|
|
|
-
|
|
|
-其中`config`组用来设置:`xmake f --help`中的本地工程菜单,`global`用来设置:`xmake g --help`全局平台配置中的菜单。
|
|
|
-
|
|
|
-具体设置格式可参考:[task:set_menu](#taskset_menu)。
|
|
|
-
|
|
|
-##### set_hosts
|
|
|
-
|
|
|
-###### 设置平台支持的主机环境
|
|
|
-
|
|
|
-用来设置当前目标平台支持主机构建环境,例如`iphoneos`平台可以在`macosx`主机系统上构建,那么可以设置为:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("iphoneos")
|
|
|
- set_hosts("macosx")
|
|
|
-```
|
|
|
-
|
|
|
-而`android`平台可以同时在`linux`, "macosx", `windows`主机环境中构建,那么可以设置为:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("android")
|
|
|
- set_hosts("linux", "macosx", "windows")
|
|
|
-```
|
|
|
-
|
|
|
-##### set_archs
|
|
|
-
|
|
|
-###### 设置平台支持的架构环境
|
|
|
-
|
|
|
-用来设置当前目标平台支持的编译架构环境,例如`iphoneos`平台可以构建`armv7`, `armv7s`, `arm64`, `i386`, `x86_64`等架构,那么可以设置为:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("iphoneos")
|
|
|
- set_archs("armv7", "armv7s", "arm64", "i386", "x86_64")
|
|
|
-```
|
|
|
-
|
|
|
-配置好架构后,执行:`xmake f -h`,就会在对应arch参数描述,自动显示设置的架构列表:
|
|
|
-
|
|
|
-```
|
|
|
- -a ARCH, --arch=ARCH Compile for the given architecture. (default: auto)
|
|
|
- - android: armv5te armv6 armv7-a armv8-a arm64-v8a
|
|
|
- - iphoneos: armv7 armv7s arm64 i386 x86_64
|
|
|
- - linux: i386 x86_64
|
|
|
- - macosx: i386 x86_64
|
|
|
- - mingw: i386 x86_64
|
|
|
- - watchos: armv7k i386
|
|
|
- - windows: x86 x64 amd64 x86_amd64
|
|
|
-```
|
|
|
-
|
|
|
-##### set_tooldirs
|
|
|
-
|
|
|
-###### 设置平台工具的搜索目录
|
|
|
-
|
|
|
-xmake会自动检测当前平台支持的一些构建工具是否存在,例如编译器、链接器等,如果要提高检测通过率,可以在平台配置的时候,设置一些工具环境搜索目录,例如:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("linux")
|
|
|
-
|
|
|
- -- 在linux下检测这些目录环境
|
|
|
- set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin")
|
|
|
-```
|
|
|
-
|
|
|
-##### on_load
|
|
|
-
|
|
|
-###### 设置加载平台环境配置脚本
|
|
|
-
|
|
|
-一般用于在平台刚加载时,设置一些基本配置:生成目标文件命名格式、平台相关编译选项等
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("windows")
|
|
|
-
|
|
|
- -- on load
|
|
|
- on_load(function ()
|
|
|
-
|
|
|
- -- init the file formats
|
|
|
- _g.formats = {}
|
|
|
- _g.formats.static = {"", ".lib"}
|
|
|
- _g.formats.object = {"", ".obj"}
|
|
|
- _g.formats.shared = {"", ".dll"}
|
|
|
- _g.formats.binary = {"", ".exe"}
|
|
|
- _g.formats.symbol = {"", ".pdb"}
|
|
|
-
|
|
|
- -- init flags for dlang
|
|
|
- local dc_archs = { x86 = "-m32", x64 = "-m64", amd64 = "-m64", x86_amd64 = "-m64" }
|
|
|
- _g.dcflags = { dc_archs[arch] or "" }
|
|
|
- _g["dc-shflags"] = { dc_archs[arch] or "" }
|
|
|
- _g["dc-ldflags"] = { dc_archs[arch] or "" }
|
|
|
-
|
|
|
- -- ok
|
|
|
- return _g
|
|
|
- end)
|
|
|
-```
|
|
|
-
|
|
|
-如果加载逻辑比较复杂,可以独立成单独`init.lua`文件,然后设置为:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("xxxx")
|
|
|
- on_load("init")
|
|
|
-```
|
|
|
-
|
|
|
-通过这种方式,会自动加载平台脚本目录下对应的`init.lua`文件,调用`function main() end`函数入口,完成复杂加载逻辑。
|
|
|
-
|
|
|
-##### on_check
|
|
|
-
|
|
|
-###### 设置平台工具的检测脚本
|
|
|
-
|
|
|
-由于每个平台检测的工具非常多,脚本比较复杂,一般直接独立成`check.lua`文件来实现检测逻辑,例如:
|
|
|
-
|
|
|
-```lua
|
|
|
-platform("xxx")
|
|
|
- on_check("check")
|
|
|
-```
|
|
|
-
|
|
|
-具体的检测代码入口如下:
|
|
|
-
|
|
|
-```lua
|
|
|
--- check it
|
|
|
-function main(kind)
|
|
|
-
|
|
|
- -- init the check list of config
|
|
|
- _g.config =
|
|
|
- {
|
|
|
- __check_arch
|
|
|
- , checker.check_ccache
|
|
|
- , _check_toolchains
|
|
|
- }
|
|
|
-
|
|
|
- -- init the check list of global
|
|
|
- _g.global =
|
|
|
- {
|
|
|
- checker.check_ccache
|
|
|
- , _check_ndk_sdkver
|
|
|
- }
|
|
|
-
|
|
|
- -- check it
|
|
|
- checker.check(kind, _g)
|
|
|
-end
|
|
|
-```
|
|
|
-
|
|
|
-具体实现这里就不介绍了,可以参考xmake源码目录下的`platforms`平台配置代码: [check.lua](https://github.com/xmake-io/xmake/blob/master/xmake/platforms/macosx/check.lua)
|
|
|
-
|
|
|
-##### on_install
|
|
|
-
|
|
|
-###### 设置目标工程在指定平台的安装脚本
|
|
|
-
|
|
|
-具体实现逻辑见xmake源码:[install.lua](https://github.com/xmake-io/xmake/blob/master/xmake/platforms/macosx/install.lua)
|
|
|
-
|
|
|
-##### on_uninstall
|
|
|
-
|
|
|
-###### 设置目标工程在指定平台的卸载脚本
|
|
|
-
|
|
|
-具体实现逻辑见xmake源码:[uninstall.lua](https://github.com/xmake-io/xmake/blob/master/xmake/platforms/macosx/uninstall.lua)
|
|
|
-
|
|
|
-#### Extension Languages
|
|
|
-
|
|
|
-有待后续完善。。
|
|
|
-
|
|
|
-#### Project Templates
|
|
|
-
|
|
|
-##### template
|
|
|
-##### set_description
|
|
|
-##### set_projectdir
|
|
|
-##### add_macros
|
|
|
-##### add_macrofiles
|
|
|
-
|
|
|
#### Builtin Variables
|
|
|
|
|
|
xmake提供了 `$(varname)` 的语法,来支持内置变量的获取,例如:
|