My xmake project template. C++23, source / examples / tests / external layout,
clang-format + clang-tidy + clangd wiring, and my xmake-repo already registered.
用 GitHub 的 "Use this template",或者:
gh repo create <owner>/<name> --template zzxzzk115/xmake-template --private --clone然后把 xmake.lua 里的 PROJECT_NAME 全部替换成项目名(共 5 处:set_project
和两个 option 的 id / description)。option 的 id 会变成 <name>_build_tests 之类,
下游 has_config() 要对得上。
xmake f -y && xmake build -y
xmake test模板默认 静态运行时 MT/MTd,并且把同一个运行时透传给所有依赖包:
local msvc_runtime = is_mode("debug") and "MTd" or "MT"
set_runtimes(msvc_runtime)
add_requireconfs("**", {configs = {runtimes = msvc_runtime}})两行缺一不可。set_runtimes() 只管本项目的 target;没有 add_requireconfs("**"),
依赖包会按自己的默认(通常 MD)编译,然后拒绝链接进 MT 的 target —— 报 LNK2038,
而且因为 set_runtimes() 看起来已经设过了,排查方向很容易跑偏。
选 MT 是为了对齐 VRI / libvultra 那套包 ——
它们都是 MT 构建的。如果某个项目确实需要动态运行时,改 msvc_runtime 一个变量即可,
但要确认它拉的每个包也都是 MD。
| 路径 | 用途 |
|---|---|
source/ |
库与可执行文件的 target |
external/ |
add_requires 依赖声明 |
tests/ |
单元测试(我一般用 doctest + add_tests("default")) |
examples/ |
示例 |
.clangd.win / .clangd.nowin 由 clangd.config rule 在 on_config 时按宿主平台
拷成 .clangd,不用手动切。