getting_started.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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/getting_started">https://xmake.io/#/zh-cn/getting_started</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>🙏 xmake项目属于个人开源项目,它的发展需要您的帮助,如果您愿意支持xmake项目的开发,欢迎为其捐赠,支持它的发展。</p>
  87. <p>👉 <a href="https://xmake.io/#/zh-cn/about/sponsor">捐助页面</a></p>
  88. <p>也可以通过购买周边纪念物品的方式,来支持我们的项目发展。</p>
  89. <p>👉 <a href="https://xmake.io/#/zh-cn/about/peripheral_items">周边物品</a></p>
  90. <h2 id="">技术支持</h2>
  91. <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>
  92. <ul>
  93. <li>[x] 更高优先级的 Issues 问题处理</li>
  94. <li>[x] 一对一技术咨询服务</li>
  95. <li>[x] Review xmake.lua 并提供改进建议</li>
  96. </ul>
  97. <h2 id="new">课程(New)</h2>
  98. <p><a href="https://www.lanqiao.cn/courses/2764">Xmake 带你轻松构建 C/C++ 项目</a> 是我们在实验楼上新推出的一门 xmake 入门和进阶课程(收费),以边学边做实验的方式快速学习 xmake 的使用。</p>
  99. <p>通过此处优惠码购买可享 9 折优惠:<code>NYFbmf3X</code></p>
  100. <h2 id="xmake">谁在使用 Xmake?</h2>
  101. <p>如果您在使用 xmake,欢迎点击编辑 <a href="https://github.com/xmake-io/xmake-docs/blob/master/zh-cn/about/who_is_using_xmake.md">此页面</a> 通过 PR 将信息提交至下面的列表,让更多的用户了解有多少用户在使用 xmake,也能让用户更加安心使用 xmake。</p>
  102. <p>我们也会有更多的动力去持续投入,让 xmake 项目和社区更加繁荣。</p>
  103. <h2 id="">安装</h2>
  104. <h4 id="curl">使用curl</h4>
  105. <pre><code class="lang-bash">curl -fsSL https://xmake.io/shget.text | bash
  106. </code></pre>
  107. <h4 id="wget">使用wget</h4>
  108. <pre><code class="lang-bash">wget https://xmake.io/shget.text -O - | bash
  109. </code></pre>
  110. <h4 id="powershell">使用powershell</h4>
  111. <pre><code class="lang-powershell">Invoke-Expression (Invoke-Webrequest &#39;https://xmake.io/psget.text&#39; -UseBasicParsing).Content
  112. </code></pre>
  113. <h4 id="">其他安装方式</h4>
  114. <p>如果不想使用脚本安装,也可以点击查看 <a href="https://xmake.io/#/zh-cn/guide/installation">安装文档</a>,了解其他安装方法。</p>
  115. <h2 id="">简单的工程描述</h2>
  116. <pre><code class="lang-lua">target("hello")
  117. set_kind("binary")
  118. add_files("src/*.cpp")
  119. </code></pre>
  120. <h2 id="">包依赖描述</h2>
  121. <pre><code class="lang-lua">add_requires("tbox 1.6.*", "zlib", "libpng ~1.6")
  122. </code></pre>
  123. <p>官方的xmake包管理仓库: <a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a></p>
  124. <h2 id="">构建工程</h2>
  125. <pre><code class="lang-bash">$ xmake
  126. </code></pre>
  127. <h2 id="">运行目标</h2>
  128. <pre><code class="lang-bash">$ xmake run console
  129. </code></pre>
  130. <h2 id="">调试程序</h2>
  131. <pre><code class="lang-bash">$ xmake run -d console
  132. </code></pre>
  133. <h2 id="">配置平台</h2>
  134. <pre><code class="lang-bash">$ xmake f -p [windows|linux|macosx|android|iphoneos ..] -a [x86|arm64 ..] -m [debug|release]
  135. $ xmake
  136. </code></pre>
  137. <h2 id="">图形化菜单配置</h2>
  138. <pre><code class="lang-bash">$ xmake f --menu
  139. </code></pre>
  140. <p><img src="https://xmake.io/assets/img/index/menuconf.png" width="650px" /></p>
  141. <h2 id="ninja">跟ninja一样快的构建速度</h2>
  142. <p>测试工程: <a href="https://github.com/xmake-io/xmake/tree/master/core">xmake-core</a></p>
  143. <h3 id="">多任务并行编译测试</h3>
  144. <table>
  145. <thead>
  146. <tr>
  147. <th>构建系统</th>
  148. <th>Termux (8core/-j12)</th>
  149. <th>构建系统</th>
  150. <th>MacOS (8core/-j12)</th>
  151. </tr>
  152. </thead>
  153. <tbody>
  154. <tr>
  155. <td>xmake</td>
  156. <td>24.890s</td>
  157. <td>xmake</td>
  158. <td>12.264s</td>
  159. </tr>
  160. <tr>
  161. <td>ninja</td>
  162. <td>25.682s</td>
  163. <td>ninja</td>
  164. <td>11.327s</td>
  165. </tr>
  166. <tr>
  167. <td>cmake(gen+make)</td>
  168. <td>5.416s+28.473s</td>
  169. <td>cmake(gen+make)</td>
  170. <td>1.203s+14.030s</td>
  171. </tr>
  172. <tr>
  173. <td>cmake(gen+ninja)</td>
  174. <td>4.458s+24.842s</td>
  175. <td>cmake(gen+ninja)</td>
  176. <td>0.988s+11.644s</td>
  177. </tr>
  178. </tbody>
  179. </table>
  180. <h3 id="">单任务编译测试</h3>
  181. <table>
  182. <thead>
  183. <tr>
  184. <th>构建系统</th>
  185. <th>Termux (-j1)</th>
  186. <th>构建系统</th>
  187. <th>MacOS (-j1)</th>
  188. </tr>
  189. </thead>
  190. <tbody>
  191. <tr>
  192. <td>xmake</td>
  193. <td>1m57.707s</td>
  194. <td>xmake</td>
  195. <td>39.937s</td>
  196. </tr>
  197. <tr>
  198. <td>ninja</td>
  199. <td>1m52.845s</td>
  200. <td>ninja</td>
  201. <td>38.995s</td>
  202. </tr>
  203. <tr>
  204. <td>cmake(gen+make)</td>
  205. <td>5.416s+2m10.539s</td>
  206. <td>cmake(gen+make)</td>
  207. <td>1.203s+41.737s</td>
  208. </tr>
  209. <tr>
  210. <td>cmake(gen+ninja)</td>
  211. <td>4.458s+1m54.868s</td>
  212. <td>cmake(gen+ninja)</td>
  213. <td>0.988s+38.022s</td>
  214. </tr>
  215. </tbody>
  216. </table>
  217. <h2 id="">包依赖管理</h2>
  218. <h3 id="">下载和编译</h3>
  219. <p><img src="https://xmake.io/assets/img/index/package_manage.png" width="650px" /></p>
  220. <h3 id="">架构和流程</h3>
  221. <p><img src="https://xmake.io/assets/img/index/package_arch.png" width="650px" /></p>
  222. <h2 id="">支持平台</h2>
  223. <ul>
  224. <li>Windows (x86, x64)</li>
  225. <li>macOS (i386, x86_64)</li>
  226. <li>Linux (i386, x86_64, cross-toolchains ..)</li>
  227. <li>*BSD (i386, x86_64)</li>
  228. <li>Android (x86, x86_64, armeabi, armeabi-v7a, arm64-v8a)</li>
  229. <li>iOS (armv7, armv7s, arm64, i386, x86_64)</li>
  230. <li>WatchOS (armv7k, i386)</li>
  231. <li>MSYS (i386, x86_64)</li>
  232. <li>MinGW (i386, x86_64)</li>
  233. <li>Cygwin (i386, x86_64)</li>
  234. <li>SDCC (stm8, mcs51, ..)</li>
  235. <li>Cross (cross-toolchains ..)</li>
  236. </ul>
  237. <h2 id="">支持语言</h2>
  238. <ul>
  239. <li>C/C++</li>
  240. <li>Objc/Objc++</li>
  241. <li>Swift</li>
  242. <li>Assembly</li>
  243. <li>Golang</li>
  244. <li>Rust</li>
  245. <li>Dlang</li>
  246. <li>Cuda</li>
  247. </ul>
  248. <h2 id="">工程类型</h2>
  249. <ul>
  250. <li>静态库程序</li>
  251. <li>动态库类型</li>
  252. <li>控制台程序</li>
  253. <li>Cuda程序</li>
  254. <li>Qt应用程序</li>
  255. <li>WDK驱动程序</li>
  256. <li>WinSDK应用程序</li>
  257. <li>MFC应用程序</li>
  258. </ul>
  259. <h2 id="">更多例子</h2>
  260. <p>Debug和Release模式:</p>
  261. <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
  262. target("console")
  263. set_kind("binary")
  264. add_files("src/*.c")
  265. if is_mode("debug") then
  266. add_defines("DEBUG")
  267. end
  268. </code></pre>
  269. <p>自定义脚本:</p>
  270. <pre><code class="lang-lua">target("test")
  271. set_kind("binary")
  272. add_files("src/*.c")
  273. after_build(function (target)
  274. print("hello: %s", target:name())
  275. os.exec("echo %s", target:targetfile())
  276. end)
  277. </code></pre>
  278. <p>下载和使用在<a href="https://github.com/xmake-io/xmake-repo">xmake-repo</a>和第三方包仓库的依赖包:</p>
  279. <pre><code class="lang-lua">add_requires("tbox >1.6.1", "libuv master", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8")
  280. add_requires("conan::openssl/1.1.1g", {alias = "openssl", optional = true, debug = true})
  281. target("test")
  282. set_kind("binary")
  283. add_files("src/*.c")
  284. add_packages("tbox", "libuv", "vcpkg::ffmpeg", "brew::pcre2/libpcre2-8", "openssl")
  285. </code></pre>
  286. <p>Qt QuickApp应用程序:</p>
  287. <pre><code class="lang-lua">target("test")
  288. add_rules("qt.quickapp")
  289. add_files("src/*.cpp")
  290. add_files("src/qml.qrc")
  291. </code></pre>
  292. <p>Cuda程序:</p>
  293. <pre><code class="lang-lua">target("test")
  294. set_kind("binary")
  295. add_files("src/*.cu")
  296. add_cugencodes("native")
  297. add_cugencodes("compute_30")
  298. </code></pre>
  299. <p>WDK/UMDF驱动程序:</p>
  300. <pre><code class="lang-lua">target("echo")
  301. add_rules("wdk.driver", "wdk.env.umdf")
  302. add_files("driver/*.c")
  303. add_files("driver/*.inx")
  304. add_includedirs("exe")
  305. target("app")
  306. add_rules("wdk.binary", "wdk.env.umdf")
  307. add_files("exe/*.cpp")
  308. </code></pre>
  309. <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>
  310. <h2 id="">插件</h2>
  311. <h4 id="idemakefilevs2002vs2019">生成IDE工程文件插件(makefile, vs2002 - vs2019, ...)</h4>
  312. <pre><code class="lang-bash">$ xmake project -k vsxmake -m "debug;release" # 新版vs工程生成插件(推荐)
  313. $ xmake project -k vs -m "debug;release"
  314. $ xmake project -k cmake
  315. $ xmake project -k ninja
  316. $ xmake project -k compile_commands
  317. </code></pre>
  318. <h4 id="lua">加载自定义lua脚本插件</h4>
  319. <pre><code class="lang-bash">$ xmake l ./test.lua
  320. $ xmake l -c "print(&#39;hello xmake!&#39;)"
  321. $ xmake l lib.detect.find_tool gcc
  322. $ xmake l
  323. > print("hello xmake!")
  324. > {1, 2, 3}
  325. < {
  326. 1,
  327. 2,
  328. 3
  329. }
  330. </code></pre>
  331. <p>更多内置插件见相关文档:<a href="https://xmake.io/#/zh-cn/plugin/builtin_plugins">内置插件文档</a></p>
  332. <p>其他扩展插件,请到插件仓库进行下载安装: <a href="https://github.com/xmake-io/xmake-plugins">xmake-plugins</a>.</p>
  333. <h2 id="ide">IDE和编辑器插件</h2>
  334. <ul>
  335. <li><a href="https://github.com/xmake-io/xmake-vscode">xmake-vscode</a></li>
  336. </ul>
  337. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-vscode/master/res/problem.gif" width="650px" /></p>
  338. <ul>
  339. <li><a href="https://github.com/xmake-io/xmake-sublime">xmake-sublime</a></li>
  340. </ul>
  341. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-sublime/master/res/problem.gif" width="650px" /></p>
  342. <ul>
  343. <li><a href="https://github.com/xmake-io/xmake-idea">xmake-idea</a></li>
  344. </ul>
  345. <p><img src="https://raw.githubusercontent.com/xmake-io/xmake-idea/master/res/problem.gif" width="650px" /></p>
  346. <ul>
  347. <li><a href="https://github.com/Mythos-404/xmake.nvim">xmake.nvim</a> (第三方开发, 感谢<a href="https://github.com/Mythos-404">@Mythos_404</a>)</li>
  348. </ul>
  349. <p><img src="https://raw.githubusercontent.com/Mythos-404/xmake.nvim/main/assets/XmakePreview.gif" width="650px" /></p>
  350. <ul>
  351. <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>
  352. </li>
  353. <li><p><a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a>: 一个无缝整合xmake的gradle插件</p>
  354. </li>
  355. </ul>
  356. <h2 id="">项目例子</h2>
  357. <p>一些使用xmake的项目:</p>
  358. <ul>
  359. <li><a href="https://github.com/tboox/tbox">tbox</a></li>
  360. <li><a href="https://github.com/tboox/gbox">gbox</a></li>
  361. <li><a href="https://github.com/tboox/vm86">vm86</a></li>
  362. <li><a href="https://github.com/xmake-io/awesome-xmake">更多</a></li>
  363. </ul>
  364. <h2 id="">演示视频</h2>
  365. <p><a href="https://asciinema.org/a/133693"><br><img src="https://asciinema.org/a/133693.png" width="650px" /><br></a></p>
  366. <h2 id="">联系方式</h2>
  367. <ul>
  368. <li>邮箱:<a href="mailto:[email protected]">[email protected]</a></li>
  369. <li>主页:<a href="https://tboox.org/cn">tboox.org</a></li>
  370. <li>社区:<a href="https://www.reddit.com/r/xmake/">Reddit论坛</a></li>
  371. <li>源码:<a href="https://github.com/xmake-io/xmake">Github</a>, <a href="https://gitee.com/tboox/xmake">Gitee</a></li>
  372. <li>QQ群:343118190(满), 662147501</li>
  373. <li>微信公众号:tboox-os</li>
  374. </ul>
  375. <h2 id="">感谢</h2>
  376. <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>
  377. <ul>
  378. <li><a href="https://github.com/TitanSnow">TitanSnow</a>: 提供xmake <a href="https://github.com/TitanSnow/ts-xmake-logo">logo</a> 和安装脚本</li>
  379. <li><a href="https://github.com/uael">uael</a>: 提供语义版本跨平台c库 <a href="https://github.com/uael/sv">sv</a></li>
  380. <li><a href="https://github.com/OpportunityLiu">OpportunityLiu</a>: 改进cuda构建, tests框架和ci</li>
  381. </ul>
  382. </article>
  383. </body>
  384. </html>