index.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>xmake</title>
  6. <link rel="icon" href="/assets/img/favicon.ico">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  8. <meta name="description" content="Description">
  9. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  11. <style>
  12. .markdown-body {
  13. box-sizing: border-box;
  14. min-width: 200px;
  15. max-width: 980px;
  16. margin: 0 auto;
  17. padding: 45px;
  18. }
  19. @media (max-width: 767px) {
  20. .markdown-body {
  21. padding: 15px;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <article class="markdown-body">
  28. <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/zh-cn/">https://xmake.io/#/zh-cn/</a>
  29. <div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
  30. </br>
  31. <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
  32. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  33. <style>
  34. #carbonads {
  35. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  36. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  37. }
  38. #carbonads {
  39. display: flex;
  40. max-width: 330px;
  41. background-color: hsl(0, 0%, 98%);
  42. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  43. }
  44. #carbonads a {
  45. color: inherit;
  46. text-decoration: none;
  47. }
  48. #carbonads a:hover {
  49. color: inherit;
  50. }
  51. #carbonads span {
  52. position: relative;
  53. display: block;
  54. overflow: hidden;
  55. }
  56. #carbonads .carbon-wrap {
  57. display: flex;
  58. }
  59. .carbon-img {
  60. display: block;
  61. margin: 0;
  62. line-height: 1;
  63. }
  64. .carbon-img img {
  65. display: block;
  66. }
  67. .carbon-text {
  68. font-size: 13px;
  69. padding: 10px;
  70. line-height: 1.5;
  71. text-align: left;
  72. }
  73. .carbon-poweredby {
  74. display: block;
  75. padding: 8px 10px;
  76. background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  77. text-align: center;
  78. text-transform: uppercase;
  79. letter-spacing: .5px;
  80. font-weight: 600;
  81. font-size: 9px;
  82. line-height: 1;
  83. }
  84. </style>
  85. <h2 id="">项目支持</h2>
  86. <p>通过<a href="https://xmake.io/#/about/sponsor">成为赞助者</a>来支持该项目。您的logo将显示在此处,并带有指向您网站的链接。🙏</p>
  87. <p><a href="https://opencollective.com/xmake#sponsors" target="_blank"><img src="https://opencollective.com/xmake/sponsors.svg?width=890"></a><br><a href="https://opencollective.com/xmake#backers" target="_blank"><img src="https://opencollective.com/xmake/backers.svg?width=600"></a></p>
  88. <h2 id="">技术支持</h2>
  89. <p>你也可以考虑通过 <a href="https://github.com/sponsors/waruqi">Github 的赞助计划</a> 赞助我们来获取额外的技术支持服务,然后你就能获取 <a href="https://github.com/xmake-io/technical-support">xmake-io/technical-support</a> 仓库的访问权限,获取更多技术咨询相关的信息。</p>
  90. <ul>
  91. <li>[x] 更高优先级的 Issues 问题处理</li>
  92. <li>[x] 一对一技术咨询服务</li>
  93. <li>[x] Review xmake.lua 并提供改进建议</li>
  94. </ul>
  95. <h2 id="">简介</h2>
  96. <p>Xmake 是一个基于 Lua 的轻量级跨平台构建工具。</p>
  97. <p>它非常的轻量,没有任何依赖,因为它内置了 Lua 运行时。</p>
  98. <p>它使用 xmake.lua 维护项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对新手非常友好,短时间内就能快速入门,能够让用户把更多的精力集中在实际的项目开发上。</p>
  99. <p>我们能够使用它像 Make/Ninja 那样可以直接编译项目,也可以像 CMake/Meson 那样生成工程文件,另外它还有内置的包管理系统来帮助用户解决 C/C++ 依赖库的集成使用问题。</p>
  100. <p>目前,Xmake 主要用于 C/C++ 项目的构建,但是同时也支持其他 native 语言的构建,可以实现跟 C/C++ 进行混合编译,同时编译速度也是非常的快,可以跟 Ninja 持平。</p>
  101. <pre><code>Xmake = Build backend + Project Generator + Package Manager + [Remote|Distributed] Build + Cache
  102. </code></pre><p>尽管不是很准确,但我们还是可以把 Xmake 按下面的方式来理解:</p>
  103. <pre><code>Xmake ≈ Make/Ninja + CMake/Meson + Vcpkg/Conan + distcc + ccache/sccache
  104. </code></pre><p>如果你想要了解更多,请参考:<a href="https://xmake.io/#/zh-cn/getting_started">在线文档</a>, <a href="https://github.com/xmake-io/xmake">Github</a>以及<a href="https://gitee.com/tboox/xmake">Gitee</a>,同时也欢迎加入我们的 <a href="https://xmake.io/#/zh-ch/about/contact">社区</a>.</p>
  105. <h2 id="">课程</h2>
  106. <p>xmake 官方也推出了一些入门课程,带你一步步快速上手 xmake,课程列表如下:</p>
  107. <ul>
  108. <li><a href="https://xmake.io/#/zh-cn/about/course">Xmake 带你轻松构建 C/C++ 项目</a></li>
  109. </ul>
  110. <h2 id="">安装</h2>
  111. <h4 id="curl">使用curl</h4>
  112. <pre><code class="lang-bash">curl -fsSL https://xmake.io/shget.text | bash
  113. </code></pre>
  114. <h4 id="wget">使用wget</h4>
  115. <pre><code class="lang-bash">wget https://xmake.io/shget.text -O - | bash
  116. </code></pre>
  117. <h4 id="powershell">使用powershell</h4>
  118. <pre><code class="lang-powershell">Invoke-Expression (Invoke-Webrequest &#39;https://xmake.io/psget.text&#39; -UseBasicParsing).Content
  119. </code></pre>
  120. <h4 id="">其他安装方式</h4>
  121. <p>如果不想使用脚本安装,也可以点击查看 <a href="https://xmake.io/#/zh-cn/guide/installation">安装文档</a>,了解其他安装方法。</p>
  122. <h2 id="">简单的工程描述</h2>
  123. <p><img src="https://xmake.io/assets/img/index/showcode1.png" width="340px" /></p>
  124. <h2 id="">包依赖描述</h2>
  125. <p><img src="https://xmake.io/assets/img/index/add_require.png" width="600px" /></p>
  126. <p>官方的xmake包管理仓库: <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a></p>
  127. <h2 id="">构建工程</h2>
  128. <pre><code class="lang-bash">$ xmake
  129. </code></pre>
  130. <h2 id="">运行目标</h2>
  131. <pre><code class="lang-bash">$ xmake run console
  132. </code></pre>
  133. <h2 id="">调试程序</h2>
  134. <pre><code class="lang-bash">$ xmake run -d console
  135. </code></pre>
  136. <h2 id="">配置平台</h2>
  137. <pre><code class="lang-bash">$ xmake f -p [windows|linux|macosx|android|iphoneos ..] -a [x86|arm64 ..] -m [debug|release]
  138. $ xmake
  139. </code></pre>
  140. <h2 id="">图形化菜单配置</h2>
  141. <pre><code class="lang-bash">$ xmake f --menu
  142. </code></pre>
  143. <p><img src="https://xmake.io/assets/img/index/menuconf.png" width="650px" /></p>
  144. <h2 id="ninja">跟ninja一样快的构建速度</h2>
  145. <p>测试工程: <a href="https://github.com/xmake-io/xmake/tree/master/core">xmake-core</a></p>
  146. <h3 id="">多任务并行编译测试</h3>
  147. <table>
  148. <thead>
  149. <tr>
  150. <th>构建系统</th>
  151. <th>Termux (8core/-j12)</th>
  152. <th>构建系统</th>
  153. <th>MacOS (8core/-j12)</th>
  154. </tr>
  155. </thead>
  156. <tbody>
  157. <tr>
  158. <td>xmake</td>
  159. <td>24.890s</td>
  160. <td>xmake</td>
  161. <td>12.264s</td>
  162. </tr>
  163. <tr>
  164. <td>ninja</td>
  165. <td>25.682s</td>
  166. <td>ninja</td>
  167. <td>11.327s</td>
  168. </tr>
  169. <tr>
  170. <td>cmake(gen+make)</td>
  171. <td>5.416s+28.473s</td>
  172. <td>cmake(gen+make)</td>
  173. <td>1.203s+14.030s</td>
  174. </tr>
  175. <tr>
  176. <td>cmake(gen+ninja)</td>
  177. <td>4.458s+24.842s</td>
  178. <td>cmake(gen+ninja)</td>
  179. <td>0.988s+11.644s</td>
  180. </tr>
  181. </tbody>
  182. </table>
  183. <h3 id="">单任务编译测试</h3>
  184. <table>
  185. <thead>
  186. <tr>
  187. <th>构建系统</th>
  188. <th>Termux (-j1)</th>
  189. <th>构建系统</th>
  190. <th>MacOS (-j1)</th>
  191. </tr>
  192. </thead>
  193. <tbody>
  194. <tr>
  195. <td>xmake</td>
  196. <td>1m57.707s</td>
  197. <td>xmake</td>
  198. <td>39.937s</td>
  199. </tr>
  200. <tr>
  201. <td>ninja</td>
  202. <td>1m52.845s</td>
  203. <td>ninja</td>
  204. <td>38.995s</td>
  205. </tr>
  206. <tr>
  207. <td>cmake(gen+make)</td>
  208. <td>5.416s+2m10.539s</td>
  209. <td>cmake(gen+make)</td>
  210. <td>1.203s+41.737s</td>
  211. </tr>
  212. <tr>
  213. <td>cmake(gen+ninja)</td>
  214. <td>4.458s+1m54.868s</td>
  215. <td>cmake(gen+ninja)</td>
  216. <td>0.988s+38.022s</td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. <h2 id="">包依赖管理</h2>
  221. <h3 id="">下载和编译</h3>
  222. <p><img src="https://xmake.io/assets/img/index/package_manage.png" width="650px" /></p>
  223. <h3 id="">架构和流程</h3>
  224. <p><img src="https://xmake.io/assets/img/index/package_arch.png" width="650px" /></p>
  225. <h3 id="">支持的包管理仓库</h3>
  226. <ul>
  227. <li>官方自建仓库 <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a> (tbox >1.6.1)</li>
  228. <li>官方包管理器 <a href="https://github.com/xmake-io/xrepo">Xrepo</a></li>
  229. <li><a href="https://xmake.io/#/zh-cn/package/remote_package?id=%e4%bd%bf%e7%94%a8%e8%87%aa%e5%bb%ba%e7%a7%81%e6%9c%89%e5%8c%85%e4%bb%93%e5%ba%93">用户自建仓库</a></li>
  230. <li>Conan (conan::openssl/1.1.1g)</li>
  231. <li>Conda (conda::libpng 1.3.67)</li>
  232. <li>Vcpkg (vcpkg::ffmpeg)</li>
  233. <li>Homebrew/Linuxbrew (brew::pcre2/libpcre2-8)</li>
  234. <li>Pacman on archlinux/msys2 (pacman::libcurl)</li>
  235. <li>Apt on ubuntu/debian (apt::zlib1g-dev)</li>
  236. <li>Clib (clib::<a href="mailto:clibs/[email protected]">clibs/[email protected]</a>)</li>
  237. <li>Dub (dub::log 0.4.3)</li>
  238. <li>Portage on Gentoo/Linux (portage::libhandy)</li>
  239. <li>Nimble for nimlang (nimble::zip >1.3)</li>
  240. <li>Cargo for rust (cargo::base64 0.13.0)</li>
  241. </ul>
  242. <h3 id="">包管理特性</h3>
  243. <ul>
  244. <li>官方仓库提供近 500+ 常用包,真正做到全平台一键下载集成编译</li>
  245. <li>全平台包支持,支持交叉编译的依赖包集成</li>
  246. <li>支持包虚拟环境管理和加载,<code>xrepo env shell</code></li>
  247. <li>Windows 云端预编译包加速</li>
  248. <li>支持自建包仓库,私有仓库部署</li>
  249. <li>第三方包仓库支持,提供更加丰富的包源,例如:vcpkg, conan, conda 等等</li>
  250. <li>支持自动拉取使用云端工具链</li>
  251. <li>支持包依赖锁定</li>
  252. </ul>
  253. <h2 id="">支持平台</h2>
  254. <ul>
  255. <li>Windows (x86, x64)</li>
  256. <li>macOS (i386, x86_64, arm64)</li>
  257. <li>Linux (i386, x86_64, cross-toolchains ..)</li>
  258. <li>*BSD (i386, x86_64)</li>
  259. <li>Android (x86, x86_64, armeabi, armeabi-v7a, arm64-v8a)</li>
  260. <li>iOS (armv7, armv7s, arm64, i386, x86_64)</li>
  261. <li>WatchOS (armv7k, i386)</li>
  262. <li>AppleTVOS (armv7, arm64, i386, x86_64)</li>
  263. <li>MSYS (i386, x86_64)</li>
  264. <li>MinGW (i386, x86_64, arm, arm64)</li>
  265. <li>Cygwin (i386, x86_64)</li>
  266. <li>Wasm (wasm32)</li>
  267. <li>Cross (cross-toolchains ..)</li>
  268. </ul>
  269. <h2 id="">支持工具链</h2>
  270. <pre><code class="lang-bash">$ xmake show -l toolchains
  271. xcode Xcode IDE
  272. msvc Microsoft Visual C/C++ Compiler
  273. yasm The Yasm Modular Assembler
  274. clang A C language family frontend for LLVM
  275. go Go Programming Language Compiler
  276. dlang D Programming Language Compiler
  277. gfortran GNU Fortran Programming Language Compiler
  278. zig Zig Programming Language Compiler
  279. sdcc Small Device C Compiler
  280. cuda CUDA Toolkit (nvcc, nvc, nvc++, nvfortran)
  281. ndk Android NDK
  282. rust Rust Programming Language Compiler
  283. swift Swift Programming Language Compiler
  284. llvm A collection of modular and reusable compiler and toolchain technologies
  285. cross Common cross compilation toolchain
  286. nasm NASM Assembler
  287. gcc GNU Compiler Collection
  288. mingw Minimalist GNU for Windows
  289. gnu-rm GNU Arm Embedded Toolchain
  290. envs Environment variables toolchain
  291. fasm Flat Assembler
  292. tinycc Tiny C Compiler
  293. emcc A toolchain for compiling to asm.js and WebAssembly
  294. icc Intel C/C++ Compiler
  295. ifort Intel Fortran Compiler
  296. muslcc The musl-based cross-compilation toolchain
  297. fpc Free Pascal Programming Language Compiler
  298. wasi WASI-enabled WebAssembly C/C++ toolchain
  299. nim Nim Programming Language Compiler
  300. circle A new C++20 compiler
  301. armcc ARM Compiler Version 5 of Keil MDK
  302. armclang ARM Compiler Version 6 of Keil MDK
  303. c51 Keil development tools for the 8051 Microcontroller Architecture
  304. </code></pre>
  305. <h2 id="">支持语言</h2>
  306. <ul>
  307. <li>C/C++</li>
  308. <li>Objc/Objc++</li>
  309. <li>Swift</li>
  310. <li>Assembly</li>
  311. <li>Golang</li>
  312. <li>Rust</li>
  313. <li>Dlang</li>
  314. <li>Fortran</li>
  315. <li>Cuda</li>
  316. <li>Zig</li>
  317. <li>Vala</li>
  318. <li>Pascal</li>
  319. <li>Nim</li>
  320. </ul>
  321. <h2 id="">支持特性</h2>
  322. <ul>
  323. <li>语法简单易上手</li>
  324. <li>快速安装,无任何依赖</li>
  325. <li>全平台一键编译</li>
  326. <li>支持交叉编译,智能分析交叉工具链信息</li>
  327. <li>极速,多任务并行编译支持</li>
  328. <li>C++20 Module 支持</li>
  329. <li>支持跨平台的 C/C++ 依赖包快速集成,内置包管理器</li>
  330. <li>多语言混合编译支持</li>
  331. <li>丰富的插件支持,提供各种工程生成器,例如:vs/makefile/cmakelists/compile_commands 生成插件</li>
  332. <li>REPL 交互式执行支持</li>
  333. <li>增量编译支持,头文件依赖自动分析</li>
  334. <li>工具链的快速切换、定制化支持</li>
  335. <li>丰富的扩展模块支持</li>
  336. <li>远程编译支持</li>
  337. <li>分布式编译支持</li>
  338. <li>内置的本地和远程编译缓存支持</li>
  339. </ul>
  340. <h2 id="">工程类型</h2>
  341. <ul>
  342. <li>静态库程序</li>
  343. <li>动态库类型</li>
  344. <li>控制台程序</li>
  345. <li>Cuda 程序</li>
  346. <li>Qt 应用程序</li>
  347. <li>WDK Windows 驱动程序</li>
  348. <li>WinSDK 应用程序</li>
  349. <li>MFC 应用程序</li>
  350. <li>iOS/MacOS 应用程序(支持.metal)</li>
  351. <li>Framework和Bundle程序(iOS/MacOS)</li>
  352. <li>SWIG 模块 (Lua, python, ...)</li>
  353. <li>Luarocks 模块</li>
  354. <li>Protobuf 程序</li>
  355. <li>Lex/yacc 程序</li>
  356. <li>C++20 模块</li>
  357. <li>Linux 内核驱动模块</li>
  358. </ul>
  359. <h2 id="">分布式编译</h2>
  360. <ul>
  361. <li>[x] 跨平台支持</li>
  362. <li>[x] 支持 msvc, clang, gcc 和交叉编译工具链</li>
  363. <li>[x] 支持构建 android, ios, linux, win, macOS 程序</li>
  364. <li>[x] 除了编译工具链,无任何其他依赖</li>
  365. <li>[x] 支持编译服务器负载均衡调度</li>
  366. <li>[x] 支持大文件实时压缩传输 (lz4)</li>
  367. <li>[x] 几乎零配置成本,无需共享文件系统,更加方便和安全</li>
  368. </ul>
  369. <p>更多详情见:<a href="https://github.com/xmake-io/xmake/issues/274">#274</a></p>
  370. <h2 id="">远程编译</h2>
  371. <p>更多详情见:<a href="https://github.com/xmake-io/xmake/issues/622">#622</a></p>
  372. <h2 id="">本地和远程编译缓存</h2>
  373. <p>更多详情见: <a href="https://github.com/xmake-io/xmake/issues/2371">#622</a></p>
  374. <h2 id="">更多例子</h2>
  375. <h4 id="debugrelease">Debug 和 Release模式</h4>
  376. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  377. target("console")
  378. set_kind("binary")
  379. add_files("src/*.c")
  380. if is_mode("debug") then
  381. add_defines("DEBUG")
  382. end
  383. </code></pre>
  384. <h4 id="">自定义脚本</h4>
  385. <pre><code class="lang-lua">target("test")
  386. set_kind("binary")
  387. add_files("src/*.c")
  388. after_build(function (target)
  389. print("hello: %s", target:name())
  390. os.exec("echo %s", target:targetfile())
  391. end)
  392. </code></pre>
  393. <h4 id="">依赖包自动集成</h4>
  394. <p>下载和使用在 <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a> 和第三方包仓库的依赖包:</p>
  395. <pre><code class="lang-lua">add_requires("tbox >1.6.1", "libuv master", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8")
  396. add_requires("conan::openssl/1.1.1g", {alias = "openssl", optional = true, debug = true})
  397. target("test")
  398. set_kind("binary")
  399. add_files("src/*.c")
  400. add_packages("tbox", "libuv", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8", "openssl")
  401. </code></pre>
  402. <p>另外,我们也可以使用 <a href="https://github.com/xmake-io/xrepo">xrepo</a> 命令来快速安装依赖包。</p>
  403. <h4 id="qtquickapp">Qt QuickApp 应用程序</h4>
  404. <pre><code class="lang-lua">target("test")
  405. add_rules("qt.quickapp")
  406. add_files("src/*.cpp")
  407. add_files("src/qml.qrc")
  408. </code></pre>
  409. <h4 id="cuda">Cuda 程序</h4>
  410. <pre><code class="lang-lua">target("test")
  411. set_kind("binary")
  412. add_files("src/*.cu")
  413. add_cugencodes("native")
  414. add_cugencodes("compute_35")
  415. </code></pre>
  416. <h4 id="wdkumdf">WDK/UMDF 驱动程序</h4>
  417. <pre><code class="lang-lua">target("echo")
  418. add_rules("wdk.driver", "wdk.env.umdf")
  419. add_files("driver/*.c")
  420. add_files("driver/*.inx")
  421. add_includedirs("exe")
  422. target("app")
  423. add_rules("wdk.binary", "wdk.env.umdf")
  424. add_files("exe/*.cpp")
  425. </code></pre>
  426. <p>更多WDK驱动程序例子(umdf/kmdf/wdm),见:<a href="https://xmake.io/#/zh-cn/guide/project_examples?id=wdk%e9%a9%b1%e5%8a%a8%e7%a8%8b%e5%ba%8f">WDK工程例子</a></p>
  427. <h4 id="iosmacos">iOS/MacOS 应用程序</h4>
  428. <pre><code class="lang-lua">target("test")
  429. add_rules("xcode.application")
  430. add_files("src/*.m", "src/**.storyboard", "src/*.xcassets")
  431. add_files("src/Info.plist")
  432. </code></pre>
  433. <h4 id="frameworkbundleiosmacos">Framework 和 Bundle 程序(iOS/MacOS)</h4>
  434. <pre><code class="lang-lua">target("test")
  435. add_rules("xcode.framework") -- 或者 xcode.bundle
  436. add_files("src/*.m")
  437. add_files("src/Info.plist")
  438. </code></pre>
  439. <h4 id="openmp">OpenMP 程序</h4>
  440. <pre><code class="lang-lua">add_requires("libomp", {optional = true})
  441. target("loop")
  442. set_kind("binary")
  443. add_files("src/*.cpp")
  444. add_rules("c++.openmp")
  445. add_packages("libomp")
  446. </code></pre>
  447. <h4 id="zig">Zig 程序</h4>
  448. <pre><code class="lang-lua">target("test")
  449. set_kind("binary")
  450. add_files("src/main.zig")
  451. </code></pre>
  452. <h3 id="">自动拉取远程工具链</h3>
  453. <h4 id="llvm">拉取指定版本的 llvm 工具链</h4>
  454. <p>我们使用 llvm-10 中的 clang 来编译项目。</p>
  455. <pre><code class="lang-lua">add_requires("llvm 10.x", {alias = "llvm-10"})
  456. target("test")
  457. set_kind("binary")
  458. add_files("src/*.c)
  459. set_toolchains("llvm@llvm-10")
  460. `
  461. </code></pre>
  462. <h4 id="">拉取交叉编译工具链</h4>
  463. <p>我们也可以拉取指定的交叉编译工具链来编译项目。</p>
  464. <pre><code class="lang-lua">add_requires("muslcc")
  465. target("test")
  466. set_kind("binary")
  467. add_files("src/*.c)
  468. set_toolchains("@muslcc")
  469. </code></pre>
  470. <h4 id="">拉取工具链并且集成对应工具链编译的依赖包</h4>
  471. <p>我们也可以使用指定的muslcc交叉编译工具链去编译和集成所有的依赖包。</p>
  472. <pre><code class="lang-lua">add_requires("muslcc")
  473. add_requires("zlib", "libogg", {system = false})
  474. set_toolchains("@muslcc")
  475. target("test")
  476. set_kind("binary")
  477. add_files("src/*.c")
  478. add_packages("zlib", "libogg")
  479. </code></pre>
  480. <h2 id="">插件</h2>
  481. <h4 id="idemakefilevs2002vs2022">生成IDE工程文件插件(makefile, vs2002 - vs2022, ...)</h4>
  482. <pre><code class="lang-bash">$ xmake project -k vsxmake -m "debug,release" # 新版vs工程生成插件(推荐)
  483. $ xmake project -k vs -m "debug,release"
  484. $ xmake project -k cmake
  485. $ xmake project -k ninja
  486. $ xmake project -k compile_commands
  487. </code></pre>
  488. <h4 id="lua">加载自定义lua脚本插件</h4>
  489. <pre><code class="lang-bash">$ xmake l ./test.lua
  490. $ xmake l -c "print(&#39;hello xmake!&#39;)"
  491. $ xmake l lib.detect.find_tool gcc
  492. $ xmake l
  493. > print("hello xmake!")
  494. > {1, 2, 3}
  495. < {
  496. 1,
  497. 2,
  498. 3
  499. }
  500. </code></pre>
  501. <p>更多内置插件见相关文档:<a href="https://xmake.io/#/zh-cn/plugin/builtin_plugins">内置插件文档</a></p>
  502. <p>其他扩展插件,请到插件仓库进行下载安装: <a href="https://github.com/xmake-io/xmake-plugins">xmake-plugins</a>.</p>
  503. <h2 id="ide">IDE和编辑器插件</h2>
  504. <ul>
  505. <li><a href="https://github.com/xmake-io/xmake-vscode">xmake-vscode</a></li>
  506. </ul>
  507. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-vscode/master/res/problem.gif" width="650px" /></p>
  508. <ul>
  509. <li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
  510. </ul>
  511. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
  512. <ul>
  513. <li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
  514. </ul>
  515. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
  516. <ul>
  517. <li><a href="https://github.com/Mythos-404/xmake.nvim">xmake.nvim</a> (第三方开发, 感谢<a href="https://github.com/Mythos-404">@Mythos_404</a>)</li>
  518. </ul>
  519. <p><img src="https://raw.githubusercontent.com/Mythos-404/xmake.nvim/main/assets/XmakePreview.gif" width="650px" /></p>
  520. <ul>
  521. <li><p><a href="https://github.com/luzhlon/xmake.vim">xmake.vim</a> (third-party, thanks <a href="https://github.com/luzhlon">@luzhlon</a>)</p>
  522. </li>
  523. <li><p><a href="https://github.com/HelloWorld886/xmake-visualstudio">xmake-visualstudio</a> (third-party, thanks <a href="https://github.com/HelloWorld886">@HelloWorld886</a>)</p>
  524. </li>
  525. <li><p><a href="https://github.com/Arthapz/xmake-project-manager">xmake-qtcreator</a> (third-party, thanks <a href="https://github.com/Arthapz">@Arthapz</a>)</p>
  526. </li>
  527. </ul>
  528. <h3 id="xmakegradlejni">XMake Gradle插件 (JNI)</h3>
  529. <p>我们也可以在Gradle中使用<a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>插件来集成编译JNI库</p>
  530. <pre><code>plugins {
  531. id &#39;org.tboox.gradle-xmake-plugin&#39; version &#39;1.1.5&#39;
  532. }
  533. android {
  534. externalNativeBuild {
  535. xmake {
  536. path "jni/xmake.lua"
  537. }
  538. }
  539. }
  540. </code></pre><p>当<code>gradle-xmake-plugin</code>插件被应用生效后,<code>xmakeBuild</code>任务会自动注入到现有的<code>assemble</code>任务中去,自动执行jni库编译和集成。</p>
  541. <pre><code class="lang-console">$ ./gradlew app:assembleDebug
  542. > Task :nativelib:xmakeConfigureForArm64
  543. > Task :nativelib:xmakeBuildForArm64
  544. >> xmake build
  545. [ 50%]: cache compiling.debug nativelib.cc
  546. [ 75%]: linking.debug libnativelib.so
  547. [100%]: build ok!
  548. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/arm64-v8a
  549. > Task :nativelib:xmakeConfigureForArmv7
  550. > Task :nativelib:xmakeBuildForArmv7
  551. >> xmake build
  552. [ 50%]: cache compiling.debug nativelib.cc
  553. [ 75%]: linking.debug libnativelib.so
  554. [100%]: build ok!
  555. >> install artifacts to /Users/ruki/projects/personal/xmake-gradle/nativelib/libs/armeabi-v7a
  556. > Task :nativelib:preBuild
  557. > Task :nativelib:assemble
  558. > Task :app:assembleDebug
  559. </code></pre>
  560. <h2 id="ci">CI 集成</h2>
  561. <h3 id="githubaction">GitHub Action</h3>
  562. <p>我们可以使用 <a href="https://github.com/xmake-io/github-action-setup-xmake">github-action-setup-xmake</a> 在 Github Action 上实现跨平台安装集成 Xmake。</p>
  563. <pre><code>uses: xmake-io/github-action-setup-xmake@v1
  564. with:
  565. xmake-version: latest
  566. </code></pre><h2 id="xmake">谁在使用 Xmake?</h2>
  567. <p>请点击 <a href="https://xmake.io/#/zh-cn/about/who_is_using_xmake">用户列表</a> 查看完整用户使用列表。</p>
  568. <p>如果您在使用 xmake,也欢迎通过 PR 将信息提交至上面的列表,让更多的用户了解有多少用户在使用 xmake,也能让用户更加安心使用 xmake。</p>
  569. <p>我们也会有更多的动力去持续投入,让 xmake 项目和社区更加繁荣。</p>
  570. <h2 id="">联系方式</h2>
  571. <ul>
  572. <li>邮箱:<a href="mailto:[email protected]">[email protected]</a></li>
  573. <li>主页:<a href="https://xmake.io/#/zh-cn/">xmake.io</a></li>
  574. <li>社区<ul>
  575. <li><a href="https://www.reddit.com/r/xmake/">Reddit论坛</a></li>
  576. <li><a href="https://t.me/tbooxorg">Telegram群组</a></li>
  577. <li><a href="https://discord.gg/xmake">Discord聊天室</a></li>
  578. <li>QQ群:343118190, 662147501</li>
  579. </ul>
  580. </li>
  581. <li>源码:<a href="https://github.com/xmake-io/xmake">Github</a>, <a href="https://gitee.com/tboox/xmake">Gitee</a></li>
  582. <li>微信公众号:tboox-os</li>
  583. </ul>
  584. <h2 id="">感谢</h2>
  585. <p>感谢所有对xmake有所<a href="CONTRIBUTING.md">贡献</a>的人:<br><a href="https://github.com/xmake-io/xmake/graphs/contributors"><img src="https://opencollective.com/xmake/contributors.svg?width=890&amp;button=false" /></a></p>
  586. <ul>
  587. <li><a href="https://github.com/TitanSnow">TitanSnow</a>: 提供xmake <a href="https://github.com/TitanSnow/ts-xmake-logo">logo</a> 和安装脚本。</li>
  588. <li><a href="https://github.com/uael">uael</a>: 提供语义版本跨平台c库 <a href="https://github.com/uael/sv">sv</a>。</li>
  589. <li><a href="https://github.com/OpportunityLiu">OpportunityLiu</a>: 改进cuda构建, tests框架和ci。</li>
  590. <li><a href="https://github.com/xq114">xq144</a>: 改进 <code>xrepo env shell</code>,并贡献大量包到 <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a> 仓库。</li>
  591. </ul>
  592. </article>
  593. </body>
  594. </html>