基本命令介绍

在介绍 xmake 命令行程序的各种子命令前,我们先介绍下 xmake 的 help 菜单,所有 xmake 命令参数都是可以从这个菜单中找到,并且有相应的描述和参数值说明。

因此,在还不熟悉怎么使用某个子命令的时候,都可以通过查看对应的帮助菜单里面的参数说明,来快速找到想要的某个设置参数的使用方式。

主菜单

xmake 的整个命令行格式如下

  1. xmake [task] [options] [target]

主要由 [task]、[options] 还有 [target] 组成,其中 [] 部分表示可选输入,里面的 task 就是子命令任务名,xmake 提供了很多的内置子命令以及插件任务子命令,可以通过执行 xmake —help 在主菜单里面查看具体有哪些子命令,整个主菜单的列表内容如下。

  1. xmake [task] [options] [target]
  2. xmake v2.5.9+HEAD.809ee9806, A cross-platform build utility based on LuaJIT
  3. Copyright (C) 2015-present Ruki Wang, tboox.org, xmake.io
  4. _
  5. __ ___ __ __ __ _| | ______
  6. \ \/ / | \/ |/ _ | |/ / __ \
  7. > < | \__/ | /_| | < ___/
  8. /_/\_\_|_| |_|\__ \|_|\_\____|
  9. by ruki, xmake.io
  10. 👉 Manual: https://xmake.io/#/getting_started
  11. 🙏 Donate: https://xmake.io/#/sponsor
  12. Usage: $xmake [task] [options] [target]
  13. Build targets if no given tasks.
  14. Actions:
  15. create Create a new project.
  16. c, clean Remove all binary and temporary files.
  17. f, config Configure the project.
  18. p, package Package target.
  19. r, run Run the project target.
  20. u, uninstall Uninstall the project binary files.
  21. q, require Install and update required packages.
  22. b, build Build targets if no given tasks.
  23. update Update and uninstall the xmake program.
  24. g, global Configure the global options for xmake.
  25. i, install Package and install the target binary files.
  26. Plugins:
  27. repo Manage package repositories.
  28. doxygen Generate the doxygen document.
  29. project Generate the project file.
  30. show Show the given project information.
  31. l, lua Run the lua script.
  32. plugin Manage plugins of xmake.
  33. m, macro Run the given macro.
  34. service Start service for remote or distributed compilation and etc. (Experimental, still in development)
  35. Common options:
  36. -q, --quiet Quiet operation.
  37. -y, --yes Input yes by default if need user confirm.
  38. --confirm=CONFIRM Input the given result if need user confirm.
  39. - yes
  40. - no
  41. - def
  42. -v, --verbose Print lots of verbose information for users.
  43. --root Allow to run xmake as root.
  44. -D, --diagnosis Print lots of diagnosis information (backtrace, check info ..) only for developers.
  45. And we can append -v to get more whole information.
  46. e.g. $ xmake -vD
  47. --version Print the version number and exit.
  48. -h, --help Print this help message and exit.
  49. -F FILE, --file=FILE Read a given xmake.lua file.
  50. -P PROJECT, --project=PROJECT Change to the given project directory.
  51. Search priority:
  52. 1. The Given Command Argument
  53. 2. The Envirnoment Variable: XMAKE_PROJECT_DIR
  54. 3. The Current Directory
  55. Command options (build):
  56. -b, --build Build target. This is default building mode and optional.
  57. -r, --rebuild Rebuild the target.
  58. -a, --all Build all targets.
  59. --dry-run Dry run to build target.
  60. -j JOBS, --jobs=JOBS Set the number of parallel compilation jobs. (default: 12)
  61. --linkjobs=LINKJOBS Set the number of parallel link jobs.
  62. -w, --warning Enable the warnings output.
  63. --files=FILES Build the given source files.
  64. e.g.
  65. - xmake --files=src/main.c
  66. - xmake --files='src/*.c' [target]
  67. - xmake --files='src/**c|excluded_file.c'
  68. - xmake --files='src/main.c;src/test.c'
  69. target The target name. It will build all default targets if this parameter is not
  70. specified.

而 options 就是指的上图中的参数选项,除了主菜单的参数选项,每个子命令也有对应的参数选项,比如 xmake build —help 就是 build 子命令的帮助菜单。
最后面的 target 指的是当前的命令是针对哪个目标程序的,这个也是可选的参数,并不是所有命令都有,主要是 build、install 等这些基础命令才提供,用于指定编译、安装对应的目标程序,而默认不指定,则会编译安装所有程序。

在上图中的 Actions 区域的子命令,就是用于跟构建相关的所有内置命令,而 Plugins 区域的子命令,是扩展的插件命令。这里我们主要简单介绍下 Actions 命令,其实很多在实验 1 《xmake 的基本使用》中都已经使用过。

  • config:配置编译需要的参数,比如平台、架构等。
  • global:全局配置编译参数。
  • build:构建程序。
  • run:运行目标程序。
  • install:安装编译后的目标程序。
  • uninstall:卸载之前安装的程序文件。
  • package:打包编译生成的库和头文件。
  • clean:清理编译过程中生成的临时文件。
  • require:手动拉取第三方依赖库。
  • update:xmake 程序自更新。