Used to get the configuration information when the project is compiled, that is, the value of the parameter option passed in xmake f|config --xxx=val.
::: tip API
config.get(name: <string>)
:::
| Parameter | Description |
|---|---|
| name | Required. Configuration item name |
| Type | Description |
|---|---|
| any | Returns the configuration value, or nil if it doesn't exist |
Used to get the configuration value of xmake f|config --xxx=val, for example:
target("test")
on_run(function (target)
-- Import configuration module
import("core.project.config")
-- Get configuration values
print(config.get("xxx"))
end)
::: tip API
config.load()
:::
No parameters required for this function.
This function has no return value.
Generally used in plug-in development, the plug-in task is not like the custom script of the project, the environment needs to be initialized and loaded by itself, the default project configuration is not loaded, if you want to use config.get interface to get the project Configuration, then you need to:
-- Import configuration module
import("core.project.config")
function main(...)
-- Load project configuration first
config.load()
-- Get configuration values
print(config.get("xxx"))
end
::: tip API
config.arch()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| string | Returns the architecture name, e.g., "x86_64", "armv7" |
That is to get the platform configuration of xmake f|config --arch=armv7, which is equivalent to config.get("arch").
::: tip API
config.plat()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| string | Returns the platform name, e.g., "macosx", "linux" |
That is to get the platform configuration of xmake f|config --plat=iphoneos, which is equivalent to config.get("plat").
::: tip API
config.mode()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| string | Returns the compilation mode, e.g., "debug", "release" |
That is to get the platform configuration of xmake f|config --mode=debug, which is equivalent to config.get("mode").
::: tip API
config.builddir()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| string | Returns the build output directory path |
That is to get the platform configuration of xmake f|config -o /tmp/output, which is equivalent to config.get("builddir").
::: tip API
config.directory()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| string | Returns the configuration information directory path |
Get the storage directory of the project configuration, the default is: projectdir/.config
::: tip API
config.dump()
:::
No parameters required for this function.
| Type | Description |
|---|---|
| table | Returns a table containing all configuration information |
Print out all configuration information of the current project. The output is for example:
{
sh = "xcrun -sdk macosx clang++",
xcode_dir = "/Applications/Xcode.app",
ar = "xcrun -sdk macosx ar",
small = true,
object = false,
arch = "x86_64",
xcode_sdkver = "10.12",
ex = "xcrun -sdk macosx ar",
cc = "xcrun -sdk macosx clang",
rc = "rustc",
plat = "macosx",
micro = false,
host = "macosx",
as = "xcrun -sdk macosx clang",
dc = "dmd",
gc = "go",
openssl = false,
ccache = "ccache",
cxx = "xcrun -sdk macosx clang",
sc = "xcrun -sdk macosx swiftc",
mm = "xcrun -sdk macosx clang",
builddir = "build",
mxx = "xcrun -sdk macosx clang++",
ld = "xcrun -sdk macosx clang++",
mode = "release",
kind = "static"
}