builtin_plugins.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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="//cdn.jsdelivr.net/npm/[email protected]/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="generate-ide-project-files">Generate IDE Project Files</h2>
  84. <h3 id="generate-makefile">Generate Makefile</h3>
  85. <pre><code class="lang-bash">$ xmake project -k makefile
  86. </code></pre>
  87. <h3 id="generate-cmakelists-txt">Generate CMakelists.txt</h3>
  88. <pre><code class="lang-console">$ xmake project -k cmakelists
  89. </code></pre>
  90. <h3 id="generate-build-ninja">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="generate-compiler_flags">Generate compiler_flags</h3>
  95. <pre><code class="lang-console">$ xmake project -k compiler_flags
  96. </code></pre>
  97. <h3 id="generate-compiler_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="generate-visualstudio-project">Generate VisualStudio Project</h3>
  110. <h4 id="compile-with-xmake-integration">Compile with xmake integration</h4>
  111. <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>
  112. <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>
  113. <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>
  114. <p>The specific use is similar to the old version:</p>
  115. <pre><code class="lang-console">$ xmake project -k [vsxmake2010|vsxmake2013|vsxmake2015|..] -m "debug;release"
  116. </code></pre>
  117. <p>If no version is specified, xmake will automatically detect the current version of vs to generate:</p>
  118. <pre><code class="lang-bash">$ xmake project -k vsxmake -m "debug;release"
  119. </code></pre>
  120. <p><img src="/assets/img/manual/qt_vs.png" alt=""></p>
  121. <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>
  122. <p><img src="/assets/img/manual/property_page_vsxmake.png" alt=""></p>
  123. <h4 id="using-vs-built-in-compilation-mechanism">Using vs built-in compilation mechanism</h4>
  124. <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>
  125. <pre><code class="lang-bash">$ xmake project -k [vs2008|vs2013|vs2015|..]
  126. </code></pre>
  127. <p>v2.1.2 or later, it supports multi-mode and multi-architecture generation for vs201x project.</p>
  128. <p>For example:</p>
  129. <pre><code class="lang-bash">$ xmake project -k vs2017 -m "debug,release"
  130. </code></pre>
  131. <p>It will generate four project configurations: <code>debug|x86</code>, <code>debug|x64</code>, <code>release|x86</code>, <code>release|x64</code>.</p>
  132. <p>Or you can set modes to <code>xmake.lua</code>:</p>
  133. <pre><code class="lang-lua">set_modes("debug", "release")
  134. </code></pre>
  135. <p>Then, we run the following command:</p>
  136. <pre><code class="lang-bash">$ xmake project -k vs2017
  137. </code></pre>
  138. <p>The effect is same.</p>
  139. <h2 id="run-the-custom-lua-script">Run the Custom Lua Script</h2>
  140. <h3 id="run-the-given-script">Run the given script</h3>
  141. <p>Write a simple lua script:</p>
  142. <pre><code class="lang-lua">function main()
  143. print("hello xmake!")
  144. end
  145. </code></pre>
  146. <p>Run this lua script.</p>
  147. <pre><code class="lang-bash">$ xmake lua /tmp/test.lua
  148. </code></pre>
  149. <p><p class="tip"><br> You can also use <code>import</code> api to write a more advance lua script.<br></p>
  150. </p>
  151. <h3 id="run-the-builtin-script">Run the builtin script</h3>
  152. <p>You can run <code>xmake lua -l</code> to list all builtin script name, for example:</p>
  153. <pre><code class="lang-bash">$ xmake lua -l
  154. scripts:
  155. cat
  156. cp
  157. echo
  158. versioninfo
  159. ...
  160. </code></pre>
  161. <p>And run them:</p>
  162. <pre><code class="lang-bash">$ xmake lua cat ~/file.txt
  163. $ xmake lua echo "hello xmake"
  164. $ xmake lua cp /tmp/file /tmp/file2
  165. $ xmake lua versioninfo
  166. </code></pre>
  167. <h3 id="run-interactive-commands-repl-">Run interactive commands (REPL)</h3>
  168. <p>Enter interactive mode:</p>
  169. <pre><code class="lang-bash">$ xmake lua
  170. > 1 + 2
  171. 3
  172. > a = 1
  173. > a
  174. 1
  175. > for _, v in pairs({1, 2, 3}) do
  176. >> print(v)
  177. >> end
  178. 1
  179. 2
  180. 3
  181. </code></pre>
  182. <p>And we can <code>import</code> modules:</p>
  183. <pre><code class="lang-bash">> task = import("core.project.task")
  184. > task.run("hello")
  185. hello xmake!
  186. </code></pre>
  187. <p>If you want to cancel multiline input, please input character <code>q</code>, for example:</p>
  188. <pre><code class="lang-bash">> for _, v in ipairs({1, 2}) do
  189. >> print(v)
  190. >> q <-- cancel multiline and clear previous input
  191. > 1 + 2
  192. 3
  193. </code></pre>
  194. <h2 id="show-specified-information-and-list">Show specified information and list</h2>
  195. <h3 id="show-basic-information-about-xmake-itself-and-the-current-project">Show basic information about xmake itself and the current project</h3>
  196. <pre><code class="lang-bash">$ xmake show
  197. The information of xmake:
  198. version: 2.3.3+202006011009
  199. host: macosx/x86_64
  200. programdir: /Users/ruki/.local/share/xmake
  201. programfile: /Users/ruki/.local/bin/xmake
  202. globaldir: /Users/ruki/.xmake
  203. tmpdir: /var/folders/32/w9cz0y_14hs19lkbs6v6_fm80000gn/T/.xmake501/200603
  204. workingdir: /Users/ruki/projects/personal/tbox
  205. packagedir: /Users/ruki/.xmake/packages
  206. packagedir(cache): /Users/ruki/.xmake/cache/packages/2006
  207. The information of project: tbox
  208. version: 1.6.5
  209. plat: macosx
  210. arch: x86_64
  211. mode: release
  212. buildir: build
  213. configdir: /Users/ruki/projects/personal/tbox/.xmake/macosx/x86_64
  214. projectdir: /Users/ruki/projects/personal/tbox
  215. projectfile: /Users/ruki/projects/personal/tbox/xmake.lua
  216. </code></pre>
  217. <h3 id="show-toolchains-list">Show toolchains list</h3>
  218. <pre><code class="lang-bash">$ xmake show -l toolchains
  219. xcode Xcode IDE
  220. vs VisualStudio IDE
  221. yasm The Yasm Modular Assembler
  222. clang A C language family frontend for LLVM
  223. go Go Programming Language Compiler
  224. dlang D Programming Language Compiler
  225. sdcc Small Device C Compiler
  226. cuda CUDA Toolkit
  227. ndk Android NDK
  228. rust Rust Programming Language Compiler
  229. llvm A collection of modular and reusable compiler and toolchain technologies
  230. cross Common cross compilation toolchain
  231. nasm NASM Assembler
  232. gcc GNU Compiler Collection
  233. mingw Minimalist GNU for Windows
  234. gnu-rm GNU Arm Embedded Toolchain
  235. envs Environment variables toolchain
  236. fasm Flat Assembler
  237. </code></pre>
  238. <h3 id="show-the-information-of-the-given-target">Show the information of the given target</h3>
  239. <pre><code class="lang-bash">$ xmake show --target=tbox
  240. The information of target(tbox):
  241. kind: static
  242. targetfile: build/macosx/x86_64/release/libtbox.a
  243. rules: mode.release, mode.debug, mode.profile, mode.coverage
  244. options: info, float, wchar, exception, force-utf8, deprecated, xml, zip, hash, regex, coroutine, object, charset, database
  245. packages: mbedtls, polarssl, openssl, pcre2, pcre, zlib, mysql, sqlite3
  246. links: pthread
  247. syslinks: pthread, dl, m, c
  248. cxflags: -Wno-error=deprecated-declarations, -fno-strict-aliasing, -Wno-error=expansion-to-defined, -fno-stack-protector
  249. defines: __tb_small__, __tb_prefix__="tbox"
  250. mxflags: -Wno-error=deprecated-declarations, -fno-strict-aliasing, -Wno-error=expansion-to-defined
  251. headerfiles: src/(tbox/**.h)|**/impl/**.h, src/(tbox/prefix/**/prefix.S), src/(tbox/math/impl/*.h), src/(tbox/utils/impl/*.h), build/macosx/x86_64/release/tbox.config.h
  252. includedirs: src, build/macosx/x86_64/release
  253. at: /Users/ruki/projects/personal/tbox/src/tbox/xmake.lua
  254. sourcebatch(cc): with rule(c.build)
  255. -> src/tbox/string/static_string.c
  256. -> build/.objs/tbox/macosx/x86_64/release/src/tbox/string/static_string.c.o
  257. -> build/.deps/tbox/macosx/x86_64/release/src/tbox/string/static_string.c.o.d
  258. -> src/tbox/platform/sched.c
  259. -> build/.objs/tbox/macosx/x86_64/release/src/tbox/platform/sched.c.o
  260. -> build/.deps/tbox/macosx/x86_64/release/src/tbox/platform/sched.c.o.d
  261. -> src/tbox/stream/stream.c
  262. -> build/.objs/tbox/macosx/x86_64/release/src/tbox/stream/stream.c.o
  263. -> build/.deps/tbox/macosx/x86_64/release/src/tbox/stream/stream.c.o.d
  264. -> src/tbox/utils/base32.c
  265. -> build/.objs/tbox/macosx/x86_64/release/src/tbox/utils/base32.c.o
  266. -> build/.deps/tbox/macosx/x86_64/release/src/tbox/utils/base32.c.o.d
  267. </code></pre>
  268. <h3 id="show-builtin-compilation-modes-list">Show builtin compilation modes list</h3>
  269. <pre><code class="lang-bash">$ xmake show -l modes
  270. </code></pre>
  271. <h3 id="show-builtin-compilation-rules-list">Show builtin compilation rules list</h3>
  272. <pre><code class="lang-bash">$ xmake show -l rules
  273. </code></pre>
  274. <h3 id="show-other-information">Show other information</h3>
  275. <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>
  276. <p>Or run</p>
  277. <pre><code class="lang-bash">$ xmake show --help
  278. </code></pre>
  279. <h2 id="macros-recording-and-playback">Macros Recording and Playback</h2>
  280. <h3 id="introduction">Introduction</h3>
  281. <p>We can record and playback our xmake commands and save as macro quickly using this plugin.</p>
  282. <p>And we can run this macro to simplify our jobs repeatably.</p>
  283. <h3 id="record-commands">Record Commands</h3>
  284. <pre><code class="lang-bash"># begin to record commands
  285. $ xmake macro --begin
  286. # run some xmake commands
  287. $ xmake f -p android --ndk=/xxx/ndk -a arm64-v8a
  288. $ xmake p
  289. $ xmake f -p mingw --sdk=/mingwsdk
  290. $ xmake p
  291. $ xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin
  292. $ xmake p
  293. $ xmake f -p iphoneos -a armv7
  294. $ xmake p
  295. $ xmake f -p iphoneos -a arm64
  296. $ xmake p
  297. $ xmake f -p iphoneos -a armv7s
  298. $ xmake p
  299. $ xmake f -p iphoneos -a i386
  300. $ xmake p
  301. $ xmake f -p iphoneos -a x86_64
  302. $ xmake p
  303. # stop to record and save as anonymous macro
  304. xmake macro --end
  305. </code></pre>
  306. <h3 id="playback-macro">Playback Macro</h3>
  307. <pre><code class="lang-bash"># playback the previous anonymous macro
  308. $ xmake macro .
  309. </code></pre>
  310. <h3 id="named-macro">Named Macro</h3>
  311. <pre><code class="lang-bash">$ xmake macro --begin
  312. $ ...
  313. $ xmake macro --end macroname
  314. $ xmake macro macroname
  315. </code></pre>
  316. <h3 id="import-and-export-macro">Import and Export Macro</h3>
  317. <p>Import the given macro file or directory.</p>
  318. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua macroname
  319. $ xmake macro --import=/xxx/macrodir
  320. </code></pre>
  321. <p>Export the given macro to file or directory.</p>
  322. <pre><code class="lang-bash">$ xmake macro --export=/xxx/macro.lua macroname
  323. $ xmake macro --export=/xxx/macrodir
  324. </code></pre>
  325. <h3 id="list-and-show-macro">List and Show Macro</h3>
  326. <p>List all builtin macros.</p>
  327. <pre><code class="lang-bash">$ xmake macro --list
  328. </code></pre>
  329. <p>Show the given macro script content.</p>
  330. <pre><code class="lang-bash">$ xmake macro --show macroname
  331. </code></pre>
  332. <h3 id="custom-macro-script">Custom Macro Script</h3>
  333. <p>Create and write a <code>macro.lua</code> script first.</p>
  334. <pre><code class="lang-lua">function main()
  335. os.exec("xmake f -p android --ndk=/xxx/ndk -a arm64-v8a")
  336. os.exec("xmake p")
  337. os.exec("xmake f -p mingw --sdk=/mingwsdk")
  338. os.exec("xmake p")
  339. os.exec("xmake f -p linux --sdk=/toolsdk --toolchains=/xxxx/bin")
  340. os.exec("xmake p")
  341. os.exec("xmake f -p iphoneos -a armv7")
  342. os.exec("xmake p")
  343. os.exec("xmake f -p iphoneos -a arm64")
  344. os.exec("xmake p")
  345. os.exec("xmake f -p iphoneos -a armv7s")
  346. os.exec("xmake p")
  347. os.exec("xmake f -p iphoneos -a i386")
  348. os.exec("xmake p")
  349. os.exec("xmake f -p iphoneos -a x86_64")
  350. os.exec("xmake p")
  351. end
  352. </code></pre>
  353. <p>Import this macro script to xmake.</p>
  354. <pre><code class="lang-bash">$ xmake macro --import=/xxx/macro.lua [macroname]
  355. </code></pre>
  356. <p>Playback this macro script.</p>
  357. <pre><code class="lang-bash">$ xmake macro [.|macroname]
  358. </code></pre>
  359. <h3 id="builtin-macros">Builtin Macros</h3>
  360. <p>XMake supports some builtins macros to simplify our jobs.</p>
  361. <p>For example, we use <code>package</code> macro to package all architectures of the iphoneos platform just for once.</p>
  362. <pre><code class="lang-bash">$ xmake macro package -p iphoneos
  363. </code></pre>
  364. <h3 id="advance-macro-script">Advance Macro Script</h3>
  365. <p>Let&#39;s see the <code>package</code> macro script:</p>
  366. <pre><code class="lang-lua">-- imports
  367. import("core.base.option")
  368. import("core.project.config")
  369. import("core.project.project")
  370. import("core.platform.platform")
  371. -- the options
  372. local options =
  373. {
  374. {&#39;p&#39;, "plat", "kv", os.host(), "Set the platform." }
  375. , {&#39;f&#39;, "config", "kv", nil, "Pass the config arguments to \"xmake config\" .." }
  376. , {&#39;o&#39;, "outputdir", "kv", nil, "Set the output directory of the package." }
  377. }
  378. -- package all
  379. --
  380. -- .e.g
  381. -- xmake m package
  382. -- xmake m package -f "-m debug"
  383. -- xmake m package -p linux
  384. -- xmake m package -p iphoneos -f "-m debug --xxx ..." -o /tmp/xxx
  385. -- xmake m package -f \"--mode=debug\"
  386. --
  387. function main(argv)
  388. -- parse arguments
  389. local args = option.parse(argv, options, "Package all architectures for the given the platform."
  390. , ""
  391. , "Usage: xmake macro package [options]")
  392. -- package all archs
  393. local plat = args.plat
  394. for _, arch in ipairs(platform.archs(plat)) do
  395. -- config it
  396. os.exec("xmake f -p %s -a %s %s -c %s", plat, arch, args.config or "", (option.get("verbose") and "-v" or ""))
  397. -- package it
  398. if args.outputdir then
  399. os.exec("xmake p -o %s %s", args.outputdir, (option.get("verbose") and "-v" or ""))
  400. else
  401. os.exec("xmake p %s", (option.get("verbose") and "-v" or ""))
  402. end
  403. end
  404. -- package universal for iphoneos, watchos ...
  405. if plat == "iphoneos" or plat == "watchos" then
  406. -- load configure
  407. config.load()
  408. -- load project
  409. project.load()
  410. -- enter the project directory
  411. os.cd(project.directory())
  412. -- the outputdir directory
  413. local outputdir = args.outputdir or config.get("buildir")
  414. -- package all targets
  415. for _, target in pairs(project.targets()) do
  416. -- get all modes
  417. local modedirs = os.match(format("%s/%s.pkg/lib/*", outputdir, target:name()), true)
  418. for _, modedir in ipairs(modedirs) do
  419. -- get mode
  420. local mode = path.basename(modedir)
  421. -- make lipo arguments
  422. local lipoargs = nil
  423. for _, arch in ipairs(platform.archs(plat)) do
  424. local archfile = format("%s/%s.pkg/lib/%s/%s/%s/%s", outputdir, target:name(), mode, plat, arch, path.filename(target:targetfile()))
  425. if os.isfile(archfile) then
  426. lipoargs = format("%s -arch %s %s", lipoargs or "", arch, archfile)
  427. end
  428. end
  429. if lipoargs then
  430. -- make full lipo arguments
  431. lipoargs = format("-create %s -output %s/%s.pkg/lib/%s/%s/universal/%s", lipoargs, outputdir, target:name(), mode, plat, path.filename(target:targetfile()))
  432. -- make universal directory
  433. os.mkdir(format("%s/%s.pkg/lib/%s/%s/universal", outputdir, target:name(), mode, plat))
  434. -- package all archs
  435. os.execv("xmake", {"l", "lipo", lipoargs})
  436. end
  437. end
  438. end
  439. end
  440. end
  441. </code></pre>
  442. <p><p class="tip"><br> If you want to known more options, please run: <code>xmake macro --help</code><br></p>
  443. </p>
  444. <h2 id="generate-doxygen-document">Generate Doxygen Document</h2>
  445. <p>Please ensure that the doxygen tool has been installed first.</p>
  446. <pre><code class="lang-bash">$ xmake doxygen
  447. </code></pre>
  448. </article>
  449. </body>
  450. </html>