Skip to content

add xmake build #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ build/
*.a
.vscode
compile_commands.json
log.txt
scripts/*.txt
cmake-build-debug
.idea
.xmake
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ $ mkdir build
$ cd build && make -j 8
$ make run
```

## 使用 XMake 编译
XMake 是一个基于 Lua 的轻量级跨平台构建工具,使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能快速入门,能够让用户把更多的精力集中在实际的项目开发上。

> 关于如何安装 XMake, 请参考 [XMake 安装教程](https://xmake.io/#/zh-cn/guide/installation)

### 1.设置编译选项

```bash
xmake -f --type=<type> --mode=<debug/release>
```

其中 `<type>` 为 `sentry`、`infantry`、`hero` 之一,`mode` 表示当前以 `debug` 模式编译还是 `release` 模式。

在使用过程中,你可以随时运行上面的目录来修改编译选项。

### 2.编译

```bash
xmake build
```

在构建过程中会要求安装第三方库,输入 `y` 即可。

在编译结束后,你可以在输出文件夹中找到编译结果,生成的二进制文件名与第一步中设置的 `type` 一致。输出文件夹位于 `build` 目录下,并按照以下规则命名:[平台]\\[架构]\\[编译模式]。例如,假设在x86的linux上以 release模式编译,那么输出的文件位于 build\linux\x86_64\release下。
38 changes: 38 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
add_rules("mode.debug", "mode.release")
add_requires("serial")

option("type")
set_default("infantry")
set_showmenu(true)
set_description("指定要编译的机器人类型")
set_values("infantry","hero","sentry")
after_check(function(option)
option:add("defines", "CONFIG_" .. string.upper(option:value()))
option:set("basename",option:value())
end)

target("GKDControl")
set_kind("binary")
set_languages("c++23")
add_files(
"src/*.cc",
"src/**/*.cc"
)
add_includedirs(
"include",
"include/chassis",
"include/configs",
"include/device",
"include/device/referee",
"include/gimbal",
"include/utils"
)
add_packages("serial")
set_warnings("allextra")

add_options("type")
set_basename(get_config("type"))

if(is_mode("debug")) then
add_defines("__DEBUG__")
end