xmake帮助2
示例
target("demo")
-- 构建库时,禁止
if has_config("onlylib") then
set_default(false)
end
-- 加依赖
add_deps("xmake")
-- exe
set_kind("binary")
-- 加定义
add_defines("__tb_prefix__=\"xmake\"")
-- 加包含目录
add_includedirs("$(projectdir)", "$(projectdir)/src")
-- 加源
add_files("**.c")
-- 加资源文件.
if is_plat("windows") then
add_files("*.rc")
end
-- 加链接
if is_plat("windows") then
add_links("ws2_32", "advapi32", "shell32")
add_ldflags("/export:malloc", "/export:free")
else
add_links("pthread", "dl", "m", "c")
end
-- xp兼容.
if is_plat("windows") then
if is_arch("x86") then
add_ldflags("/subsystem:console,5.01")
else
add_ldflags("/subsystem:console,5.02")
end
end
-- 复制进构建目录.
after_build(function (target)
os.cp(target:targetfile(), "$(buildir)/xmake" .. (is_plat("windows") and ".exe" or ""))
end)
加模式
add_rules("mode.release", "mode.debug")
if is_mode("release") then
set_optimize("smallest")
if is_plat("windows") then
add_ldflags("/LTCG")
end
end
加标志加定义
add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing", "-Wno-error=nullability-completeness", "-Wno-error=parentheses-equality")
-- 加定义
add_defines("_GNU_SOURCE=1", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE")
-- 窗口平台
if is_plat("windows") then
add_cxflags("-MT")
add_ldflags("-nodefaultlib:msvcrt.lib")
add_links("kernel32", "user32", "gdi32")
-- 加链接
end
-- 加工程
includes("src/lua-cjson", "src/lcurses", "src/sv","src/luajit", "src/lua", "src/tbox", "src/xmake", "src/demo")
加配置目录
set_configdir("$(buildir)/config")
add_configfiles("test.c.in", {filename = "mytest.c"})
add_includedirs("$(buildir)/config/header")
//加包含目录
仅头文件
target("foo")
set_kind("headeronly")
add_headerfiles("src/foo.h")
add_rules("utils.install.cmake_importfiles")
add_rules("utils.install.pkgconfig_importfiles")
add_files("src/*.manifest")
//加清单
template("console")
add_configfiles("xmake.lua")
//模板,加配置文件.
加工具链
toolchain("dlang")
-- 主页,描述
set_homepage("https://dlang.org/")
set_description("D语言")
-- 检查
on_check("check")
-- 加载
on_load(function (toolchain)
-- 导入
import("core.project.config")
-- 前缀
local cross = toolchain:cross() or ""
-- 工具集
toolchain:add("toolset", "dc", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcld", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcsh", "$(env DC)", "dmd", "ldc2", cross .. "gdc")
toolchain:add("toolset", "dcar", "$(env DC)", "dmd", "ldc2", cross .. "gcc-ar")
-- 初始标志
local march
if toolchain:is_arch("x86_64", "x64") then
march = "-m64"
elseif toolchain:is_arch("i386", "x86") then
march = "-m32"
end
toolchain:add("dcflags", march or "")
toolchain:add("dcshflags", march or "")
toolchain:add("dcldflags", march or "")
end)
xmake的xmake
target("xmake")
-- 静态库
set_kind("static")
-- 加依赖
if has_config("curses") or has_config("pdcurses") then
add_deps("lcurses")
end
add_deps("sv", "lua-cjson", "tbox")
add_deps(get_config("runtime"))
-- 加定义
add_defines("__tb_prefix__=\"xmake\"")
if is_mode("debug") then
add_defines("__tb_debug__", {public = true})
end
-- 置自动生成`配置.h`
set_configdir("$(buildir)/$(plat)/$(arch)/$(mode)")
add_configfiles("xmake.config.h.in")
-- 加包含目录
add_includedirs("..", {interface = true})
add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)", {public = true})
-- 加头文件.
add_headerfiles("../(xmake/*.h)")
add_headerfiles("../(xmake/prefix/*.h)")
add_headerfiles("$(buildir)/$(plat)/$(arch)/$(mode)/xmake.config.h", {prefixdir = "xmake"})
-- 加源文件
add_files("**.c|winos/*.c")
if is_plat("windows", "msys", "cygwin") then
add_files("winos/*.c")
end
-- 加选项
add_options("readline")
if is_plat("windows") then
add_defines("UNICODE", "_UNICODE")
end
定义规则
rule("markdown")
set_extensions(".md", ".markdown")
on_load(function (target)
print("markdown: on_load")
end)
on_build_file(function (target, sourcefile)
print("compile %s", sourcefile)
os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
end)
差不多了,遇到了,再看吧.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现