GitHub - Meidozuki/VBAO: A library aiming for building an MVVM (or MVFM) project
https://github.com/Btk-Project/xmake-repo
GitHub - tboox/gbox: 🎨 A multi-platform graphic library
GitHub - tboox/vm86: 🍔 A x86 Script Instruction Virtual Machine
GitHub - tboox/ltui: 🍖 A cross-platform terminal ui library based on Lua
#https://xmake.io/#/guide/faq?id=breakpoint-debugging
xrepo update-repo
xrepo env -b emmylua_debugger -- xmake build #调试构建
xrepo env -b emmylua_debugger -- xmake install -o /tmp #调试安装
Create Project:
xmake create -l c -P ./hello
xmake create -l c -t console test
xmake create -l c -t static test
xmake create -l c -t shared test
xmake create -l c++ -t console_qt test
xmake create -l c++ -t static_qt test
xmake create -l c++ -t shared_qt test
xmake create -l c++ -t quickapp_qt test
xmake create -t quickapp_qt -l c ++ appAndroidDemo
xmake create -t xcode.macapp -l objc test
xmake create -t xcode.iosapp -l objc test
xmake create -t xcode.framework -l objc test
xmake create -t xcode.bundle -l objc test
xmake create -l go -t console test
Build Project:
xmake #generate xmake.lua automatically and build
xmake f -y #generate xmake.lua automatically
Run Program:
xmake run hello || xmake r hello
Debug Program:
xmake config -m debug && xmake && xmake f --debugger=gdb && xmake run -d hello
Paltform:
xmake f -p wasm --toolchain=wasi [--qt=~/Qt]
xmake f -p [iphoneos|macosx|windows|android] -a [armv7|armv7s|arm64|i386|x86_64]
xmake f -p mingw --sdk=/usr/local/i386-mingw32-4.3.0/ [-a i386|x86_64|arm|arm64]
xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/
SDK:
xmake f --qt=~/Qt/Qt5.9.1
xmake f -p cross android --ndk=~/Downloads/android-ndk-r19c/ --android_sdk=~/Library/Android/sdk/ --bin=/usr/opt/bin --cross=armv7-linux- -c
xmake f --wdk="G:\Program Files\Windows Kits\10" -c
xmake f --wdk_winver=[win10_rs3|win8|win7|win7_sp1]
xmake f --cuda=/usr/local/cuda-9.1/
Flags:
--cflags,--cxxflags, --ldflags, --shflags and --arflags
xmake f -p cross --sdk=/user/toolsdk
--cc=armv7-linux-clang
--cxx=armv7-linux-clang++
--ld=armv7-linux-clang++
--sh=armv7-linux-clang++
--ar=armv7-linux-ar
--includedirs=/usr/toolsdk/xxx/include
--linkdirs=/usr/toolsdk/xxx/lib
--links=pthread
--cflags="-DTEST -I/xxx/xxx"
--ldflags="-lpthread"
--cxflags Set c/c++ compiler option
g global configuration
-c clean all cached configuration and re-configure project.
(multiple directories use : under linux / macos, and ; under win.)
set_config("cflags", "-DTEST")
set_config("sdk", "/home/xxx/tooksdk")
set_config("cc", "gcc")
set_config("ld", "g++")
xmake f -m debug --menu --xxx=y --export=/tmp/config.txt --import=/tmp/config.txt
Install:
xmake install
xmake [p|package] -o outputdir -f remote #generate package
xmake uninstall
Custom toolchain:
xmake f --toolchain=[myclang,emcc]
--bin Set the bin directory of toolchains
--cross Set the prefix of compilation tools
--as Set asm assembler
--asflags Set asm assembler option
toolchain("myclang")
set_kind("standalone")
set_toolset("cc", "clang")
set_toolset("cxx", "clang", "clang++")
set_toolset("ld", "clang++", "clang")
set_toolset("sh", "clang++", "clang")
set_toolset("ar", "ar")
set_toolset("ex", "ar")
set_toolset("strip", "strip")
set_toolset("mm", "clang")
set_toolset("mxx", "clang", "clang++")
set_toolset("as", "clang")
Policies:
xmake f --ccache=n || xmake f --policies=build.ccache:n,build.sanitizer.address #n->禁用缓存,没有表示开启
set_policy("build.warning", true)
set_warnings("all", "extra")
set_policy("build.optimization.lto", true) #link-time optimisation (LTO)
set_policy("check.auto_ignore_flags", false) #自动忽略
set_policy("check.auto_map_flags", false) #自定映射到不同平台
set_policy("build.across_targets_in_parallel", false) #多目标并行编译
set_policy("build.ccache", false)
set_policy("build.sanitizer.address", true)
set_policy("build.sanitizer.undefined", true)
set_policy("build.sanitizer.thread", true)
set_policy("build.sanitizer.memory", true)
set_policy("build.sanitizer.leak", true)
add_requires("zlib", {configs = {asan = true}}) #Address Sanitizer (ASan)
xmake f --policies=run.autobuild
set_policy("package.librarydeps.strict_compatibility", true)
set_policy("package.download.http_headers", "TEST1: foo", "TEST2: bar")
add_urls("https://github.com/madler/zlib/archive/$(version).tar.gz", {
http_headers = {"TEST1: foo", "TEST2: bar"}
})
preprocessor.linemarkers
preprocessor.gcc.directives_only
package.requires_lock
package.precompiled
package.fetch_only
package.install_only
package.strict_compatibility
package.install_always
Help:
xmake create --help
xmake f --help
xmake show -l toolchains
xmake -v -D
xmake show -l envs
xmake l os.programdir
xmake [action|plugin] [-h|--help]
xmake [-q|--quiet]
xmake [-w|--warning]
xmake l find_package cmake::ZLIB
构建脚本调试:
https://xmake.io/#/guide/faq?id=breakpoint-debugging
无法连接9966端口,改"host": "127.0.0.1"。或vscode底部重启EmmyLua。
xrepo update-repo
xrepo env -b emmylua_debugger -- xmake build #调试构建
xrepo env -b emmylua_debugger -- xmake install -o /tmp #调试安装
文档生成:
xmake doxygen
Executable Program:
-- set project name
set_project("tbox")
-- set project version
set_version("1.5.1", {build = "%Y%m%d%H%M", soname = true})\
-- the current xmake version must be larger than 2.1.0
set_xmakever("2.1.0")
add_moduledirs("$(projectdir)/modules")
add_packagedirs("packages")
add_rules("mode.debug", "mode.release")
add_requires("qt5widgets", {optional = true, asan = true, debug = true, small=true, verify = false, external = false})
add_requires("go::github.com/sirupsen/logrus", {alias = "logrus"})
add_requires("go::golang.org/x/sys/internal/unsafeheader", {alias = "unsafeheader"})
add_requires("cmake::ZLIB", {alias = "zlib", system = true})
add_requires("cmake::Boost", {system = true, configs = {components = {"regex", "system"}}))
add_requires("cmake::OpenCV", {system = true, configs = {envs = {CMAKE_PREFIX_PATH = "xxx"}}})
add_requires("cmake::xxx", {configs = {link_libraries = {"abc::lib1", "abc::lib2"}}})
add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0")
add_configfiles("../include/co/config.h.in", {filename = "../include/co/config.h"})
add_repositories("my-repo my-repo")
option("linux-headers", {showmenu = true, description = "Set linux-headers path."})
if is_plat("windows", "macosx") then
add_requires("go::golang.org/x/sys/windows", {alias = "syshost"})
add_links("pthread", "m", "dl")
else
for _, name in ipairs({"pthread", "m", "dl"}) do
add_links(name)
end
add_requires("go::golang.org/x/sys/unix", {alias = "syshost"})
end
if is_plat("myplat") then
add_defines("TEST")
end
target("test")
set_plat("cross")
set_arch("c-sky")
set_targetdir("$(projectdir)/lib")
set_rundir("$(projectdir)")
set_basename("co")
add_rules("xcode.application" || "xcode.framework" || "xcode.bundle")
add_files("src/*.m", "src/**.storyboard", "src/*.xcassets")
add_files("src/Info.plist")
add_values("xcode.bundle_identifier", "org.tboox.test")
add_values("xcode.codesign_identity", "Apple Development: xxx@gmail.com (T3NA4MRVPU)")
add_values("xcode.mobile_provision", "iOS Team Provisioning Profile: org.tboox.test")
after_load(function (target)
for _, sourcebatch in pairs(target:sourcebatches()) do
if sourcebatch.sourcekind == "as" then -- only asm files
for idx, objectfile in ipairs(sourcebatch.objectfiles) do
sourcebatch.objectfiles[idx] = objectfile:gsub("%.S%.o", ".o")
end
end
end
end)
target:set("filename", TARGET_NAME..".elf")
target:add("ldflags", flto .. "-Wl,--gc-sections -Wl,-zmax-page-size=1024 -Wl,--whole-archive ./lib/libwmarch.a ./lib/libgt.a ./lib/libwlan.a ./lib/libdsp.a ./lib/libbtcontroller.a -Wl,--no-whole-archive -mcpu=ck804ef -nostartfiles -mhard-float -lm -Wl,-T./ld/air101_103.ld -Wl,-ckmap=./build/out/"..TARGET_NAME..".map ",{force = true})
target("usbview")
add_rules("win.sdk.application")
add_files("*.c", "*.rc")
add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"})
set_values("wdk.sign.certfile", path.join(os.projectdir(), "xxxx.cer"))
set_values("wdk.env.winver", "win10")
target("qt_static_library")
add_rules("qt.static" || "qt.shared" || "qt.console" || "qt.quickapp" || "qt.quickapp_static" || "qt.qmlplugin" || "qt.widgetapp")
add_packages("qt5widgets")
add_headerfiles("src/*.h")
add_files("src/*.cpp")
add_files("src/mainwindow.ui")
set_values("qt.qmlplugin.import_name", "My.Plugin")
add_frameworks("QtNetwork", "QtGui", "QtWidgets")
target("library")
set_kind("static" || "shared")
add_files("src/library/*.c")
add_deps("add", "sub")
set_policy("build.merge_archive", true) #合并静态库
target("test")
set_kind("binary")
set_languages("c++11")
add_packages("protobuf-cpp")
add_packages("logrus", "syshost", "unsafeheader")
add_rules("lex", "yacc")
add_files("src/*.c")
add_files("*.mpp", { install = true })
add_deps("library")
-- generate SASS code for SM architecture of current host
add_cugencodes("native")
-- generate PTX code for the virtual architecture to guarantee compatibility
add_cugencodes("compute_30")
add_values("iverilogs.flags", "-DTEST")
add_defines("DEBUG")
add_syslinks("pthread")
set_license("GPL-2.0")
set_policy("build.c++.modules", true)
set_toolchains("@iverilog", "clang", "yasm")
set_toolset("cxx", "clang")
set_toolset("ld", "clang++")
add_ldflags("-static", {force = true})
target_end()
target("VBAO")
set_installdir("$(buildir)/install")
add_installfiles("Lib_VBao/COPYING.LESSER",{prefixdir = "VBAO"})
add_installfiles("Lib_VBao/VBAO/*",{prefixdir = "VBAO/include"})
set_languages("cxx17")
set_kind("headeronly")
package("foo") # on/after/before_build/install/package/run
set_sourcedir(path.join(os.scriptdir(), "src"))
on_install(function(package)
import("package.tools.xmake").install(package, {})
end)
after_link(function (target)
import("utils.archive.merge_staticlib")
merge_staticlib(target, "libout.a", {"libfoo.a", "libbar.a"})
end)
on_fetch(function (package, opt)
return {includedirs = "/usr/src/linux-headers-5.0/include"}
end)
on_load(function (target)
if is_plat("linux", "macosx") then
target:add("links", "pthread", "m", "dl")
end
end)
after_build(function (target)
Import("core.project.config")
Local targetfile = target:targetfile()
Os.cp(targetfile, path.join(config.buildir(), path.filename(targetfile)))
Print("build %s", targetfile)
-- Execute signature, if it fails, automatically interrupt, giving a highlight error message
os.run("ldid -S$(projectdir)/entitlements.plist %s", target:targetfile())
end)
on_load("modules.test.load")
on_install("modules.test.install")
on_run(function ()
-- Internal scope
end)
after_package(function ()
-- Internal scope
end)
if is_host("windows") then
set_urls("http://cdndownload.openluat.com/xmake/toolchains/csky/csky-elfabiv2-tools-mingw-minilibc-$(version).tar.gz")
add_versions("20210423", "e7d0130df26bcf7b625f7c0818251c04e6be4715ed9b3c8f6303081cea1f058b")
add_versions("20230301", "1b958769601e8ba94a866df68215700614f55e0152933d5f5263899bb44d24f5")
elseif is_host("linux") then
set_urls("http://cdndownload.openluat.com/xmake/toolchains/csky/csky-elfabiv2-tools-x86_64-minilibc-$(version).tar.gz")
add_versions("20210423", "8b9a353c157e4d44001a21974254a21cc0f3c7ea2bf3c894f18a905509a7048f")
add_versions("20230301", "dac3c285d7dc9fe91805d6275c11fa260511cdd6a774891cbe2d79ec73535e10")
end
on_install("@windows", "@linux", function (package)
os.vcp("*", package:installdir())
end)
-- external scope
task("hello") do
-- external scope
on_run(function ()
-- Internal scope
end)
end
-- option settings, only local settings are supported, not affected by global api settings
option("test")
-- local scope of the current option
set_default(false)
set_showmenu(true)
set_description("test1 option")
option_end()
-- local variables, only valid for current xmake.lua
local var1 = 0
-- global variables that affect all subsmake.lua included after includes()
var2 = 1
includes("src")
target("demo", {kind = "binary", files = "src/*.c"})
option("test1", {default = true, showmenu = true, description = "test1 option"})
Integrate CMake source library:
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")
常用命令:
-- 显示目标文件路径
print(target:targetfile())
-- 显示目标的构建类型
print(target:get("kind"))
-- 显示目标的宏定义
print(target:get("defines"))
-- 获取当前工程目录
print(project.directory())
-- add_deps("UIEvent")
-- add_links("tbox")
-- add_linkdirs("lib")
import("module", {alias="test", rootdir="./", inherit = true})
testModule()
target("Global")
set_kind("shared")
add_files("*.cpp")
add_files("Private/*.cpp")
add_files("Private/*/*.cpp", "Private/**/*.cpp")
-- 添加src下的所有cpp文件,但是不包括src/test.cpp、src/hello.cpp以及src下所有带xx_前缀的cpp文件
-- add_files("src/*.cpp|test.cpp|hello.cpp|xx_*.cpp")
add_includedirs("Private", {private = true})
add_includedirs("Private/Port", {private = true})
add_includedirs("Public", {interface = true}) -- public 当前target,依赖的子target都会被设置
add_defines("BUILDING_$(target:name():upper)")
-- os模块
-- 运行shell命令,如果运行失败直接中断,并显示出错信息,我们不需要判断返回值
os.run("echo hello xmake!")
-- 复制文件
os.cp("/tmp/src", "/tmp/dst")
-- 删除文件或者目录
os.rm("/tmp/dir")
-- 移动文件
os.mv("/tmp/old", "/tmp/new")
-- 判断文件是否存在
if os.isfile("/tmp/file") then
end
-- 判断目录是否存在
if os.isdir("/tmp/dir") then
end
-- 匹配遍历文件,*为非递归匹配,**为递归匹配
for _, file in ipairs(os.match("src/*.c")) do
print(file)
end
-- 匹配遍历目录,*为非递归匹配,**为递归匹配
for _, file in ipairs(os.match("src/*", true)) do
print(file)
end
-- 常用api
-- 抛出异常,立即中断
raise()
-- 抛出异常,立即中断,并抛出异常错误信息
raise("error info")
-- 抛出异常,立即中断,并抛出异常错误代码
raise(-1)
-- 显示输出并换行,支持格式化输出,跟lua的print稍有不同
print("hello %s", "xmake")
-- 显示输出不换行
printf("hello %s", "xmake")
-- 格式化字符串
s = format("hello %s", "xmake")
-- 异常捕获api
try
{
-- try块,里面抛出异常
function ()
raise("error")
end,
catch
{
-- catch块,捕获异常
function (errors)
print(errors)
end
}
}
-- 获取try块的返回值,如果没有异常的话返回true
local ok = try
{
-- try块,里面抛出异常
function ()
-- may be error
return true
end
}
try
{
-- try块,里面抛出异常
function ()
raise("error")
end,
catch
{
-- catch块,捕获异常
function (errors)
print(errors)
end
},
finally
{
-- finally 块
function ()
end
}
}
-- path模块
-- 获取相对路径
path.relative("/tmp/a")
-- 获取绝对路径
path.absolute("src")
-- 获取目录
path.directory("/tmp/a")
-- 获取文件名 test.c
path.filename("/tmp/test.c")
-- 获取base名 test
path.basename("/tmp/test.c")
-- 获取扩展名
path.extension("/tmp/test.c")
-- 拼接路径 /tmp/test.c
path.join("/tmp", "test.c")
-- io 模块
-- 打开一个写文件
file = io.open("/tmp/a", "w")
-- 写文件数据
file:write("hello")
-- 写文件格式化行
file:print("hello %s", "xmake")
-- 写文件格式化不换行
file:printf("hello %s", "xmake")
-- 关闭文件
file:close()
-- 序列化写一个lua对象到文件
io.save("/tmp/a", object)
-- 反序列化读取一个文件对象
object = io.load("/tmp/a")
-- 读取文件数据,并显示
io.cat("/tmp/a")
-- 模式替换文件内容, 替换空格字符为 "space"
io.gsub("/tmp/a", "%s", "space")
-- tostring, tonumber
print("$(tmpdir)")
add_ldflags("$(shell pkg-config --libs sqlite3)")
-- 如果手动启用了xmake f --demo=y 选项
if is_option("demo") then
-- 编译demo目录下的代码
add_subdirs("src/demo")
end
-- 外置变量
local root = "/tmp"
set_objectdir(root .. ".objs")
set_dependir("$(buildir)/.deps")
local ld_data = io.readfile("./ld/air101_103.ld")
local ORIGIN, I_SRAM_LENGTH = ld_data:match("I-SRAM : ORIGIN = 0x(%x+) , LENGTH = 0x(%x+)")
skia编译:
add_requires("skia")
target("demo")