builtin_plugins.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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/#/plugin/builtin_plugins">https://xmake.io/#/plugin/builtin_plugins</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="generateideprojectfiles">Generate IDE Project Files</h2>
  86. <h3 id="generatemakefile">Generate Makefile</h3>
  87. <pre><code class="lang-bash">$ xmake project -k makefile
  88. </code></pre>
  89. <h3 id="generatecmakeliststxt">Generate CMakelists.txt</h3>
  90. <pre><code class="lang-console">$ xmake project -k cmakelists
  91. </code></pre>
  92. <h3 id="generatebuildninja">Generate build.ninja</h3>
  93. <p>!> Only supported in versions above 2.3.1</p>
  94. <pre><code class="lang-console">$ xmake project -k ninja
  95. </code></pre>
  96. <h3 id="generatecompiler_flags">Generate compiler_flags</h3>
  97. <pre><code class="lang-console">$ xmake project -k compiler_flags
  98. </code></pre>
  99. <h3 id="generatecompiler_commands">Generate compiler_commands</h3>
  100. <p>We can export the compilation commands info of all source files and it is JSON compilation database format.</p>
  101. <pre><code class="lang-console">$ xmake project -k compile_commands
  102. </code></pre>
  103. <p>The the content of the output file:</p>
  104. <pre><code>[
  105. { "directory": "/home/user/llvm/build",
  106. "command": "/usr/bin/clang++ -Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o file.o file.cc",
  107. "file": "file.cc" },
  108. ...
  109. ]
  110. </code></pre><p>Please see <a href="#https://clang.llvm.org/docs/JSONCompilationDatabase.html">JSONCompilationDatabase</a> if need known more info about <code>compile_commands</code>.</p>
  111. <h3 id="generatexcodeprojectfile">Generate Xcode project file</h3>
  112. <p>At present, we have no time to implement the generation of xcode projects by ourselves, but it does not mean that it is not supported, because xmake supports the generation of cmakelists.txt files, and cmake supports the generation of xcode project files. Before the official implementation,<br>We can also support it in disguise through cmake, xmake will automatically call cmake internally to transfer the generated results, there is no difference in use for users, just make sure that cmake has been installed:</p>
  113. <pre><code class="lang-console">$ xmake project -k xcode
  114. </code></pre>
  115. <p>!> After we have time, we will re-implement each more complete xcode output plugin by ourselves, and welcome everyone to contribute.</p>
  116. <h3 id="generatevisualstudioproject">Generate VisualStudio Project</h3>
  117. <h4 id="compilewithxmakeintegration">Compile with xmake integration</h4>
  118. <p>v2.2.8 or later, provides a new version of the vs project generation plugin extension, which is very different from the previous plugin processing mode for generating vs. The previously generated vs project is the compilation of all files and then transferred to vs. To handle compilation.</p>
  119. <p>But this mode, there is no way to support the rules of xmake. Because xmake&#39;s rules use a lot of custom scripts like <code>on_build</code>, they can&#39;t be expanded, so projects like qt, wdk can&#39;t support exporting to vs. compile.</p>
  120. <p>Therefore, in order to solve this problem, the new version of the vs. build plugin performs the compile operation by directly calling the xmake command under vs, and also supports intellisense and definition jumps, as well as breakpoint debugging.</p>
  121. <p>The specific use is similar to the old version:</p>
  122. <pre><code class="lang-console">$ xmake project -k [vsxmake2010|vsxmake2013|vsxmake2015|..] -m "debug;release"
  123. </code></pre>
  124. <p>If no version is specified, xmake will automatically detect the current version of vs to generate:</p>
  125. <pre><code class="lang-bash">$ xmake project -k vsxmake -m "debug,release"
  126. </code></pre>
  127. <p><img src="/assets/img/manual/qt_vs.png" alt=""></p>
  128. <p>In addition, the vsxmake plugin will additionally generate a custom configuration property page for easy and flexible modification and appending some xmake compilation configuration in the vs., and even switch to other cross toolchains in the configuration to achieve the vs. vs. Cross-compilation of other platforms such as android, linux.</p>
  129. <p><img src="/assets/img/manual/property_page_vsxmake.png" alt=""></p>
  130. <p>The v2.5.1 version provides a <code>add_rules("plugin.vsxmake.autoupdate")</code> rule. If this rule is applied, the production vs project will be checked for changes in xmake.lua and the code file list after the compilation is completed. If there are changes , The vs project will be updated automatically.</p>
  131. <pre><code class="lang-lua">add_rules("plugin.vsxmake.autoupdate")
  132. target("test")
  133. set_kind("binary")
  134. add_files("src/*.c")
  135. </code></pre>
  136. <p>In addition, we can group each target through the <code>set_group</code> interface, so that the generated vs project can be grouped according to the specified structure. For more details, please see: <a href="https://github.com/xmake-io/xmake/issues/1026">issue 1026</a></p>
  137. <h4 id="usingvsbuiltincompilationmechanism">Using vs built-in compilation mechanism</h4>
  138. <p>!> It is recommended to use the new version of the vs. plugin provided after v2.2.8 mentioned above. The support is more complete. The generation method here does not support the rules of xmake, and the generation of projects such as qt.</p>
  139. <pre><code class="lang-bash">$ xmake project -k [vs2008|vs2013|vs2015|..]
  140. </code></pre>
  141. <p>v2.1.2 or later, it supports multi-mode and multi-architecture generation for vs201x project.</p>
  142. <p>For example:</p>
  143. <pre><code class="lang-bash">$ xmake project -k vs2017 -m "debug,release"
  144. </code></pre>
  145. <p>It will generate four project configurations: <code>debug|x86</code>, <code>debug|x64</code>, <code>release|x86</code>, <code>release|x64</code>.</p>
  146. <p>Or you can set modes to <code>xmake.lua</code>:</p>
  147. <pre><code class="lang-lua">set_modes("debug", "release")
  148. </code></pre>
  149. <p>Then, we run the following command:</p>
  150. <pre><code class="lang-bash">$ xmake project -k vs2017
  151. </code></pre>
  152. <p>The effect is same.</p>
  153. <p>In addition, we can group each target through the <code>set_group</code> interface, so that the generated vs project can be grouped according to the specified structure. For more details, please see: <a href="https://github.com/xmake-io/xmake/issues/1026">issue 1026</a></p>
  154. <h2 id="runthecustomluascript">Run the Custom Lua Script</h2>
  155. <h3 id="runthegivenscript">Run the given script</h3>
  156. <p>Write a simple lua script:</p>
  157. <pre><code class="lang-lua">function main()
  158. print("hello xmake!")
  159. end
  160. </code></pre>
  161. <p>Run this lua script.</p>
  162. <pre><code class="lang-bash">$ xmake lua /tmp/test.lua
  163. </code></pre>
  164. <p><p class="tip"><br> You can also use <code>import</code> api to write a more advance lua script.<br></p>
  165. </p>
  166. <h3 id="runthebuiltinscript">Run the builtin script</h3>
  167. <p>You can run <code>xmake lua -l</code> to list all builtin script name, for example:</p>
  168. <pre><code class="lang-bash">$ xmake lua -l
  169. scripts:
  170. cat
  171. cp
  172. echo
  173. versioninfo
  174. ...
  175. </code></pre>
  176. <p>And run them:</p>
  177. <pre><code class="lang-bash">$ xmake lua cat ~/file.txt
  178. $ xmake lua echo "hello xmake"
  179. $ xmake lua cp /tmp/file /tmp/file2
  180. $ xmake lua versioninfo
  181. </code></pre>
  182. <h3 id="runinteractivecommandsrepl">Run interactive commands (REPL)</h3>
  183. <p>Enter interactive mode:</p>
  184. <pre><code class="lang-bash">$ xmake lua
  185. > 1 + 2
  186. 3
  187. > a = 1
  188. > a
  189. 1
  190. > for _, v in pairs({1, 2, 3}) do
  191. >> print(v)
  192. >> end
  193. 1
  194. 2
  195. 3
  196. </code></pre>
  197. <p>And we can <code>import</code> modules:</p>
  198. <pre><code class="lang-bash">> task = import("core.project.task")
  199. > task.run("hello")
  200. hello xmake!
  201. </code></pre>
  202. <p>If you want to cancel multiline input, please input character <code>q</code>, for example:</p>
  203. <pre><code class="lang-bash">> for _, v in ipairs({1, 2}) do
  204. >> print(v)
  205. >> q <-- cancel multiline and clear previous input
  206. > 1 + 2
  207. 3
  208. </code></pre>
  209. <h2 id="showspecifiedinformationandlist">Show specified information and list</h2>
  210. <h3 id="showbasicinformationaboutxmakeitselfandthecurrentproject">Show basic information about xmake itself and the current project</h3>
  211. <pre><code class="lang-bash">$ xmake show
  212. The information of xmake:
  213. version: 2.3.3+202006011009
  214. host: macosx/x86_64
  215. programdir: /Users/ruki/.local/share/xmake
  216. programfile: /Users/ruki/.local/bin/xmake
  217. globaldir: /Users/ruki/.xmake
  218. tmpdir: /var/folders/32/w9cz0y_14hs19lkbs6v6_fm80000gn/T/.xmake501/200603
  219. workingdir: /Users/ruki/projects/personal/tbox
  220. packagedir: /Users/ruki/.xmake/packages
  221. packagedir(cache): /Users/ruki/.xmake/cache/packages/2006
  222. The information of project: tbox
  223. version: 1.6.5
  224. plat: macosx
  225. arch: x86_64
  226. mode: release
  227. buildir: build
  228. configdir: /Users/ruki/projects/personal/tbox/.xmake/macosx/x86_64
  229. projectdir: /Users/ruki/projects/personal/tbox
  230. projectfile: /Users/ruki/projects/personal/tbox/xmake.lua
  231. </code></pre>
  232. <h3 id="showtoolchainslist">Show toolchains list</h3>
  233. <pre><code class="lang-bash">$ xmake show -l toolchains
  234. xcode Xcode IDE
  235. vs VisualStudio IDE
  236. yasm The Yasm Modular Assembler
  237. clang A C language family frontend for LLVM
  238. go Go Programming Language Compiler
  239. dlang D Programming Language Compiler
  240. sdcc Small Device C Compiler
  241. cuda CUDA Toolkit
  242. ndk Android NDK
  243. rust Rust Programming Language Compiler
  244. llvm A collection of modular and reusable compiler and toolchain technologies
  245. cross Common cross compilation toolchain
  246. nasm NASM Assembler
  247. gcc GNU Compiler Collection
  248. mingw Minimalist GNU for Windows
  249. gnu-rm GNU Arm Embedded Toolchain
  250. envs Environment variables toolchain
  251. fasm Flat Assembler
  252. </code></pre>
  253. <h3 id="showtheinformationofthegiventarget">Show the information of the given target</h3>
  254. <p>We can use it to quickly trace the location of some specific configurations.</p>
  255. <pre><code class="lang-bash">$ xmake show -t tbox
  256. The information of target(tbox):
  257. at: /Users/ruki/projects/personal/tbox/src/tbox/xmake.lua
  258. kind: static
  259. targetfile: build/macosx/x86_64/release/libtbox.a
  260. rules:
  261. -> mode.release -> ./xmake.lua:26
  262. -> mode.debug -> ./xmake.lua:26
  263. -> mode.profile -> ./xmake.lua:26
  264. -> mode.coverage -> ./xmake.lua:26
  265. -> utils.install.cmake_importfiles -> ./src/tbox/xmake.lua:15
  266. -> utils.install.pkgconfig_importfiles -> ./src/tbox/xmake.lua:16
  267. options:
  268. -> info -> ./src/tbox/xmake.lua:50
  269. -> float -> ./src/tbox/xmake.lua:50
  270. -> wchar -> ./src/tbox/xmake.lua:50
  271. -> exception -> ./src/tbox/xmake.lua:50
  272. -> force-utf8 -> ./src/tbox/xmake.lua:50
  273. -> deprecated -> ./src/tbox/xmake.lua:50
  274. -> xml -> ./src/tbox/xmake.lua:53
  275. -> zip -> ./src/tbox/xmake.lua:53
  276. -> hash -> ./src/tbox/xmake.lua:53
  277. -> regex -> ./src/tbox/xmake.lua:53
  278. -> coroutine -> ./src/tbox/xmake.lua:53
  279. -> object -> ./src/tbox/xmake.lua:53
  280. -> charset -> ./src/tbox/xmake.lua:53
  281. -> database -> ./src/tbox/xmake.lua:53
  282. packages:
  283. -> mbedtls -> ./src/tbox/xmake.lua:43
  284. -> polarssl -> ./src/tbox/xmake.lua:43
  285. -> openssl -> ./src/tbox/xmake.lua:43
  286. -> pcre2 -> ./src/tbox/xmake.lua:43
  287. -> pcre -> ./src/tbox/xmake.lua:43
  288. -> zlib -> ./src/tbox/xmake.lua:43
  289. -> mysql -> ./src/tbox/xmake.lua:43
  290. -> sqlite3 -> ./src/tbox/xmake.lua:43
  291. links:
  292. -> pthread -> option(__keyword_thread_local) -> @programdir/includes/check_csnippets.lua:100
  293. syslinks:
  294. -> pthread -> ./xmake.lua:71
  295. -> dl -> ./xmake.lua:71
  296. -> m -> ./xmake.lua:71
  297. -> c -> ./xmake.lua:71
  298. defines:
  299. -> __tb_small__ -> ./xmake.lua:42
  300. -> __tb_prefix__="tbox" -> ./src/tbox/xmake.lua:19
  301. -> _GNU_SOURCE=1 -> option(__systemv_semget) -> @programdir/includes/check_cfuncs.lua:104
  302. cxflags:
  303. -> -Wno-error=deprecated-declarations -> ./xmake.lua:22
  304. -> -fno-strict-aliasing -> ./xmake.lua:22
  305. -> -Wno-error=expansion-to-defined -> ./xmake.lua:22
  306. -> -fno-stack-protector -> ./xmake.lua:51
  307. frameworks:
  308. -> CoreFoundation -> ./src/tbox/xmake.lua:38
  309. -> CoreServices -> ./src/tbox/xmake.lua:38
  310. mxflags:
  311. -> -Wno-error=deprecated-declarations -> ./xmake.lua:23
  312. -> -fno-strict-aliasing -> ./xmake.lua:23
  313. -> -Wno-error=expansion-to-defined -> ./xmake.lua:23
  314. includedirs:
  315. -> src -> ./src/tbox/xmake.lua:26
  316. -> build/macosx/x86_64/release -> ./src/tbox/xmake.lua:27
  317. headerfiles:
  318. -> src/(tbox/**.h)|**/impl/**.h -> ./src/tbox/xmake.lua:30
  319. -> src/(tbox/prefix/**/prefix.S) -> ./src/tbox/xmake.lua:31
  320. -> src/(tbox/math/impl/*.h) -> ./src/tbox/xmake.lua:32
  321. -> src/(tbox/utils/impl/*.h) -> ./src/tbox/xmake.lua:33
  322. -> build/macosx/x86_64/release/tbox.config.h -> ./src/tbox/xmake.lua:34
  323. files:
  324. -> src/tbox/*.c -> ./src/tbox/xmake.lua:56
  325. -> src/tbox/hash/bkdr.c -> ./src/tbox/xmake.lua:57
  326. -> src/tbox/hash/fnv32.c -> ./src/tbox/xmake.lua:57
  327. -> src/tbox/hash/adler32.c -> ./src/tbox/xmake.lua:57
  328. -> src/tbox/math/**.c -> ./src/tbox/xmake.lua:58
  329. -> src/tbox/libc/**.c|string/impl/**.c -> ./src/tbox/xmake.lua:59
  330. -> src/tbox/utils/*.c|option.c -> ./src/tbox/xmake.lua:60
  331. -> src/tbox/prefix/**.c -> ./src/tbox/xmake.lua:61
  332. -> src/tbox/memory/**.c -> ./src/tbox/xmake.lua:62
  333. -> src/tbox/string/**.c -> ./src/tbox/xmake.lua:63
  334. -> src/tbox/stream/**.c|**/charset.c|**/zip.c -> ./src/tbox/xmake.lua:64
  335. -> src/tbox/network/**.c|impl/ssl/*.c -> ./src/tbox/xmake.lua:65
  336. -> src/tbox/algorithm/**.c -> ./src/tbox/xmake.lua:66
  337. -> src/tbox/container/**.c|element/obj.c -> ./src/tbox/xmake.lua:67
  338. -> src/tbox/libm/impl/libm.c -> ./src/tbox/xmake.lua:68
  339. -> src/tbox/libm/idivi8.c -> ./src/tbox/xmake.lua:73
  340. -> src/tbox/libm/ilog2i.c -> ./src/tbox/xmake.lua:70
  341. -> src/tbox/libm/isqrti.c -> ./src/tbox/xmake.lua:71
  342. -> src/tbox/libm/isqrti64.c -> ./src/tbox/xmake.lua:72
  343. -> src/tbox/platform/*.c|context.c|exception.c -> ./src/tbox/xmake.lua:74
  344. -> src/tbox/platform/impl/*.c|charset.c|poller_fwatcher.c -> ./src/tbox/xmake.lua:74
  345. -> src/tbox/libm/*.c -> ./src/tbox/xmake.lua:77
  346. compiler (cc): /usr/bin/xcrun -sdk macosx clang
  347. -> -Qunused-arguments -target x86_64-apple-macos12.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
  348. linker (ar): /usr/bin/xcrun -sdk macosx ar
  349. -> -cr
  350. compflags (cc):
  351. -> -Qunused-arguments -target x86_64-apple-macos12.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -Wall -Werror -Oz -std=c99 -Isrc -Ibuild/macosx/x86_64/release -D__tb_small__ -D__tb_prefix__=\"tbox\" -D_GNU_SOURCE=1 -framework CoreFoundation -framework CoreServices -Wno-error=deprecated-declarations -fno-strict-aliasing -Wno-error=expansion-to-defined -fno-stack-protector
  352. linkflags (ar):
  353. -> -cr
  354. </code></pre>
  355. <h3 id="showbuiltincompilationmodeslist">Show builtin compilation modes list</h3>
  356. <pre><code class="lang-bash">$ xmake show -l buildmodes
  357. </code></pre>
  358. <h3 id="showbuiltincompilationruleslist">Show builtin compilation rules list</h3>
  359. <pre><code class="lang-bash">$ xmake show -l rules
  360. </code></pre>
  361. <h3 id="showotherinformation">Show other information</h3>
  362. <p>It is still being perfected, see: <a href="https://github.com/xmake-io/xmake/issues/798">https://github.com/xmake-io/xmake/issues/798</a></p>
  363. <p>Or run</p>
  364. <pre><code class="lang-bash">$ xmake show --help
  365. </code></pre>
  366. <h2 id="watchingforfileupdates">Watching for file updates</h2>
  367. <p>New in v2.7.1 is the <code>xmake watch</code> plugin command, which can automatically monitor project files for updates and then trigger an automatic build or run some custom commands.</p>
  368. <p>This is often used for personal development to enable fast, real-time incremental builds without the need to manually execute the build command each time, improving development efficiency.</p>
  369. <h3 id="buildautomaticallyafteraprojectupdate">Build automatically after a project update</h3>
  370. <p>The default behaviour is to monitor the entire project root directory and any file changes will trigger an incremental build of the project.</p>
  371. <pre><code class="lang-bash">$ xmake watch
  372. watching /private/tmp/test/src/** .
  373. watching /private/tmp/test/* ...
  374. /private/tmp/test/src/main.cpp modified
  375. [ 25%]: cache compiling.release src/main.cpp
  376. [ 50%]: linking.release test
  377. [ 100%]: build ok!
  378. ```&#39;&#39;
  379. ### Monitoring a specific directory
  380. We can also monitor specific code directories to narrow down the scope of monitoring and improve performance.
  381. ```bash
  382. $ xmake watch -d src
  383. $ xmake watch -d "src;tests/*"
  384. </code></pre>
  385. <p>The above command will recursively watch all subdirectories. If you want to keep a tight watch on the files in the current directory and not do recursive monitoring, you can use the following command.</p>
  386. <pre><code class="lang-bash">$ xmake watch -p src
  387. $ xmake watch -p "src;tests/*"
  388. </code></pre>
  389. <h3 id="watchandrunthespecifiedcommand">Watch and run the specified command</h3>
  390. <p>If you want to run the build automatically even after the automatic build, we can use a custom command set.</p>
  391. <pre><code class="lang-bash">$ xmake watch -c "xmake; xmake run"
  392. </code></pre>
  393. <p>The above list of commands is passed as a string, which is not flexible enough for complex command arguments that need to be escaped rather tediously, so we can use the following for arbitrary commands.</p>
  394. <pre><code class="lang-bash">$ xmake watch -- echo hello xmake!
  395. $ xmake watch -- xmake run --help
  396. </code></pre>
  397. <h3 id="watchingandrunningthetargetprogram">Watching and running the target program</h3>
  398. <p>Although we can automate the running of the target program with custom commands, we also provide more convenient arguments to achieve this behaviour.</p>
  399. <pre><code class="lang-bash">$ xmake watch -r
  400. $ xmake watch --run
  401. [100%]: build ok!
  402. hello world!
  403. </code></pre>
  404. <h3 id="watchingandrunningluascripts">Watching and running lua scripts</h3>
  405. <p>We can also watch for file updates and then run the specified lua script for more flexible and complex command customisation.</p>
  406. <pre><code class="lang-bash">$ xmake watch -s /tmp/test.lua
  407. </code></pre>
  408. <p>We can also get a list of all updated file paths and events in the script again.</p>
  409. <pre><code class="lang-lua">function main(events)
  410. -- TODO handle events
  411. end
  412. </code></pre>
  413. <h2 id="checkprojectconfigurationsandcodes">Check project configurations and codes</h2>
  414. <h3 id="checkprojectconfiguration">Check project configuration</h3>
  415. <h4 id="checkallapivaluesinxmakeluabydefault">Check all api values in xmake.lua by default</h4>
  416. <pre><code class="lang-lua">set_lanuages("c91") -- typo
  417. </code></pre>
  418. <pre><code class="lang-console">$ xmake check
  419. ./xmake.lua:15: warning: unknown language value &#39;c91&#39;, it may be &#39;c90&#39;
  420. 0 notes, 1 warnings, 0 errors
  421. </code></pre>
  422. <p>we can also run a given group</p>
  423. <pre><code class="lang-console">$ xmake check api
  424. $ xmake check api.target
  425. </code></pre>
  426. <h4 id="verboseoutput">Verbose output</h4>
  427. <pre><code class="lang-console">$ xmake check -v
  428. ./xmake.lua:15: warning: unknown language value &#39;cxx91&#39;, it may be &#39;cxx98&#39;
  429. ./src/tbox/xmake.lua:43: note: unknown package value &#39;mbedtls&#39;
  430. ./src/tbox/xmake.lua:43: note: unknown package value &#39;polarssl&#39;
  431. ./src/tbox/xmake.lua:43: note: unknown package value &#39;openssl&#39;
  432. ./src/tbox/xmake.lua:43: note: unknown package value &#39;pcre2&#39;
  433. ./src/tbox/xmake.lua:43: note: unknown package value &#39;pcre&#39;
  434. ./src/tbox/xmake.lua:43: note: unknown package value &#39;zlib&#39;
  435. ./src/tbox/xmake.lua:43: note: unknown package value &#39;mysql&#39;
  436. ./src/tbox/xmake.lua:43: note: unknown package value &#39;sqlite3&#39;
  437. 8 notes, 1 warnings, 0 errors
  438. </code></pre>
  439. <h4 id="checkthegivenapi">Check the given api</h4>
  440. <pre><code class="lang-console">$ xmake check api.target.languages
  441. ./xmake.lua:15: warning: unknown language value &#39;cxx91&#39;, it may be &#39;cxx98&#39;
  442. 0 notes, 1 warnings, 0 errors
  443. </code></pre>
  444. <h4 id="checkcompilerflags">Check compiler flags</h4>
  445. <pre><code class="lang-console">$ xmake check
  446. ./xmake.lua:10: warning: clang: unknown c compiler flag &#39;-Ox&#39;
  447. 0 notes, 1 warnings, 0 errors
  448. </code></pre>
  449. <h4 id="checkincludedirs">Check includedirs</h4>
  450. <pre><code class="lang-console">$ xmake check
  451. ./xmake.lua:11: warning: includedir &#39;xxx&#39; not found
  452. 0 notes, 1 warnings, 0 errors
  453. </code></pre>
  454. <h3 id="checkprojectcodeclangtidy">Check project code (clang-tidy)</h3>
  455. <h4 id="listclangtidychecks">List clang-tidy checks</h4>
  456. <pre><code class="lang-console">$ xmake check clang.tidy --list
  457. Enabled checks:
  458. clang-analyzer-apiModeling.StdCLibraryFunctions
  459. clang-analyzer-apiModeling.TrustNonnull
  460. clang-analyzer-apiModeling.google.GTest
  461. clang-analyzer-apiModeling.llvm.CastValue
  462. clang-analyzer-apiModeling.llvm.ReturnValue
  463. ...
  464. </code></pre>
  465. <h4 id="checksourcecodeintargets">Check source code in targets</h4>
  466. <pre><code class="lang-console">$ xmake check clang.tidy
  467. 1 error generated.
  468. Error while processing /private/tmp/test2/src/main.cpp.
  469. /tmp/test2/src/main.cpp:1:10: error: &#39;iostr&#39; file not found [clang-diagnostic-error]
  470. #include <iostr>
  471. ^~~~~~~
  472. Found compiler error(s).
  473. error: execv(/usr/local/opt/llvm/bin/clang-tidy -p compile_commands.json /private/tmp/test2/src
  474. /main.cpp) failed(1)
  475. </code></pre>
  476. <h4 id="checkcodewiththegivenchecks">Check code with the given checks</h4>
  477. <pre><code class="lang-console">$ xmake check clang.tidy --checks="*"
  478. 6 warnings and 1 error generated.
  479. Error while processing /private/tmp/test2/src/main.cpp.
  480. /tmp/test2/src/main.cpp:1:10: error: &#39;iostr&#39; file not found [clang-diagnostic-error]
  481. #include <iostr>
  482. ^~~~~~~
  483. /tmp/test2/src/main.cpp:3:1: warning: do not use namespace using-directives; use using-declarat
  484. ions instead [google-build-using-namespace]
  485. using namespace std;
  486. ^
  487. /tmp/test2/src/main.cpp:3:17: warning: declaration must be declared within the &#39;__llvm_libc&#39; na
  488. mespace [llvmlibc-implementation-in-namespace]
  489. using namespace std;
  490. ^
  491. /tmp/test2/src/main.cpp:5:5: warning: declaration must be declared within the &#39;__llvm_libc&#39; nam
  492. espace [llvmlibc-implementation-in-namespace]
  493. int main(int argc, char **argv) {
  494. ^
  495. /tmp/test2/src/main.cpp:5:5: warning: use a trailing return type for this function [modernize-u
  496. se-trailing-return-type]
  497. int main(int argc, char **argv) {
  498. ~~~ ^
  499. auto -> int
  500. /tmp/test2/src/main.cpp:5:14: warning: parameter &#39;argc&#39; is unused [misc-unused-parameters]
  501. int main(int argc, char **argv) {
  502. ^~~~
  503. /*argc*/
  504. /tmp/test2/src/main.cpp:5:27: warning: parameter &#39;argv&#39; is unused [misc-unused-parameters]
  505. int main(int argc, char **argv) {
  506. ^~~~
  507. /*argv*/
  508. Found compiler error(s).
  509. error: execv(/usr/local/opt/llvm/bin/clang-tidy --checks=* -p compile_commands.json /private/tm
  510. p/test2/src/main.cpp) failed(1)
  511. </code></pre>
  512. <h4 id="checkcodewiththegiventargetname">Check code with the given target name</h4>
  513. <pre><code class="lang-console">$ xmake check clang.tidy [targetname]
  514. </code></pre>
  515. <h4 id="checkcodewiththegivensourcefiles">Check code with the given source files</h4>
  516. <pre><code class="lang-console">$ xmake check clang.tidy -f src/main.c
  517. $ xmake check clang.tidy -f &#39;src/*.c:src/**.cpp&#39;
  518. </code></pre>
  519. <h4 id="setthegivenclangtidyconfigfile">Set the given .clang-tidy config file</h4>
  520. <pre><code class="lang-console">$ xmake check clang.tidy --configfile=/tmp/.clang-tidy
  521. </code></pre>
  522. <h4 id="createanewclangtidyconfigfile">Create a new .clang-tidy config file</h4>
  523. <pre><code class="lang-console">$ xmake check clang.tidy --checks="*" --create
  524. $ cat .clang-tidy
  525. ---
  526. Checks: &#39;clang-diagnostic-*,clang-analyzer-*,*&#39;
  527. WarningsAsErrors: &#39;&#39;
  528. HeaderFilterRegex: &#39;&#39;
  529. AnalyzeTemporaryDtors: false
  530. FormatStyle: none
  531. User: ruki
  532. CheckOptions:
  533. - key: readability-suspicious-call-argument.PrefixSimilarAbove
  534. value: &#39;30&#39;
  535. - key: cppcoreguidelines-no-malloc.Reallocations
  536. value: &#39;::realloc&#39;
  537. </code></pre>
  538. <h4 id="automaticallyfixingerrorcodes">Automatically fixing error codes</h4>
  539. <p>We can use the following command parameters to automatically fix problematic code detected by clang tidy.</p>
  540. <pre><code class="lang-console">$ xmake check clang.tidy --fix
  541. $ xmake check clang.tidy --fix_errors
  542. $ xmake check clang.tidy --fix_notes
  543. </code></pre>
  544. <h2 id="macrosrecordingandplayback">Macros Recording and Playback</h2>
  545. <h3 id="introduction">Introduction</h3>
  546. <p>We can record and playback our xmake commands and save as macro quickly using this plugin.</p>
  547. <p>And we can run this macro to simplify our jobs repeatably.</p>
  548. <h3 id="recordcommands">Record Commands</h3>
  549. <pre><code class="lang-bash"># begin to record commands
  550. $ xmake macro --begin
  551. # run some xmake commands
  552. $ xmake f -p android --ndk=/xxx/ndk -a arm64-v8a
  553. $ xmake p
  554. $ xmake f -p mingw --sdk=/mingwsdk
  555. $ xmake p
  556. $ xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin
  557. $ xmake p
  558. $ xmake f -p iphoneos -a armv7
  559. $ xmake p
  560. $ xmake f -p iphoneos -a arm64
  561. $ xmake p
  562. $ xmake f -p iphoneos -a armv7s
  563. $ xmake p
  564. $ xmake f -p iphoneos -a i386
  565. $ xmake p
  566. $ xmake f -p iphoneos -a x86_64
  567. $ xmake p
  568. # stop to record and save as anonymous macro
  569. xmake macro --end
  570. </code></pre>
  571. <h3 id="playbackmacro">Playback Macro</h3>
  572. <pre><code class="lang-bash"># playback the previous anonymous macro
  573. $ xmake macro .
  574. </code></pre>
  575. <h3 id="namedmacro">Named Macro</h3>
  576. <pre><code class="lang-bash">$ xmake macro --begin
  577. $ ...
  578. $ xmake macro --end macroname
  579. $ xmake macro macroname
  580. </code></pre>
  581. <h3 id="importandexportmacro">Import and Export Macro</h3>
  582. <p>Import the given macro file or directory.</p>
  583. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua macroname
  584. $ xmake macro --import=/xxx/macrodir
  585. </code></pre>
  586. <p>Export the given macro to file or directory.</p>
  587. <pre><code class="lang-bash">$ xmake macro --export=/xxx/macro.lua macroname
  588. $ xmake macro --export=/xxx/macrodir
  589. </code></pre>
  590. <h3 id="listandshowmacro">List and Show Macro</h3>
  591. <p>List all builtin macros.</p>
  592. <pre><code class="lang-bash">$ xmake macro --list
  593. </code></pre>
  594. <p>Show the given macro script content.</p>
  595. <pre><code class="lang-bash">$ xmake macro --show macroname
  596. </code></pre>
  597. <h3 id="custommacroscript">Custom Macro Script</h3>
  598. <p>Create and write a <code>macro.lua</code> script first.</p>
  599. <pre><code class="lang-lua">function main()
  600. os.exec("xmake f -p android --ndk=/xxx/ndk -a arm64-v8a")
  601. os.exec("xmake p")
  602. os.exec("xmake f -p mingw --sdk=/mingwsdk")
  603. os.exec("xmake p")
  604. os.exec("xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin")
  605. os.exec("xmake p")
  606. os.exec("xmake f -p iphoneos -a armv7")
  607. os.exec("xmake p")
  608. os.exec("xmake f -p iphoneos -a arm64")
  609. os.exec("xmake p")
  610. os.exec("xmake f -p iphoneos -a armv7s")
  611. os.exec("xmake p")
  612. os.exec("xmake f -p iphoneos -a i386")
  613. os.exec("xmake p")
  614. os.exec("xmake f -p iphoneos -a x86_64")
  615. os.exec("xmake p")
  616. end
  617. </code></pre>
  618. <p>Import this macro script to xmake.</p>
  619. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua [macroname]
  620. </code></pre>
  621. <p>Playback this macro script.</p>
  622. <pre><code class="lang-bash">$ xmake macro [.|macroname]
  623. </code></pre>
  624. <h3 id="builtinmacros">Builtin Macros</h3>
  625. <p>XMake supports some builtins macros to simplify our jobs.</p>
  626. <p>For example, we use <code>package</code> macro to package all architectures of the iphoneos platform just for once.</p>
  627. <pre><code class="lang-bash">$ xmake macro package -p iphoneos
  628. </code></pre>
  629. <h3 id="advancemacroscript">Advance Macro Script</h3>
  630. <p>Let&#39;s see the <code>package</code> macro script:</p>
  631. <pre><code class="lang-lua">-- imports
  632. import("core.base.option")
  633. import("core.project.config")
  634. import("core.project.project")
  635. import("core.platform.platform")
  636. -- the options
  637. local options =
  638. {
  639. {&#39;p&#39;, "plat", "kv", os.host(), "Set the platform." }
  640. , {&#39;f&#39;, "config", "kv", nil, "Pass the config arguments to \"xmake config\" .." }
  641. , {&#39;o&#39;, "outputdir", "kv", nil, "Set the output directory of the package." }
  642. }
  643. -- package all
  644. --
  645. -- .e.g
  646. -- xmake m package
  647. -- xmake m package -f "-m debug"
  648. -- xmake m package -p linux
  649. -- xmake m package -p iphoneos -f "-m debug --xxx ..." -o /tmp/xxx
  650. -- xmake m package -f \"--mode=debug\"
  651. --
  652. function main(argv)
  653. -- parse arguments
  654. local args = option.parse(argv, options, "Package all architectures for the given the platform."
  655. , ""
  656. , "Usage: xmake macro package [options]")
  657. -- package all archs
  658. local plat = args.plat
  659. for _, arch in ipairs(platform.archs(plat)) do
  660. -- config it
  661. os.exec("xmake f -p %s -a %s %s -c %s", plat, arch, args.config or "", (option.get("verbose") and "-v" or ""))
  662. -- package it
  663. if args.outputdir then
  664. os.exec("xmake p -o %s %s", args.outputdir, (option.get("verbose") and "-v" or ""))
  665. else
  666. os.exec("xmake p %s", (option.get("verbose") and "-v" or ""))
  667. end
  668. end
  669. -- package universal for iphoneos, watchos ...
  670. if plat == "iphoneos" or plat == "watchos" then
  671. -- load configure
  672. config.load()
  673. -- load project
  674. project.load()
  675. -- enter the project directory
  676. os.cd(project.directory())
  677. -- the outputdir directory
  678. local outputdir = args.outputdir or config.get("buildir")
  679. -- package all targets
  680. for _, target in pairs(project.targets()) do
  681. -- get all modes
  682. local modedirs = os.match(format("%s/%s.pkg/lib/*", outputdir, target:name()), true)
  683. for _, modedir in ipairs(modedirs) do
  684. -- get mode
  685. local mode = path.basename(modedir)
  686. -- make lipo arguments
  687. local lipoargs = nil
  688. for _, arch in ipairs(platform.archs(plat)) do
  689. local archfile = format("%s/%s.pkg/lib/%s/%s/%s/%s", outputdir, target:name(), mode, plat, arch, path.filename(target:targetfile()))
  690. if os.isfile(archfile) then
  691. lipoargs = format("%s -arch %s %s", lipoargs or "", arch, archfile)
  692. end
  693. end
  694. if lipoargs then
  695. -- make full lipo arguments
  696. lipoargs = format("-create %s -output %s/%s.pkg/lib/%s/%s/universal/%s", lipoargs, outputdir, target:name(), mode, plat, path.filename(target:targetfile()))
  697. -- make universal directory
  698. os.mkdir(format("%s/%s.pkg/lib/%s/%s/universal", outputdir, target:name(), mode, plat))
  699. -- package all archs
  700. os.execv("xmake", {"l", "lipo", lipoargs})
  701. end
  702. end
  703. end
  704. end
  705. end
  706. </code></pre>
  707. <p><p class="tip"><br> If you want to known more options, please run: <code>xmake macro --help</code><br></p>
  708. </p>
  709. <h2 id="generatedoxygendocument">Generate Doxygen Document</h2>
  710. <p>Please ensure that the doxygen tool has been installed first.</p>
  711. <pre><code class="lang-bash">$ xmake doxygen
  712. </code></pre>
  713. </article>
  714. </body>
  715. </html>