builtin_plugins.html 32 KB

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