v2.5.4
支持Apt,Portage
add_requires("apt::zlib1g-dev", {alias = "zlib"})
target("test")
set_kind("binary")
add_files("src/*.c")
add_packages("zlib")
导出导入
$ xrepo export -o /tmp/output zlib
$ xrepo import -i /xxx/packagedir zlib
$ xrepo env luajit
xrepo env shell
xrepo env quit
代理
function mirror(url)
return url:gsub("github.com", "hub.fastgit.org")
end
$ xmake g --proxy_pac=/tmp/pac.lua
XMAKE_PKG_INSTALLDIR 设置安装包 路径. XMAKE_PKG_CACHEDIR 缓存包目录.
v2.5.5
github action 云端预编译, 根据plat/arch/MT/MD/static/shared 来配置.
$ xrepo install --build openssl
add_requires("openssl", {build = true})
$ xmake repo --add local-repo git@github.com:xmake-mirror/myrepo-artifacts.git
add_repositories("local-repo git@github.com:xmake-mirror/myrepo-artifacts.git")
新版打包
$ xmake package
package("foo")
set_description("The foo package")
set_license("Apache-2.0")
add_deps("add", "sub")
on_load(function (package)
package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode()))
end)
on_fetch(function (package)
local result = {}
result.links = "foo"
result.linkdirs = package:installdir("lib")
result.includedirs = package:installdir("include")
return result
end)
用package() 来定义描述本地|远程 包 用add_requires/add_repositories 来使用它们
add_rules("mode.debug", "mode.release")
add_repositories("local-repo build")
add_requires("foo")
target("bar")
set_kind("binary")
add_files("src/*.cpp")
add_packages("foo")
target/add_deps 本地包,自动关联依赖 .
$ xmake package -f remote
package("foo")
set_description("The foo package")
set_license("Apache-2.0")
add_deps("add", "sub")
add_urls("https://github.com/myrepo/foo.git")
add_versions("1.0", "<shasum256 or gitcommit>")
on_install(function (package)
local configs = {}
if package:config("shared") then
configs.kind = "shared"
end
import("package.tools.xmake").install(package, configs)
end)
on_test(function (package)
-- 检查包含与接口
-- assert(package:has_cfuncs("foo", {includes = "foo.h"})
end)
$ xmake package -f remote --url=https://xxxx/xxx.tar.gz --shasum=xxxxx --homepage=xxxxx`
可用set_license 和set_version 取信息.
$ xrepo search vcpkg::pcre
set_basename/set_filename 修改目标名.set_prefixname,set_suffixname和set_extension 更多了. set_kind 未置,默认为exe .
target("test")
add_files("src/*.c")
$ xmake f -p appletvos
$ xmake
//苹果tvos
导入导出
$ xmake f --export=/tmp/config.txt
$ xmake f -m debug --xxx=y --export=/tmp/config.txt
$ xmake f --import=/tmp/config.txt
$ xmake f -m debug --xxx=y --import=/tmp/config.txt
可用--menu 加上菜单.
v2.5.7
utils.bin2c 内嵌资源进代码 , 支持vala ,用add_rules("vala") .
add_values("vala.packages")
add_requires("lua")
add_rules("mode.release", "mode.debug")
add_requires("lua", "glib")
target("test")
set_kind("binary")
add_rules("vala")
add_files("src/*.vala")
add_packages("lua", "glib")
add_values("vala.packages", "lua")
锁定包依赖:
set_policy("package.requires_lock", true)
全局设置 ,用来固定版本 .生成xmake-requires.lock 配置.
$ xmake require --upgrade
用add_csnippets/add_cxxsnippets 来运行时检查代码片段 .{tryrun=true}和{output=true} 设置参数.
option("test")
add_cxxsnippets("HAS_INT_4", "return (sizeof(int) == 4)? 0 : -1;", {tryrun = true})
通过,则启用测试 选项.
option("test")
add_cxxsnippets("INT_SIZE", 'printf("%d", sizeof(int)); return 0;', {output = true, number = true})
输出,作为测试 选项的值 .
if is_config("test", "8") tben
-- xxx
end
来取测试 选项的值.
检查代码片段
includes("check_csnippets.lua")
target("test")
set_kind("binary")
add_files("*.c")
add_configfiles("config.h.in")
check_csnippets("HAS_INT_4", "return (sizeof(int) == 4)? 0 : -1;", {tryrun = true})
check_csnippets("INT_SIZE", 'printf("%d", sizeof(int)); return 0;', {output = true, number = true})
configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true})
configvar_check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
启用捕捉输出, config.h.in 的${define PTR_SIZE }会自动生成#define PTR_SIZE 4 .
target("console")
set_kind("binart")
add_rules("utils.bin2c", {extensions = {".png", ".jpg"}})
add_files("src/*.c")
add_files("res/*.png", "res/*.jpg")
就可
#include "filename.png.h"
来引入.
add_rules("utils.bin2c", {extensions = ".metal"})
add_files("Renderer/*.metal")
加仓库,指定根目录,
add_repositories("myrepo repodir", {rootdir = os.scriptdir()})
更方便找.
os.cp("/xxx/symlink", "/xxx/dstlink", {symlink = true})
add_files 加上{always_added = true} 配置,即使不存在,也加上,因为构建过程中可能生成它们.但不能用模式匹配 ,因为当前不存在.
v2.5.8
add_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_files("src/*.pas")
构建pascal .add_fcflags() 来加Pascal 选项.
add_rules("mode.release", "mode.debug")
add_requires("lua")
target("example")
add_rules("swig.c", {moduletype = "lua"})
add_files("src/example.i", {swigflags = "-no-old-metatable-bindings"})
add_files("src/example.c")
add_packages("lua")
python与c++
add_rules("mode.release", "mode.debug")
add_requires("python 3.x")
target("example")
add_rules("swig.cpp", {moduletype = "python"})
add_files("src/example.i", {scriptdir = "share"})
add_files("src/example.cpp")
add_packages("python")
可在LoongArch 架构上运行.根目录为xmake.lua ,而foo 目录为cmake :
add_rules("mode.debug", "mode.release")
package("foo")
add_deps("cmake")
set_sourcedir(path.join(os.scriptdir(), "foo"))
on_install(function (package)
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)
end)
on_test(function (package)
assert(package:has_cfuncs("add", {includes = "foo.h"}))
end)
package_end()
add_requires("foo")
target("demo")
set_kind("binary")
add_files("src/main.c")
add_packages("foo")
add_requires("foo") 和add_packages("foo") 集成使用. package.tools.autoconf和package.tools.cmake 模块支持mingw/cross/iphoneos/android 等交叉编译.
configvar_check_features("HAS_CXX_STD_20", "cxx_std_20", {languages = "c++20"})
configvar_check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++20"})
set_symbols("debug") 生成pdb . set_languages 新增c++latest .
v2.5.9
支持nim
xmake create -l nim -t console test
xmake create -l nim -t static test
xmake create -l nim -t shared test
add_rules("mode.debug", "mode.release")
add_requires("nimble::zip >0.3")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("nimble::zip")
unity 构建,搞成个大目标 来编译.
add_rules("c.unity_build")
add_rules("c++.unity_build")
target("test")
set_kind("binary")
add_includedirs("src")
add_rules("c++.unity_build", {batchsize = 2})
add_files("src/*.c", "src/*.cpp")
target("test")
set_kind("binary")
add_rules("c++.unity_build", {batchsize = 0}) -- 禁止批模式,0,禁用分组
add_files("src/*.c", "src/*.cpp")
add_files("src/foo/*.c", {unity_group = "foo"})
add_files("src/bar/*.c", {unity_group = "bar"})
add_files("src/test/*.c", {unity_ignored = true}) --忽略这些
.mpp ,.ixx,.cppm,.mxx 支持模块.
set_languages("c++20")
target("test")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
还有:
target("hello")
add_deps("foo")
add_rules("mdk.console")
add_files("src/*.c", "src/*.s")
add_defines("__EVAL", "__MICROLIB")
add_includedirs("src/lib/cmsis")
$ xmake f -p cross -a cortex-m3 --toolchain=armcc -c
$ xmake
//armcc编译
$ xmake f -p cross -a cortex-m3 --toolchain=armclang -c
$ xmake
//armclang编译
add_rules("mode.debug", "mode.release")
target("foo")
add_rules("mdk.static")
//mdk静态库
add_files("src/foo/*.c")
$ xmake f -p wasm --toolchain=wasi
$ xmake
$ xmake f --toolchain=circle
$ xmake
//circle编译器
有有趣的编译期元编程特性 的circle .网站.
$ xmake f --toolchain=gcc-11 -c
$ xmake
includes("check_features.lua")
target("test")
set_kind("binary")
add_files("*.c")
add_configfiles("config.h.in")
configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr")
configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"})
仅头文件
add_rules("mode.release", "mode.debug")
target("foo")
set_kind("headeronly")
add_headerfiles("src/foo.h")
add_rules("utils.install.cmake_importfiles")
add_rules("utils.install.pkgconfig_importfiles")
借助cmake 来找包.
find_package("cmake::xxx")
$ xmake l find_package cmake::ZLIB
$ xmake l find_package cmake::LibXml2
find_package("cmake::OpenCV", {required_version = "4.1.1"})
find_package("cmake::Boost", {components = {"regex", "system"}})
find_package("cmake::Boost", {components = {"regex", "system"}, presets = {Boost_USE_STATIC_LIB = true}})
set(Boost_USE_STATIC_LIB ON) -- 在FindBoost.cmake中用
find_package(Boost REQUIRED COMPONENTS regex system)
find_package("cmake::OpenCV", {envs = {CMAKE_PREFIX_PATH = "xxx"}})
find_package("cmake::Foo", {moduledirs = "mydir/cmake_modules"})
依赖包
package("xxx")
on_fetch(function (package, opt)
opt.components = {}
if package:config("regex") then
table.insert(opt.components, "regex")
end
return package:find_package("cmake::xxx", opt)
end)
package_end()
add_requires("xxx")
add_requires("boost", {configs = {regex = true}})
v2.6.1
增加utils.glsl2spv 工具,支持编译glsl shader . 支持cargo
add_rules("mode.release", "mode.debug")
add_requires("cargo::base64 0.13.0")
add_requires("cargo::flate2 1.0.17", {configs = {features = "zlib"}})
target("test")
set_kind("binary")
add_files("src/main.rs")
add_packages("cargo::base64", "cargo::flate2")
使用cxxbridge 在c++ 中调用rust
add_rules("mode.debug", "mode.release")
add_requires("cargo::cxx 1.0")
target("foo")
set_kind("static")
add_files("src/foo.rs")
set_values("rust.cratetype", "staticlib")
add_packages("cargo::cxx")
target("test")
set_kind("binary")
add_rules("rust.cxxbridge")
add_deps("foo")
add_files("src/main.cc")
add_files("src/bridge.rsx")
foo.rs
#[cxx::bridge]
mod foo {
extern "Rust" {
fn add(a: i32, b: i32) -> i32;
}
}
pub fn add(a: i32, b: i32) -> i32 {
return a + b;
}
#[cxx::bridge]
mod foo {
extern "Rust" {
fn add(a: i32, b: i32) -> i32;
}
}
C++ 中调用.
http://main.cc
#include <stdio.h>
#include "bridge.rs.h"
int main(int argc, char** argv) {
printf("add(1, 2) == %d\n", add(1, 2));
return 0;
}
Rust 中调用C++ 略了. utils.glsl2spv 规则,引入*.vert/*.frag 来自动编译生成*.spv .也可二进制 内嵌spv 文件.
add_rules("mode.debug", "mode.release")
add_requires("glslang", {configs = {binaryonly = true}})
target("test")
set_kind("binary")
add_rules("utils.glsl2spv", {outputdir = "build"})
add_rules("utils.glsl2spv", {bin2c = true})
add_files("src/*.c")
add_files("src/*.vert", "src/*.frag")
add_packages("glslang")
//
set_runtimes("microlib")
//微控器加运行时.
target("hello")
add_deps("foo")
add_rules("mdk.console")
//静态库.
add_rules("mdk.static")
add_files("src/*.c", "src/*.s")
add_includedirs("src/lib/cmsis")
set_runtimes("microlib")
简化openmp 编译:
add_requires("openmp")
target("loop")
set_kind("binary")
add_files("src/*.cpp")
add_packages("openmp")
v2.6.2
支持配置构建linux 驱动
add_requires("linux-headers", {configs = {driver_modules = true}})
target("hello")
add_rules("platform.linux.driver")
add_files("src/*.c")
add_packages("linux-headers")
set_license("GPL-2.0")
就生成驱动了.Xmake 会自动帮你拉取 指定版本 依赖内核源码 . 用户不需要关心如何搭建内核驱动 开发环境. 依赖,通过
add_requires("linux-headers", {configs = {driver_modules = true}})
add_requires("linux-headers 5.9.x", {configs = {driver_modules = true}})
实现. 交叉编译
$ xmake f -p cross -a arm --sdk=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf -c
$ xmake
$ xmake f -p cross -a arm64 --sdk=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu -c
$ xmake
分组,Run all tests和Run all benchmarks
target("test1")
set_kind("binary")
set_default(false)
set_group("test")
add_files("src/*.cpp")
target("test2")
set_kind("binary")
set_default(false)
set_group("test")
add_files("src/*.cpp")
用
$ xmake -g test
$ xmake --group=test
命令来构建他们.
$ xmake run -g test
$ xmake run --group=test
分组支持匹配模式
$ xmake build -g test_*
$ xmake run -g test/foo_*
$ xmake build -g bench*
$ xmake run -g bench*
方便cmake
add_requires("cmake::ZLIB", {alias = "zlib", system = true})
target("test")
set_kind("binary")
add_files("src/*.c")
add_packages("zlib")
系统 表明强制从系统 中调用cmake 查找包.
add_requires("cmake::OpenCV 4.1.1", {system = true})
add_requires("cmake::Boost", {system = true, configs = {components = {"regex", "system"}})}
add_requires("cmake::Boost", {system = true, configs = {components = {"regex", "system"}, presets = {Boost_USE_STATIC_LIB = true}}})
查找包前,预定义配置 ,来控制查找策略和状态
add_requires("cmake::OpenCV", {system = true, configs = {envs = {CMAKE_PREFIX_PATH = "xxx"}}})
v2.6.3
支持vcpkg 清单模式,
add_requires("vcpkg::zlib 1.2.11+10")
add_requires("vcpkg::fmt >=8.0.1", {configs = {baseline = "50fd3d9957195575849a49fa591e645f1d8e7156"}})
add_requires("vcpkg::libpng", {configs = {features = {"apng"}}})
target("test")
set_kind("binary")
add_files("src/*.cpp")
add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::libpng")
支持,vcpkg/conan/conda/pacman/homebrew/apt/dub/cargo 第3方管理包. 加py .
add_rules("mode.release", "mode.debug")
add_requires("pybind11")
target("example")
add_rules("python.library")
add_rules("python.library", {soabi = true})
add_files("src/*.cpp")
add_packages("pybind11")
set_languages("c++11")
删除头文件
target("test")
add_headerfiles("src/*.h")
remove_headerfiles("src/test.h")
on_config ,在配置完后,构建 前执行. on_load 在加载目标 时执行.
on_load -> after_load -> on_config -> before_build -> on_build -> after_build
内置代理
$ xmake g --proxy_pac=github_mirror.lua
支持riscv32/64 .
|