Xmake has built-in support for package dependency integration. You can declare the required dependency packages through the add_requires interface.
Then, through the add_packages interface, bind the declared package to the required compilation target, for example:
add_requires("tbox 1.6.*", "libpng ~1.16", "zlib")
target("foo")
set_kind("binary")
add_files("src/*.c")
add_packages("tbox", "libpng")
target("bar")
set_kind("binary")
add_files("src/*.c")
add_packages("zlib")
Among them, add_requires is a global interface, used for package configuration declaration, and Xmake will trigger search and installation based on the declared package.
Since a project may have multiple target programs, each target program may require different dependency packages, so we also need to bind the target through add_packages.
In the above configuration example, the foo target binds the tbox and libpng packages, while the bar target binds the zlib package.
add_requires("pkgname") declares dependencies, supports version, optional, alias, etc.add_packages("pkgname") binds packages to targets, automatically adds links, includedirs, etc.add_requires("tbox 1.6.*", "libpng ~1.16", "zlib")
add_requires("foo", {optional = true})
add_requires("foo", {system = false})
add_requires("foo", {alias = "myfoo"})
add_packages("myfoo")
add_requires("foo", {plat = "windows", arch = "x64"})
add_requires("tbox", {configs = {small = true}})
add_requireconfs("spdlog.fmt", {configs = {header_only = true}})
Available in custom rules, after_install, etc.:
package:name() get package namepackage:version_str() get versionpackage:installdir() get install dirpackage:get("links") get link librariespackage:get("includedirs") get include dirsadd_requires("foo", {optional = true})
target("bar")
add_packages("foo")
add_requires("tbox master")
add_requires("zlib 1.2.11")
add_requires("spdlog", {configs = {header_only = true}})
local-repo/packages/foo/xmake.lua).Add the local repository in xmake.lua:
add_repositories("myrepo local-repo")
add_requires("foo")
Local package structure example:
local-repo/
packages/
foo/
xmake.lua
Now you can use the local package just like an official one via add_requires("foo").
add_requires + add_packages for declaration and binding{optional = true} for optional packages{plat=..., arch=...} for precise control on multi-platformadd_requireconfs for recursive dependency configxmake require --info pkg to query package parameters