| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>xmake</title>
- <link rel="icon" href="/assets/img/favicon.ico">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <meta name="description" content="Description">
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
- <style>
- .markdown-body {
- box-sizing: border-box;
- min-width: 200px;
- max-width: 980px;
- margin: 0 auto;
- padding: 45px;
- }
- @media (max-width: 767px) {
- .markdown-body {
- padding: 15px;
- }
- }
- </style>
- </head>
- <body>
- <article class="markdown-body">
- <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/zh-cn/manual/custom_rule">https://xmake.io/#/zh-cn/manual/custom_rule</a>
- <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>
- </br>
- <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
- <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
- <style>
- #carbonads {
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
- Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
- }
- #carbonads {
- display: flex;
- max-width: 330px;
- background-color: hsl(0, 0%, 98%);
- box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
- }
- #carbonads a {
- color: inherit;
- text-decoration: none;
- }
- #carbonads a:hover {
- color: inherit;
- }
- #carbonads span {
- position: relative;
- display: block;
- overflow: hidden;
- }
- #carbonads .carbon-wrap {
- display: flex;
- }
- .carbon-img {
- display: block;
- margin: 0;
- line-height: 1;
- }
- .carbon-img img {
- display: block;
- }
- .carbon-text {
- font-size: 13px;
- padding: 10px;
- line-height: 1.5;
- text-align: left;
- }
- .carbon-poweredby {
- display: block;
- padding: 8px 10px;
- 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);
- text-align: center;
- text-transform: uppercase;
- letter-spacing: .5px;
- font-weight: 600;
- font-size: 9px;
- line-height: 1;
- }
- </style>
- <p>2.2.1发布后,xmake不仅原生支持多语言文件的构建,还允许用户通过自定义构建规则实现复杂的未知文件构建。</p>
- <p>自定义构建规则可以使用 <code>set_extensions</code> 将一组文件扩展名关联到它们。</p>
- <p>一旦这些扩展与规则相关联,稍后对 <code>add_files</code> 的调用将自动使用此自定义规则。</p>
- <p>这是一个示例规则,它将使用 Pandoc 将添加到构建目标的 Markdown 文件转换为 HTML 文件:</p>
- <pre><code class="lang-lua">-- Define a build rule for a markdown file
- rule("markdown")
- set_extensions(".md", ".markdown")
- on_build_file(function (target, sourcefile, opt)
- import("core.project.depend")
- import("utils.progress") -- it only for v2.5.9, we need use print to show progress below v2.5.8
- -- make sure build directory exists
- os.mkdir(target:targetdir())
- -- replace .md with .html
- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".html")
- -- only rebuild the file if its changed since last run
- depend.on_changed(function ()
- -- call pandoc to make a standalone html file from a markdown file
- os.vrunv('pandoc', {"-s", "-f", "markdown", "-t", "html", "-o", targetfile, sourcefile})
- progress.show(opt.progress, "${color.build.object}markdown %s", sourcefile)
- end, {files = sourcefile})
- end)
- target("test")
- set_kind("object")
- -- make the test target support the construction rules of the markdown file
- add_rules("markdown")
- -- adding a markdown file to build
- add_files("src/*.md")
- add_files("src/*.markdown")
- </code></pre>
- <p>还有一种以 <code>on_build_files</code> 形式代替 <code>on_build_file</code> 的方法,它允许您在一个函数调用中处理整个文件集。</p>
- <p>第二种称为 <code>on_buildcmd_file</code> 和 <code>on_buildcmd_files</code> 的形式是声明性的;它不是运行任意 Lua 来构建目标,而是运行 Lua 来了解这些目标是如何构建的。</p>
- <p><code>buildcmd</code> 的优点是可以将这些规则导出到根本不需要 xmake 即可运行的 makefile。</p>
- <p>我们可以使用 buildcmd 进一步简化它,如下所示:</p>
- <pre><code class="lang-lua">-- Define a build rule for a markdown file
- rule("markdown")
- set_extensions(".md", ".markdown")
- on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
- -- make sure build directory exists
- batchcmds:mkdir(target:targetdir())
- -- replace .md with .html
- local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".html")
- -- call pandoc to make a standalone html file from a markdown file
- batchcmds:vrunv('pandoc', {"-s", "-f", "markdown", "-t", "html", "-o", targetfile, sourcefile})
- batchcmds:show_progress(opt.progress, "${color.build.object}markdown %s", sourcefile)
- -- only rebuild the file if its changed since last run
- batchcmds:add_depfiles(sourcefile)
- end)
- target("test")
- set_kind("object")
- -- make the test target support the construction rules of the markdown file
- add_rules("markdown")
- -- adding a markdown file to build
- add_files("src/*.md")
- add_files("src/*.markdown")
- </code></pre>
- <p>无论文件扩展名如何,文件都可以分配给特定规则。您可以通过在添加文件时设置 <code>rule</code> 自定义属性来完成此操作,如下例所示:</p>
- <pre><code class="lang-lua">target("test")
- -- ...
- add_files("src/test/*.md.in", {rule = "markdown"})
- </code></pre>
- <p>一个target可以叠加应用多个rules去更加定制化实现自己的构建行为,甚至支持不同的构建环境。</p>
- <p>!> 通过<code>add_files("*.md", {rule = "markdown"})</code>方式指定的规则,优先级高于<code>add_rules("markdown")</code>设置的规则。</p>
- <h3 id="">内建规则</h3>
- <p>自从2.2.1版本后,xmake提供了一些内置规则去简化日常xmake.lua描述,以及一些常用构建环境的支持。</p>
- <p>我们可以通过运行以下命令,查看完整的内置规则列表:</p>
- <pre><code class="lang-bash">$ xmake show -l rules
- </code></pre>
- <h4 id="modedebug">mode.debug</h4>
- <p>为当前工程xmake.lua添加debug编译模式的配置规则,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.debug")
- </code></pre>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("debug") then
- set_symbols("debug")
- set_optimize("none")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m debug</code>来切换到此编译模式。</p>
- <h4 id="moderelease">mode.release</h4>
- <p>为当前工程xmake.lua添加release编译模式的配置规则,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.release")
- </code></pre>
- <p>!> 此模式默认不会带调试符号。</p>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("release") then
- set_symbols("hidden")
- set_optimize("fastest")
- set_strip("all")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m release</code>来切换到此编译模式。</p>
- <h4 id="modereleasedbg">mode.releasedbg</h4>
- <p>为当前工程xmake.lua添加releasedbg编译模式的配置规则,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.releasedbg")
- </code></pre>
- <p>!> 与release模式相比,此模式还会额外开启调试符号,这通常是非常有用的。</p>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("releasedbg") then
- set_symbols("debug")
- set_optimize("fastest")
- set_strip("all")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m releasedbg</code>来切换到此编译模式。</p>
- <h4 id="modeminsizerel">mode.minsizerel</h4>
- <p>为当前工程xmake.lua添加minsizerel编译模式的配置规则,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.minsizerel")
- </code></pre>
- <p>!> 与release模式相比,此模式更加倾向于最小代码编译优化,而不是速度优先。</p>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("minsizerel") then
- set_symbols("hidden")
- set_optimize("smallest")
- set_strip("all")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m minsizerel</code>来切换到此编译模式。</p>
- <h4 id="modecheck">mode.check</h4>
- <p>为当前工程xmake.lua添加check编译模式的配置规则,一般用于内存检测,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.check")
- </code></pre>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("check") then
- set_symbols("debug")
- set_optimize("none")
- add_cxflags("-fsanitize=address", "-ftrapv")
- add_mxflags("-fsanitize=address", "-ftrapv")
- add_ldflags("-fsanitize=address")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m check</code>来切换到此编译模式。</p>
- <h4 id="modeprofile">mode.profile</h4>
- <p>为当前工程xmake.lua添加profile编译模式的配置规则,一般用于性能分析,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.profile")
- </code></pre>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("profile") then
- set_symbols("debug")
- add_cxflags("-pg")
- add_ldflags("-pg")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m profile</code>来切换到此编译模式。</p>
- <h4 id="modecoverage">mode.coverage</h4>
- <p>为当前工程xmake.lua添加coverage编译模式的配置规则,一般用于覆盖分析,例如:</p>
- <pre><code class="lang-lua">add_rules("mode.coverage")
- </code></pre>
- <p>相当于:</p>
- <pre><code class="lang-lua">if is_mode("coverage") then
- add_cxflags("--coverage")
- add_mxflags("--coverage")
- add_ldflags("--coverage")
- end
- </code></pre>
- <p>我们可以通过:<code>xmake f -m coverage</code>来切换到此编译模式。</p>
- <h4 id="modevalgrind">mode.valgrind</h4>
- <p>此模式提供valgrind内存分析检测支持。</p>
- <pre><code class="lang-lua">add_rules("mode.valgrind")
- </code></pre>
- <p>我们可以通过:<code>xmake f -m valgrind</code>来切换到此编译模式。</p>
- <h4 id="modeasan">mode.asan</h4>
- <p>此模式提供AddressSanitizer内存分析检测支持。</p>
- <pre><code class="lang-lua">add_rules("mode.asan")
- </code></pre>
- <p>我们可以通过:<code>xmake f -m asan</code>来切换到此编译模式。</p>
- <h4 id="modetsan">mode.tsan</h4>
- <p>此模式提供ThreadSanitizer内存分析检测支持。</p>
- <pre><code class="lang-lua">add_rules("mode.tsan")
- </code></pre>
- <p>我们可以通过:<code>xmake f -m tsan</code>来切换到此编译模式。</p>
- <h4 id="modelsan">mode.lsan</h4>
- <p>此模式提供LeakSanitizer内存分析检测支持。</p>
- <pre><code class="lang-lua">add_rules("mode.lsan")
- </code></pre>
- <p>我们可以通过:<code>xmake f -m lsan</code>来切换到此编译模式。</p>
- <h4 id="modeubsan">mode.ubsan</h4>
- <p>此模式提供UndefinedBehaviorSanitizer内存分析检测支持。</p>
- <pre><code class="lang-lua">add_rules("mode.ubsan")
- </code></pre>
- <p>我们可以通过:<code>xmake f -m ubsan</code>来切换到此编译模式。</p>
- <h4 id="qtstatic">qt.static</h4>
- <p>用于编译生成Qt环境的静态库程序:</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.static")
- add_files("src/*.cpp")
- add_frameworks("QtNetwork", "QtGui")
- </code></pre>
- <h4 id="qtshared">qt.shared</h4>
- <p>用于编译生成Qt环境的动态库程序:</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.shared")
- add_files("src/*.cpp")
- add_frameworks("QtNetwork", "QtGui")
- </code></pre>
- <h4 id="qtconsole">qt.console</h4>
- <p>用于编译生成Qt环境的控制台程序:</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.console")
- add_files("src/*.cpp")
- </code></pre>
- <h4 id="qtquickapp">qt.quickapp</h4>
- <p>用于编译生成Qt环境的Quick(qml) ui应用程序。</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.quickapp")
- add_files("src/*.cpp")
- add_files("src/qml.qrc")
- </code></pre>
- <h4 id="qtquickapp_static">qt.quickapp_static</h4>
- <p>用于编译生成Qt环境的Quick(qml) ui应用程序(静态链接版本)。</p>
- <p>!> 需要切换到静态库版本Qt SDK</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.quickapp_static")
- add_files("src/*.cpp")
- add_files("src/qml.qrc")
- </code></pre>
- <h4 id="qtwidgetapp">qt.widgetapp</h4>
- <p>用于编译Qt Widgets(ui/moc)应用程序</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.widgetapp")
- add_files("src/*.cpp")
- add_files("src/mainwindow.ui")
- add_files("src/mainwindow.h") -- 添加带有 Q_OBJECT 的meta头文件
- </code></pre>
- <h4 id="qtwidgetapp_static">qt.widgetapp_static</h4>
- <p>用于编译Qt Widgets(ui/moc)应用程序(静态库版本)</p>
- <p>!> 需要切换到静态库版本Qt SDK</p>
- <pre><code class="lang-lua">target("test")
- add_rules("qt.widgetapp_static")
- add_files("src/*.cpp")
- add_files("src/mainwindow.ui")
- add_files("src/mainwindow.h") -- 添加带有 Q_OBJECT 的meta头文件
- </code></pre>
- <p>更多Qt相关描述见:<a href="https://github.com/xmake-io/xmake/issues/160">#160</a></p>
- <h4 id="xcodebundle">xcode.bundle</h4>
- <p>用于编译生成ios/macos bundle程序</p>
- <pre><code class="lang-lua">target("test")
- add_rules("xcode.bundle")
- add_files("src/*.m")
- add_files("src/Info.plist")
- </code></pre>
- <h4 id="xcodeframework">xcode.framework</h4>
- <p>用于编译生成ios/macos framework程序</p>
- <pre><code class="lang-lua">target("test")
- add_rules("xcode.framework")
- add_files("src/*.m")
- add_files("src/Info.plist")
- </code></pre>
- <h4 id="xcodeapplication">xcode.application</h4>
- <p>用于编译生成ios/macos应用程序</p>
- <pre><code class="lang-lua">target("test")
- add_rules("xcode.application")
- add_files("src/*.m", "src/**.storyboard", "src/*.xcassets")
- add_files("src/Info.plist")
- </code></pre>
- <h4 id="wdkenvkmdf">wdk.env.kmdf</h4>
- <p>应用WDK下kmdf的编译环境设置,需要配合:<code>wdk.[driver|binary|static|shared]</code>等规则来使用。</p>
- <h4 id="wdkenvumdf">wdk.env.umdf</h4>
- <p>应用WDK下umdf的编译环境设置,需要配合:<code>wdk.[driver|binary|static|shared]</code>等规则来使用。</p>
- <h4 id="wdkenvwdm">wdk.env.wdm</h4>
- <p>应用WDK下wdm的编译环境设置,需要配合:<code>wdk.[driver|binary|static|shared]</code>等规则来使用。</p>
- <h4 id="wdkdriver">wdk.driver</h4>
- <p>编译生成windows下基于WDK环境的驱动程序,目前仅支持WDK10环境。</p>
- <p>注:需要配合:<code>wdk.env.[umdf|kmdf|wdm]</code>等环境规则使用。</p>
- <pre><code class="lang-lua">-- add target
- target("echo")
- -- add rules
- add_rules("wdk.driver", "wdk.env.kmdf")
- -- add files
- add_files("driver/*.c")
- add_files("driver/*.inx")
- -- add includedirs
- add_includedirs("exe")
- </code></pre>
- <h4 id="wdkbinary">wdk.binary</h4>
- <p>编译生成windows下基于WDK环境的可执行程序,目前仅支持WDK10环境。</p>
- <p>注:需要配合:<code>wdk.env.[umdf|kmdf|wdm]</code>等环境规则使用。</p>
- <pre><code class="lang-lua">-- add target
- target("app")
- -- add rules
- add_rules("wdk.binary", "wdk.env.umdf")
- -- add files
- add_files("exe/*.cpp")
- </code></pre>
- <h4 id="wdkstatic">wdk.static</h4>
- <p>编译生成windows下基于WDK环境的静态库程序,目前仅支持WDK10环境。</p>
- <p>注:需要配合:<code>wdk.env.[umdf|kmdf|wdm]</code>等环境规则使用。</p>
- <pre><code class="lang-lua">target("nonpnp")
- -- add rules
- add_rules("wdk.static", "wdk.env.kmdf")
- -- add flags for rule: wdk.tracewpp
- add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
- -- add files
- add_files("driver/*.c", {rule = "wdk.tracewpp"})
- </code></pre>
- <h4 id="wdkshared">wdk.shared</h4>
- <p>编译生成windows下基于WDK环境的动态库程序,目前仅支持WDK10环境。</p>
- <p>注:需要配合:<code>wdk.env.[umdf|kmdf|wdm]</code>等环境规则使用。</p>
- <pre><code class="lang-lua">target("nonpnp")
- -- add rules
- add_rules("wdk.shared", "wdk.env.wdm")
- -- add flags for rule: wdk.tracewpp
- add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
- -- add files
- add_files("driver/*.c", {rule = "wdk.tracewpp"})
- </code></pre>
- <h4 id="wdktracewpp">wdk.tracewpp</h4>
- <p>用于启用tracewpp预处理源文件:</p>
- <pre><code class="lang-lua">target("nonpnp")
- -- add rules
- add_rules("wdk.driver", "wdk.env.kmdf")
- -- add flags for rule: wdk.tracewpp
- add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
- -- add files
- add_files("driver/*.c", {rule = "wdk.tracewpp"})
- add_files("driver/*.rc")
- </code></pre>
- <p>更多WDK规则描述见:<a href="https://github.com/xmake-io/xmake/issues/159">#159</a></p>
- <h4 id="winsdkapplication">win.sdk.application</h4>
- <p>编译生成winsdk应用程序。</p>
- <pre><code class="lang-lua">-- add rules
- add_rules("mode.debug", "mode.release")
- -- define target
- target("usbview")
- -- windows application
- add_rules("win.sdk.application")
- -- add files
- add_files("*.c", "*.rc")
- add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"})
- </code></pre>
- <h4 id="wdksdkdotnet">wdk.sdk.dotnet</h4>
- <p>用于指定某些c++源文件作为c++.net来编译。</p>
- <pre><code class="lang-lua">add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"})
- </code></pre>
- <h4 id="pluginvsxmakeautoupdate">plugin.vsxmake.autoupdate</h4>
- <p>我们可以使用此规则,在通过 <code>xmake project -k vsxmake</code> 生成的 vs 工程中,自动更新 vs 工程文件(当每次构建完成)。</p>
- <pre><code class="lang-lua">add_rules("plugin.vsxmake.autoupdate")
- target("test")
- set_kind("binary")
- add_files("src/*.c")
- </code></pre>
- <h4 id="plugincompile_commandsautoupdate">plugin.compile_commands.autoupdate</h4>
- <p>我们也可以使用这个规则来自动更新生成 compile_commandss.json</p>
- <pre><code class="lang-lua">add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})
- target("test")
- set_kind("binary")
- add_files("src/*.c")
- </code></pre>
- <h4 id="utilssymbolsexport_all">utils.symbols.export_all</h4>
- <p>v2.5.2 以上版本提供,我们可以用它自动导出所有的动态库符号,目前仅支持 windows dll 目标程序的符号导出,即使没有在代码中通过 <code>__declspec(dllexport)</code> 导出接口,<br>xmake 也会自动导出所有 c/c++ 接口符号。</p>
- <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
- target("foo")
- set_kind("shared")
- add_files("src/foo.c")
- add_rules("utils.symbols.export_all")
- target("test")
- set_kind("binary")
- add_deps("foo")
- add_files("src/main.c")
- </code></pre>
- <p>c++</p>
- <pre><code class="lang-lua">add_rules("utils.symbols.export_all", {export_classes = true})
- </code></pre>
- <p>相关 issue <a href="https://github.com/xmake-io/xmake/issues/1123">#1123</a></p>
- <p>2.9.5 之后的版本还支持自定义过滤器,去针对性过滤需要导出的符号名和源文件名:</p>
- <pre><code class="lang-lua">target("bar")
- set_kind("shared")
- add_files("src/bar.cpp")
- add_rules("utils.symbols.export_all", {export_filter = function (symbol, opt)
- local filepath = opt.sourcefile or opt.objectfile
- if filepath and filepath:find("bar.cpp", 1, true) and symbol:find("add", 1, true) then
- print("export: %s at %s", symbol, filepath)
- return true
- end
- end})
- </code></pre>
- <h4 id="utilssymbolsexport_list">utils.symbols.export_list</h4>
- <p>我们可以在 xmake.lua 里面直接定义导出的符号列表,例如:</p>
- <pre><code class="lang-lua">target("foo")
- set_kind("shared")
- add_files("src/foo.c")
- add_rules("utils.symbols.export_list", {symbols = {
- "add",
- "sub"}})
- </code></pre>
- <p>或者,在 <code>*.export.txt</code> 文件中添加导出的符号列表。</p>
- <pre><code class="lang-lua">target("foo2")
- set_kind("shared")
- add_files("src/foo.c")
- add_files("src/foo.export.txt")
- add_rules("utils.symbols.export_list")
- </code></pre>
- <p>完整的工程例子见:<a href="https://github.com/xmake-io/xmake/tree/dev/tests/projects/c/shared_library_export_list">导出符号例子</a></p>
- <h4 id="utilsinstallcmake_importfiles">utils.install.cmake_importfiles</h4>
- <p>v2.5.3 以上版本可以使用此规则在安装 target 目标库文件的时候,导出 .cmake 文件,用于其他 cmake 项目的库导入和查找。</p>
- <h4 id="utilsinstallpkgconfig_importfiles">utils.install.pkgconfig_importfiles</h4>
- <p>v2.5.3 以上版本可以使用此规则在安装 target 目标库文件的时候,导出 pkgconfig/.pc 文件,用于其他项目的库导入和查找。</p>
- <h4 id="utilsbin2c">utils.bin2c</h4>
- <p>v2.5.7 以上版本可以使用此规则,在项目中引入一些二进制文件,并见他们作为 c/c++ 头文件的方式提供开发者使用,获取这些文件的数据。</p>
- <p>比如,我们可以在项目中,内嵌一些 png/jpg 资源文件到代码中。</p>
- <pre><code class="lang-lua">target("console")
- set_kind("binary")
- add_rules("utils.bin2c", {extensions = {".png", ".jpg"}})
- add_files("src/*.c")
- add_files("res/*.png", "res/*.jpg")
- </code></pre>
- <p>!> extensions 的设置是可选的,默认后缀名是 .bin</p>
- <p>然后,我们就可以通过 <code>#include "filename.png.h"</code> 的方式引入进来使用,xmake 会自动帮你生成对应的头文件,并且添加对应的搜索目录。</p>
- <pre><code class="lang-c">static unsigned char g_png_data[] = {
- #include "image.png.h"
- };
- int main(int argc, char** argv)
- {
- printf("image.png: %s, size: %d\n", g_png_data, sizeof(g_png_data));
- return 0;
- }
- </code></pre>
- <p>生成头文件内容类似:</p>
- <pre><code class="lang-console">cat build/.gens/test/macosx/x86_64/release/rules/c++/bin2c/image.png.h
- 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x78, 0x6D, 0x61, 0x6B, 0x65, 0x21, 0x0A, 0x00
- </code></pre>
- <h4 id="utilsglsl2spv">utils.glsl2spv</h4>
- <p>v2.6.1 以上版本可以使用此规则,在项目中引入 <code>*.vert/*.frag</code> 等 glsl shader 文件,然后实现自动编译生成 <code>*.spv</code> 文件。</p>
- <p>另外,我们还支持以 C/C++ 头文件的方式,二进制内嵌 spv 文件数据,方便程序使用。</p>
- <h5 id="spv">编译生成 spv 文件</h5>
- <p>xmake 会自动调用 glslangValidator 或者 glslc 去编译 shaders 生成 .spv 文件,然后输出到指定的 <code>{outputdir = "build"}</code> 目录下。</p>
- <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
- add_requires("glslang", {configs = {binaryonly = true}})
- target("test")
- set_kind("binary")
- add_rules("utils.glsl2spv", {outputdir = "build"})
- add_files("src/*.c")
- add_files("src/*.vert", "src/*.frag")
- add_packages("glslang")
- </code></pre>
- <p>注,这里的 <code>add_packages("glslang")</code> 主要用于引入和绑定 glslang 包中的 glslangValidator,确保 xmake 总归能够使用它。</p>
- <p>当然,如果用户自己系统上已经安装了它,也可以不用额外绑定这个包,不过我还是建议添加一下。</p>
- <h5 id="cc">编译生成 c/c++ 头文件</h5>
- <p>我们也可以内部借助 bin2c 模块,将编译后的 spv 文件生成对应的二进制头文件,方便用户代码中直接引入,我们只需要启用 <code>{bin2c = true}</code>。:w</p>
- <pre><code class="lang-lua">add_rules("mode.debug", "mode.release")
- add_requires("glslang", {configs = {binaryonly = true}})
- target("test")
- set_kind("binary")
- add_rules("utils.glsl2spv", {bin2c = true})
- add_files("src/*.c")
- add_files("src/*.vert", "src/*.frag")
- add_packages("glslang")
- </code></pre>
- <p>然后我们可以在代码这么引入:</p>
- <pre><code class="lang-c">static unsigned char g_test_vert_spv_data[] = {
- #include "test.vert.spv.h"
- };
- static unsigned char g_test_frag_spv_data[] = {
- #include "test.frag.spv.h"
- };
- </code></pre>
- <p>跟 bin2c 规则的使用方式类似,完整例子见:<a href="https://github.com/xmake-io/xmake/tree/master/tests/projects/other/glsl2spv">glsl2spv example</a></p>
- <h4 id="utilshlsl2spv">utils.hlsl2spv</h4>
- <p>除了 <code>utils.glsl2spv</code> 规则,我们现在还支持 <code>utils.hlsl2spv</code> 规则。</p>
- <pre><code class="lang-bash">add_rules("mode.debug", "mode.release")
- add_requires("glslang", {configs = {binaryonly = true}})
- target("test")
- set_kind("binary")
- add_rules("utils.hlsl2spv", {bin2c = true})
- add_files("src/*.c")
- add_files("src/*.hlsl", "src/*.hlsl")
- add_packages("directxshadercompiler")
- </code></pre>
- <h4 id="pythonlibrary">python.library</h4>
- <p>我们可以用这个规则,配合 pybind11 生成 python 库模块,它会调整 python 库的模块名。</p>
- <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
- add_requires("pybind11")
- target("example")
- add_rules("python.library")
- add_files("src/*.cpp")
- add_packages("pybind11")
- set_languages("c++11")
- </code></pre>
- <p>带有 soabi:</p>
- <pre><code class="lang-lua">add_rules("mode.release", "mode.debug")
- add_requires("pybind11")
- target("example")
- add_rules("python.library", {soabi = true})
- add_files("src/*.cpp")
- add_packages("pybind11")
- set_languages("c++11")
- </code></pre>
- <h4 id="nodejsmodule">nodejs.module</h4>
- <p>构建 nodejs 模块。</p>
- <pre><code class="lang-lua">add_requires("node-addon-api")
- target("foo")
- set_languages("cxx17")
- add_rules("nodejs.module")
- add_packages("node-addon-api")
- add_files("*.cc")
- end
- </code></pre>
- <h4 id="utilsipsc">utils.ipsc</h4>
- <p>ipsc 编译器规则支持,使用方式如下:</p>
- <pre><code class="lang-lua">target("test")
- set_kind("binary")
- add_rules("utils.ispc", {header_extension = "_ispc.h"})
- set_values("ispc.flags", "--target=host")
- add_files("src/*.ispc")
- add_files("src/*.cpp")
- </code></pre>
- <h3 id="rule">rule</h3>
- <h4 id="">定义规则</h4>
- <pre><code class="lang-lua">rule("markdown")
- set_extensions(".md", ".markdown")
- on_build_file(function (target, sourcefile, opt)
- os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
- end)
- </code></pre>
- <h3 id="ruleadd_deps">rule:add_deps</h3>
- <h4 id="">添加规则依赖</h4>
- <p>关联依赖可以绑定一批规则,也就是不必对 target 挨个去使用 <code>add_rules()</code> 添加规则,只需要应用一个规则,就能生效它和它的所有依赖规则。</p>
- <p>例如:</p>
- <pre><code class="lang-lua">rule("foo")
- add_deps("bar")
- rule("bar")
- ...
- </code></pre>
- <p>我们只需要 <code>add_rules("foo")</code>,就能同时应用 foo 和 bar 两个规则。</p>
- <p>但是,默认情况下,依赖之间是不存在执行的先后顺序的,foo 和 bar 的 <code>on_build_file</code> 等脚本是并行执行的,顺序未定义。</p>
- <p>如果要严格控制执行顺序,可以配置 <code>add_deps("bar", {order = true})</code>,告诉 xmake,我们需要根据依赖顺序来执行同级别的脚本。</p>
- <p>例如:</p>
- <pre><code class="lang-lua">rule("foo")
- add_deps("bar", {order = true})
- on_build_file(function (target, sourcefile)
- end)
- rule("bar")
- on_build_file(function (target, sourcefile)
- end)
- </code></pre>
- <p>bar 的 <code>on_build_file</code> 将会被先执行。</p>
- <p>!> 控制依赖顺序,我们需要 xmake 2.7.2 以上版本才支持。</p>
- <p>不过,这种控制依赖的方式,只适合 foo 和 bar 两个规则都是自定义规则,如果想要将自己的规则插入到 xmake 的内置规则之前执行,这就不适用了。</p>
- <p>这个时候,我们需要使用更加灵活的动态规则创建和注入的方式,去修改内置规则。</p>
- <p>例如,我们想在内置的 <code>c++.build</code> 规则之前,执行自定义 cppfront 规则的 <code>on_build_file</code> 脚本,我们可以通过下面的方式来实现。</p>
- <pre><code class="lang-lua">rule("cppfront")
- set_extensions(".cpp2")
- on_load(function (target)
- local rule = target:rule("c++.build"):clone()
- rule:add("deps", "cppfront", {order = true})
- target:rule_add(rule)
- end)
- on_build_file(function (target, sourcefile, opt)
- print("build cppfront file")
- end)
- target("test")
- set_kind("binary")
- add_rules("cppfront")
- add_files("src/*.cpp")
- add_files("src/*.cpp2")
- </code></pre>
- <h3 id="ruleadd_imports">rule:add_imports</h3>
- <h4 id="">为所有自定义脚本预先导入扩展模块</h4>
- <p>使用方式和说明请见:<a href="#targetadd_imports">target:add_imports</a>,用法相同。</p>
- <h3 id="ruleset_extensions">rule:set_extensions</h3>
- <h4 id="">设置规则支持的文件扩展类型</h4>
- <p>通过设置支持的扩展文件类型,将规则应用于带这些后缀的文件上,例如:</p>
- <pre><code class="lang-lua">-- 定义一个markdown文件的构建规则
- rule("markdown")
- set_extensions(".md", ".markdown")
- on_build_file(function (target, sourcefile, opt)
- os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html"))
- end)
- target("test")
- set_kind("binary")
- -- 使test目标支持markdown文件的构建规则
- add_rules("markdown")
- -- 添加markdown文件的构建
- add_files("src/*.md")
- add_files("src/*.markdown")
- </code></pre>
- <h3 id="ruleon_load">rule:on_load</h3>
- <h4 id="">自定义加载脚本</h4>
- <p>用于实现自定规则的加载脚本,当加载target的时候,会被执行,可在里面自定义设置一些target配置,例如:</p>
- <pre><code class="lang-lua">rule("test")
- on_load(function (target)
- target:add("defines", "TEST")
- end)
- </code></pre>
- <h3 id="ruleon_link">rule:on_link</h3>
- <h4 id="">自定义链接脚本</h4>
- <p>用于实现自定规则的链接脚本,会覆盖被应用的target的默认链接行为,例如:</p>
- <pre><code class="lang-lua">rule("test")
- on_link(function (target)
- end)
- </code></pre>
- <h3 id="ruleon_config">rule:on_config</h3>
- <h4 id="">自定义配置脚本</h4>
- <p>在 <code>xmake config</code> 执行完成后,Build 之前会执行此脚本,通常用于编译前的配置工作。它与 on_load 不同的是,on_load 只要 target 被加载就会执行,执行时机更早。</p>
- <p>如果一些配置,无法在 on_load 中过早配置,那么都可以在 on_config 中去配置它。</p>
- <p>另外,它的执行时机比 before_build 还要早,大概的执行流程如下:</p>
- <pre><code>on_load -> after_load -> on_config -> before_build -> on_build -> after_build
- </code></pre><h3 id="ruleon_build">rule:on_build</h3>
- <h4 id="">自定义编译脚本</h4>
- <p>用于实现自定规则的构建脚本,会覆盖被应用的target的默认构建行为,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_build(function (target)
- end)
- </code></pre>
- <h3 id="ruleon_clean">rule:on_clean</h3>
- <h4 id="">自定义清理脚本</h4>
- <p>用于实现自定规则的清理脚本会,覆盖被应用的target的默认清理行为,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_clean(function (target)
- -- remove sourcefile.html
- end)
- </code></pre>
- <h3 id="ruleon_package">rule:on_package</h3>
- <h4 id="">自定义打包脚本</h4>
- <p>用于实现自定规则的打包脚本,覆盖被应用的target的默认打包行为, 例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_package(function (target)
- -- package sourcefile.html
- end)
- </code></pre>
- <h3 id="ruleon_install">rule:on_install</h3>
- <h4 id="">自定义安装脚本</h4>
- <p>用于实现自定规则的安装脚本,覆盖被应用的target的默认安装行为, 例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_install(function (target)
- end)
- </code></pre>
- <h3 id="ruleon_uninstall">rule:on_uninstall</h3>
- <h4 id="">自定义卸载脚本</h4>
- <p>用于实现自定规则的卸载脚本,覆盖被应用的target的默认卸载行为, 例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_uninstall(function (target)
- end)
- </code></pre>
- <h3 id="ruleon_build_file">rule:on_build_file</h3>
- <h4 id="">自定义编译脚本,一次处理一个源文件</h4>
- <pre><code class="lang-lua">rule("markdown")
- on_build_file(function (target, sourcefile, opt)
- print("%%%d: %s", opt.progress, sourcefile)
- end)
- </code></pre>
- <p>其中第三个参数opt是可选参数,用于获取一些编译过程中的信息状态,例如:opt.progress 为当期的编译进度。</p>
- <h3 id="ruleon_buildcmd_file">rule:on_buildcmd_file</h3>
- <h4 id="">自定义批处理编译脚本,一次处理一个源文件</h4>
- <p>这是 2.5.2 版本新加的接口,里面的脚本不会直接构建源文件,但是会通过 batchcmds 对象,构造一个批处理命令行任务,<br>xmake 在实际执行构建的时候,一次性执行这些命令。</p>
- <p>这对于 <code>xmake project</code> 此类工程生成器插件非常有用,因为生成器生成的第三方工程文件并不支持 <code>on_build_files</code> 此类内置脚本的执行支持。</p>
- <p>但是 <code>on_buildcmd_files</code> 构造的最终结果,就是一批原始的 cmd 命令行,可以直接给其他工程文件作为 custom commands 来执行。</p>
- <p>另外,相比 <code>on_build_files</code>,它也简化对扩展文件的编译实现,更加的可读易配置,对用户也更加友好。</p>
- <pre><code class="lang-lua">rule("foo")
- set_extensions(".xxx")
- on_buildcmd_file(function (target, batchcmds, sourcefile, opt)
- batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile})
- batchcmds:add_depfiles("/xxxxx/dependfile.h", ...)
- -- batchcmds:add_depvalues(...)
- -- batchcmds:set_depmtime(os.mtime(...))
- -- batchcmds:set_depcache("xxxx.d")
- end)
- </code></pre>
- <p>除了 <code>batchcmds:vrunv</code>,我们还支持一些其他的批处理命令,例如:</p>
- <pre><code class="lang-lua">batchcmds:show("hello %s", "xmake")
- batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile}, {envs = {LD_LIBRARY_PATH="/xxx"}})
- batchcmds:mkdir("/xxx") -- and cp, mv, rm, ln ..
- batchcmds:compile(sourcefile_cx, objectfile, {configs = {includedirs = sourcefile_dir, languages = (sourcekind == "cxx" and "c++11")}})
- batchcmds:link(objectfiles, targetfile, {configs = {linkdirs = ""}})
- </code></pre>
- <p>同时,我们在里面也简化对依赖执行的配置,下面是一个完整例子:</p>
- <pre><code class="lang-lua">rule("lex")
- set_extensions(".l", ".ll")
- on_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt)
- -- imports
- import("lib.detect.find_tool")
- -- get lex
- local lex = assert(find_tool("flex") or find_tool("lex"), "lex not found!")
- -- get c/c++ source file for lex
- local extension = path.extension(sourcefile_lex)
- local sourcefile_cx = path.join(target:autogendir(), "rules", "lex_yacc", path.basename(sourcefile_lex) .. (extension == ".ll" and ".cpp" or ".c"))
- -- add objectfile
- local objectfile = target:objectfile(sourcefile_cx)
- table.insert(target:objectfiles(), objectfile)
- -- add commands
- batchcmds:show_progress(opt.progress, "${color.build.object}compiling.lex %s", sourcefile_lex)
- batchcmds:mkdir(path.directory(sourcefile_cx))
- batchcmds:vrunv(lex.program, {"-o", sourcefile_cx, sourcefile_lex})
- batchcmds:compile(sourcefile_cx, objectfile)
- -- add deps
- batchcmds:add_depfiles(sourcefile_lex)
- local dependfile = target:dependfile(objectfile)
- batchcmds:set_depmtime(os.mtime(dependfile))
- batchcmds:set_depcache(dependfile)
- end)
- </code></pre>
- <p><code>add_depfiles</code> 设置这个目标文件依赖的源文件。<code>set_depmtime</code> 设置目标文件的修改时间,如果有任意源文件的修改时间大于它,则认为需要重新生成这个目标文件。这里使用 dependfile 而不是 objectfile 的原因见 <a href="https://github.com/xmake-io/xmake/issues/748">issues 748</a>。<code>set_depcache</code> 设置存储依赖信息的文件。</p>
- <p>关于这个的详细说明和背景,见:<a href="https://github.com/xmake-io/xmake/issues/1246">issue 1246</a></p>
- <h3 id="ruleon_build_files">rule:on_build_files</h3>
- <h4 id="">自定义编译脚本,一次处理多个源文件</h4>
- <p>大部分的自定义构建规则,每次都是处理单独一个文件,输出一个目标文件,例如:a.c => a.o</p>
- <p>但是,有些情况下,我们需要同时输入多个源文件一起构建生成一个目标文件,例如:a.c b.c d.c => x.o</p>
- <p>对于这种情况,我们可以通过自定义这个脚本来实现:</p>
- <pre><code class="lang-lua">rule("markdown")
- on_build_files(function (target, sourcebatch, opt)
- -- build some source files
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- -- ...
- end
- end)
- </code></pre>
- <h3 id="ruleon_buildcmd_files">rule:on_buildcmd_files</h3>
- <h4 id="">自定义批处理编译脚本,一次处理多个源文件</h4>
- <p>关于这个的详细说明,见:<a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a></p>
- <pre><code class="lang-lua">rule("foo")
- set_extensions(".xxx")
- on_buildcmd_files(function (target, batchcmds, sourcebatch, opt)
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- batchcmds:vrunv("gcc", {"-o", objectfile, "-c", sourcefile})
- end
- end)
- </code></pre>
- <h3 id="rulebefore_config">rule:before_config</h3>
- <h4 id="">自定义配置前脚本</h4>
- <p>用于实现自定义 target 配置前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("test")
- before_config(function (target)
- end)
- </code></pre>
- <p>它会在 on_config 之前被执行。</p>
- <h3 id="rulebefore_link">rule:before_link</h3>
- <h4 id="">自定义链接前脚本</h4>
- <p>用于实现自定义target链接前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("test")
- before_link(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_build">rule:before_build</h3>
- <h4 id="">自定义编译前脚本</h4>
- <p>用于实现自定义target构建前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- before_build(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_clean">rule:before_clean</h3>
- <h4 id="">自定义清理前脚本</h4>
- <p>用于实现自定义target清理前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- before_clean(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_package">rule:before_package</h3>
- <h4 id="">自定义打包前脚本</h4>
- <p>用于实现自定义target打包前的执行脚本, 例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- before_package(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_install">rule:before_install</h3>
- <h4 id="">自定义安装前脚本</h4>
- <p>用于实现自定义target安装前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- before_install(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_uninstall">rule:before_uninstall</h3>
- <h4 id="">自定义卸载前脚本</h4>
- <p>用于实现自定义target卸载前的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("markdown")
- before_uninstall(function (target)
- end)
- </code></pre>
- <h3 id="rulebefore_build_file">rule:before_build_file</h3>
- <h4 id="">自定义编译前脚本,一次处理一个源文件</h4>
- <p>跟<a href="#ruleon_build_file">rule:on_build_file</a>用法类似,不过这个接口被调用的时机是在编译某个源文件之前,<br>一般用于对某些源文件进行编译前的预处理。</p>
- <h3 id="rulebefore_buildcmd_file">rule:before_buildcmd_file</h3>
- <h4 id="">自定义编译前批处理脚本,一次处理一个源文件</h4>
- <p>跟<a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a>用法类似,不过这个接口被调用的时机是在编译某个源文件之前,<br>一般用于对某些源文件进行编译前的预处理。</p>
- <h3 id="rulebefore_build_files">rule:before_build_files</h3>
- <h4 id="">自定义编译前脚本,一次处理多个源文件</h4>
- <p>跟<a href="#ruleon_build_files">rule:on_build_files</a>用法类似,不过这个接口被调用的时机是在编译某些源文件之前,<br>一般用于对某些源文件进行编译前的预处理。</p>
- <h3 id="rulebefore_buildcmd_files">rule:before_buildcmd_files</h3>
- <h4 id="">自定义编译前批处理脚本,一次处理多个源文件</h4>
- <p>跟<a href="#ruleon_buildcmd_files">rule:on_buildcmd_files</a>用法类似,不过这个接口被调用的时机是在编译某些源文件之前,<br>一般用于对某些源文件进行编译前的预处理。</p>
- <h3 id="ruleafter_config">rule:after_config</h3>
- <h4 id="">自定义配置后脚本</h4>
- <p>用于实现自定义 target 配置后的执行脚本,例如:</p>
- <pre><code class="lang-lua">rule("test")
- after_config(function (target)
- end)
- </code></pre>
- <p>它会在 on_config 之后被执行。</p>
- <h3 id="ruleafter_link">rule:after_link</h3>
- <h4 id="">自定义链接后脚本</h4>
- <p>用于实现自定义target链接后的执行脚本,用法跟<a href="#rulebefore_link">rule:before_link</a>类似。</p>
- <h3 id="ruleafter_build">rule:after_build</h3>
- <h4 id="">自定义编译后脚本</h4>
- <p>用于实现自定义target构建后的执行脚本,用法跟<a href="#rulebefore_build">rule:before_build</a>类似。</p>
- <h3 id="ruleafter_clean">rule:after_clean</h3>
- <h4 id="">自定义清理后脚本</h4>
- <p>用于实现自定义target清理后的执行脚本,用法跟<a href="#rulebefore_clean">rule:before_clean</a>类似。</p>
- <h3 id="ruleafter_package">rule:after_package</h3>
- <h4 id="">自定义打包后脚本</h4>
- <p>用于实现自定义target打包后的执行脚本, 用法跟<a href="#rulebefore_package">rule:before_package</a>类似。</p>
- <h3 id="ruleafter_install">rule:after_install</h3>
- <h4 id="">自定义安装后脚本</h4>
- <p>用于实现自定义target安装后的执行脚本,用法跟<a href="#rulebefore_install">rule:before_install</a>类似。</p>
- <h3 id="ruleafter_uninstall">rule:after_uninstall</h3>
- <h4 id="">自定义卸载后脚本</h4>
- <p>用于实现自定义target卸载后的执行脚本,用法跟<a href="#rulebefore_uninstall">rule:before_uninstall</a>类似。</p>
- <h3 id="ruleafter_build_file">rule:after_build_file</h3>
- <h4 id="">自定义编译后脚本,一次处理一个源文件</h4>
- <p>跟<a href="#ruleon_build_file">rule:on_build_file</a>用法类似,不过这个接口被调用的时机是在编译某个源文件之后,<br>一般用于对某些编译后对象文件进行后期处理。</p>
- <h3 id="ruleafter_buildcmd_file">rule:after_buildcmd_file</h3>
- <h4 id="">自定义编译后批处理脚本,一次处理一个源文件</h4>
- <p>跟<a href="#ruleon_buildcmd_file">rule:on_buildcmd_file</a>用法类似,不过这个接口被调用的时机是在编译某个源文件之后,<br>一般用于对某些编译后对象文件进行后期处理。</p>
- <h3 id="ruleafter_build_files">rule:after_build_files</h3>
- <h4 id="">自定义编译后脚本,一次处理多个源文件</h4>
- <p>跟<a href="#ruleon_build_files">rule:on_build_files</a>用法类似,不过这个接口被调用的时机是在编译某些源文件之后,<br>一般用于对某些编译后对象文件进行后期处理。</p>
- <h3 id="ruleafter_buildcmd_files">rule:after_buildcmd_files</h3>
- <h4 id="">自定义编译后批处理脚本,一次处理多个源文件</h4>
- <p>跟<a href="#ruleon_buildcmd_files">rule:on_buildcmd_files</a>用法类似,不过这个接口被调用的时机是在编译某些源文件之后,<br>一般用于对某些编译后对象文件进行后期处理。</p>
- <h3 id="rule_end">rule_end</h3>
- <h4 id="">结束定义规则</h4>
- <p>这个是可选的,如果想要手动结束rule的定义,可以调用它:</p>
- <pre><code class="lang-lua">rule("test")
- -- ..
- rule_end()
- </code></pre>
- </article>
- </body>
- </html>
|