| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <!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/#/manual/conditions">https://xmake.io/#/manual/conditions</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>Conditions are generally used to handle some special compilation platforms.</p>
- <table>
- <thead>
- <tr>
- <th>Interfaces</th>
- <th>Description</th>
- <th>Support version</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td><a href="#is_os">is_os</a></td>
- <td>Is the current compilation target system?</td>
- <td>>= 2.0.1</td>
- </tr>
- <tr>
- <td><a href="#is_arch">is_arch</a></td>
- <td>Is the current compilation architecture?</td>
- <td>>= 2.0.1</td>
- </tr>
- <tr>
- <td><a href="#is_plat">is_plat</a></td>
- <td>Is the current compilation platform?</td>
- <td>>= 2.0.1</td>
- </tr>
- <tr>
- <td><a href="#is_host">is_host</a></td>
- <td>Is the current compilation host system?</td>
- <td>>= 2.1.4</td>
- </tr>
- <tr>
- <td><a href="#is_mode">is_mode</a></td>
- <td>Is the current compilation mode?</td>
- <td>>= 2.0.1</td>
- </tr>
- <tr>
- <td><a href="#is_kind">is_kind</a></td>
- <td>Is the current target kind?</td>
- <td>>= 2.0.1</td>
- </tr>
- <tr>
- <td><a href="#is_config">is_config</a></td>
- <td>Is the given config values?</td>
- <td>>= 2.2.2</td>
- </tr>
- <tr>
- <td><a href="#has_config">has_config</a></td>
- <td>Is the given configs enabled?</td>
- <td>>= 2.2.2</td>
- </tr>
- <tr>
- <td><a href="#has_package">has_package</a></td>
- <td>Is the given dependent package enabled?</td>
- <td>>= 2.2.3</td>
- </tr>
- </tbody>
- </table>
- <h3 id="is_os">is_os</h3>
- <h4 id="isthecurrentcompilationtargetsystem">Is the current compilation target system</h4>
- <pre><code class="lang-lua">if is_os("ios") then
- add_files("src/xxx/*.m")
- end
- </code></pre>
- <p>Support operation systems:</p>
- <ul>
- <li>windows</li>
- <li>linux</li>
- <li>android</li>
- <li>macosx</li>
- <li>ios</li>
- </ul>
- <h3 id="is_arch">is_arch</h3>
- <h4 id="isthecurrentcompilationarchitecture">Is the current compilation architecture</h4>
- <p>You can use this api to check the configuration command: <code>xmake f -a armv7</code></p>
- <pre><code class="lang-lua">-- if the current architecture is x86_64 or i386
- if is_arch("x86_64", "i386") then
- add_files("src/xxx/*.c")
- end
- -- if the current architecture is armv7 or arm64 or armv7s or armv7-a
- if is_arch("armv7", "arm64", "armv7s", "armv7-a") then
- -- ...
- end
- </code></pre>
- <p>And you can also use the lua regular expression: <code>.*</code> to check all matched architectures.</p>
- <pre><code class="lang-lua">-- if the current architecture is arm which contains armv7, arm64, armv7s and armv7-a ...
- if is_arch("arm.*") then
- -- ...
- end
- </code></pre>
- <h3 id="is_plat">is_plat</h3>
- <h4 id="isthecurrentcompilationplatform">Is the current compilation platform</h4>
- <p>You can use this api to check the configuration command: <code>xmake f -p iphoneos</code></p>
- <pre><code class="lang-lua">-- if the current platform is android
- if is_plat("android") then
- add_files("src/xxx/*.c")
- end
- -- if the current platform is macosx or iphoneos
- if is_plat("macosx", "iphoneos") then
- add_frameworks("Foundation")
- end
- </code></pre>
- <p>Available platforms:</p>
- <table>
- <thead>
- <tr>
- <th>Platform</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>android</td>
- </tr>
- <tr>
- <td>appletvos</td>
- </tr>
- <tr>
- <td>applexros</td>
- </tr>
- <tr>
- <td>bsd</td>
- </tr>
- <tr>
- <td>cross</td>
- </tr>
- <tr>
- <td>cygwin</td>
- </tr>
- <tr>
- <td>haiku</td>
- </tr>
- <tr>
- <td>iphoneos</td>
- </tr>
- <tr>
- <td>linux</td>
- </tr>
- <tr>
- <td>macosx</td>
- </tr>
- <tr>
- <td>mingw</td>
- </tr>
- <tr>
- <td>msys</td>
- </tr>
- <tr>
- <td>wasm</td>
- </tr>
- <tr>
- <td>watchos</td>
- </tr>
- <tr>
- <td>windows</td>
- </tr>
- </tbody>
- </table>
- <h3 id="is_host">is_host</h3>
- <h4 id="isthecurrentcompilationhostsystem">Is the current compilation host system</h4>
- <p>Some compilation platforms can be built on multiple different operating systems, for example: android ndk (on linux, macOS and windows).</p>
- <p>So, we can use this api to determine the current host operating system.</p>
- <pre><code class="lang-lua">if is_host("windows") then
- add_includedirs("C:\\includes")
- else
- add_includedirs("/usr/includess")
- end
- </code></pre>
- <p>Support hosts:</p>
- <ul>
- <li>windows</li>
- <li>linux</li>
- <li>macosx</li>
- </ul>
- <p>We can also get it from <a href="/mirror/manual/builtin_variables.html#varhost">$(host)</a> or <a href="/mirror/manual/builtin_modules.html#oshost">os.host</a>.</p>
- <h3 id="is_subhost">is_subhost</h3>
- <h4 id="determinethesubsystemenvironmentofthecurrenthost">Determine the subsystem environment of the current host</h4>
- <p>At present, it is mainly used for detection of cygwin, msys2 and other subsystem environments on windows systems. If you run xmake in the msys2 shell environment, then <code>is_subhost("windows")</code> will return false, and <code>is_host("windows")</code> It will still return true.</p>
- <p>Currently supported subsystems:</p>
- <ul>
- <li>msys</li>
- <li>cygwin</li>
- </ul>
- <p>Configuration example:</p>
- <pre><code class="lang-lua">if is_subhost("msys", "cygwin") then
- - Currently in the shell environment of msys2/cygwin
- end
- </code></pre>
- <p>We can also quickly check the current subsystem platform by executing <code>xmake l os.subhost</code>.</p>
- <p>!> It may also support other subsystem environments under linux and macos systems later, if they exist.</p>
- <h3 id="is_subarch">is_subarch</h3>
- <h4 id="determinethearchitectureofthecurrenthostsubsystemenvironment">Determine the architecture of the current host subsystem environment</h4>
- <p>At present, it is mainly used for the detection of the architecture under the subsystem environment such as cygwin and msys2 on the windows system. The msvc tool chain is usually used on the windows compilation platform, and the architecture is x64, x86.<br>In the msys/cygwin subsystem environment, the compiler architecture defaults to x86_64/i386, which is different.</p>
- <p>We can also quickly view the current subsystem architecture by executing <code>xmake l os.subarch</code>.</p>
- <h3 id="is_cross">is_cross</h3>
- <h4 id="determineswhetherthecurrentplatformiscrosscompiledornot">Determines whether the current platform is cross-compiled or not.</h4>
- <p>This interface returns true if the current target architecture and platform, which is not the current host platform, is cross-compiled.</p>
- <h3 id="is_mode">is_mode</h3>
- <h4 id="isthecurrentcompilationmode">Is the current compilation mode</h4>
- <p>You can use this api to check the configuration command: <code>xmake f -m debug</code></p>
- <p>The compilation mode is not builtin mode for xmake, so you can set the mode value by yourself.</p>
- <p>We often use these configuration values: <code>debug</code>, <code>release</code>, <code>profile</code>, etc.</p>
- <pre><code class="lang-lua">-- if the current compilation mode is debug?
- if is_mode("debug") then
- -- add macro: DEBUG
- add_defines("DEBUG")
- -- enable debug symbols
- set_symbols("debug")
- -- disable optimization
- set_optimize("none")
- end
- -- if the current compilation mode is release or profile?
- if is_mode("release", "profile") then
- if is_mode("release") then
- -- mark symbols visibility as hidden
- set_symbols("hidden")
- -- strip all symbols
- set_strip("all")
- -- fomit frame pointer
- add_cxflags("-fomit-frame-pointer")
- add_mxflags("-fomit-frame-pointer")
- else
- -- enable debug symbols
- set_symbols("debug")
- end
- -- add vectorexts
- add_vectorexts("sse2", "sse3", "ssse3", "mmx")
- end
- </code></pre>
- <h3 id="is_kind">is_kind</h3>
- <h4 id="isthecurrenttargetkind">Is the current target kind</h4>
- <p>You can use this api to check the configuration command: <code>xmake f -k [static|shared]</code></p>
- <pre><code class="lang-lua">target("test")
- -- set target kind from the configuration command
- set_kind("$(kind)")
- add_files("src/*c")
- -- compile target for static?
- if is_kind("static") then
- add_files("src/xxx.c")
- end
- </code></pre>
- <p>You can switch the target kind by configuration command.</p>
- <pre><code class="lang-bash"># compile as static library
- $ xmake f -k static
- $ xmake
- </code></pre>
- <pre><code class="lang-bash"># compile as shared library
- $ xmake f -k shared
- $ xmake
- </code></pre>
- <h3 id="is_config">is_config</h3>
- <h4 id="isthegivenconfigvalues">Is the given config values?</h4>
- <p>This interface is introduced from version 2.2.2 to determine whether the specified configuration is a given value.</p>
- <p>For example:</p>
- <pre><code class="lang-console">$ xmake f --test=hello1
- </code></pre>
- <pre><code class="lang-lua">option("test")
- set_showmenu(true)
- set_description("The test config option")
- option_end()
- if is_config("test", "hello1", "hello2") then
- add_defines("HELLO")
- end
- </code></pre>
- <p>Can be used for conditional package requirements, eg. :</p>
- <pre><code class="lang-lua">-- Add lua or luajit package requirements, depending on the lua_flavor option value
- option("lua_flavor")
- set_showmenu(true)
- set_values("luajit", "lua")
- option_end()
- if is_config("lua_flavor", "luajit") then
- add_requires("luajit")
- elseif is_config("lua_flavor", "lua") then
- add_requires("lua")
- end
- </code></pre>
- <p>Not only that, we can also set pattern matching rules to determine values, such as:</p>
- <pre><code class="lang-lua">if is_config("test", "hello.*") then
- add_defines("HELLO")
- end
- </code></pre>
- <p><p class="tip"><br>This interface is not only able to determine the custom options defined through the <a href="#option">option</a>,<br>but also to determine the built-in global and local configuration.<br></p>
- </p>
- <h3 id="has_config">has_config</h3>
- <h4 id="isthegivenconfigsenabled">Is the given configs enabled?</h4>
- <p>This interface is introduced from version 2.2.2 to detect whether a custom or built-in option/configuration exists or is enabled.</p>
- <p>For example, the following configuration will be true:</p>
- <pre><code class="lang-console"># enable the given config or option (if be boolean type)
- $ xmake f --test1=y
- $ xmake f --test1=yes
- $ xmake f --test1=true
- # set the config value
- $ xmake f --test2=value
- </code></pre>
- <pre><code class="lang-lua">if has_config("test1", "test2") then
- add_defines("TEST")
- end
- </code></pre>
- <p>And the following configuration will be false:</p>
- <pre><code class="lang-console"># disable config/option(if be boolean type)
- $ xmake f --test1=n
- $ xmake f --test1=no
- $ xmake f --test1=false
- </code></pre>
- <p><p class="tip"><br>This interface can determine not only the built-in global and local configs,<br>but also the custom options defined through the <a href="#option">option</a>.<br></p>
- </p>
- <h3 id="has_package">has_package</h3>
- <h4 id="isthegivendependentpackageenabled">Is the given dependent package enabled?</h4>
- <p>This interface is introduced from version 2.2.3 to detect whether a dependent package exists or is enabled.</p>
- <p>It is usually used to <a href="/mirror/zh-cn/manual/global_interfaces.html#add_requires">add_requires</a>.</p>
- <pre><code class="lang-lua">add_requires("tbox", {optional = true})
- target("test")
- set_kind("binary")
- add_files("src/*.c")
- add_packages("tbox")
- if has_package("tbox") then
- add_defines("HAVE_TBOX")
- end
- </code></pre>
- <p>If the remote dependencies are added via the optional add-on package added by <code>add_requires</code>, or the current platform does not support the actual installation, then <code>has_package</code> will return false.<br>Indicates that it does not exist, and then does some special processing for other flags definitions and even source file compilation controls.</p>
- <p><p class="tip"><br>The difference between this interface and <a href="#has_config">has_config</a> is that <a href="#has_config">has_config</a> is used for <a href="#option">option</a> whereas this is used for <a href="#add_requires">add_requires</a>.<br></p>
- </p>
- </article>
- </body>
- </html>
|