| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- <!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/package_instance">https://xmake.io/#/manual/package_instance</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>This page describes the interface for <code>package</code> of functions like <code>on_load()</code>, <code>on_install()</code> or <code>on_test()</code> of the <a href="manual/package_dependencies.md">Package Dependencies</a></p>
- <h4 id="packagename">package:name</h4>
- <ul>
- <li>Get the name of the package</li>
- </ul>
- <h4 id="packageget">package:get</h4>
- <ul>
- <li>Get the values of the package by name</li>
- </ul>
- <pre><code class="lang-lua">-- get the dependencies
- package:get("deps")
- -- get the links
- package:get("links")
- -- get the defined macros
- package:get("defines")
- </code></pre>
- <h4 id="packageset">package:set</h4>
- <ul>
- <li>Set the values of the package by name (If you just want to add values use <a href="#packageadd">package:add</a>)</li>
- </ul>
- <pre><code class="lang-lua">-- set the dependencies
- package:set("deps", "python")
- -- set the links
- package:set("links", "sdl2")
- -- set the defined macros
- package:set("defines", "SDL_MAIN_HANDLED")
- </code></pre>
- <h4 id="packageadd">package:add</h4>
- <ul>
- <li>Add to the values of the package by name</li>
- </ul>
- <pre><code class="lang-lua">-- add dependencies
- package:add("deps", "python")
- -- add links
- package:add("links", "sdl2")
- -- add defined macros
- package:add("defines", "SDL_MAIN_HANDLED")
- </code></pre>
- <h4 id="packagelicense">package:license</h4>
- <ul>
- <li>Get the license of the package (Same as <code>package:get("license")</code>)</li>
- </ul>
- <h4 id="packagedescription">package:description</h4>
- <ul>
- <li>Get the description of the package (Same as <code>package:get("description")</code>)</li>
- </ul>
- <h4 id="packageplat">package:plat</h4>
- <ul>
- <li>Get the platform of the package. Can be any of:<ul>
- <li>windows</li>
- <li>linux</li>
- <li>macosx</li>
- <li>android</li>
- <li>iphoneos</li>
- <li>watchos</li>
- <li>mingw</li>
- <li>cygwin</li>
- <li>bsd</li>
- </ul>
- </li>
- </ul>
- <p>If the package is binary <a href="manual/builtin_modules.md#oshost"><code>os.host</code></a> is returned</p>
- <h4 id="packagearch">package:arch</h4>
- <ul>
- <li>Get the architecture of the package (e.g. x86, x64, x86_64)</li>
- </ul>
- <p>If the package is binary <a href="manual/builtin_modules.md#osarch"><code>os.arch</code></a> is returned</p>
- <h4 id="packagetargetos">package:targetos</h4>
- <ul>
- <li>Get the targeted OS of the package. Can have the same values as <a href="#packageplat">package:plat</a></li>
- </ul>
- <h4 id="packagetargetarch">package:targetarch</h4>
- <ul>
- <li>Get the targeted architecture of the package. Can have the same values as <a href="#packagearch">package:arch</a></li>
- </ul>
- <h4 id="packageis_plat">package:is_plat</h4>
- <ul>
- <li>Wether the current platform is one of the given platforms</li>
- </ul>
- <pre><code class="lang-lua">-- Is the current platform android?
- package:is_plat("android")
- -- Is the current platform windows, linux or macosx?
- package:is_plat("windows", "linux", "macosx")
- </code></pre>
- <h4 id="packageis_arch">package:is_arch</h4>
- <ul>
- <li>Wether the current platform is one of the given platforms</li>
- </ul>
- <pre><code class="lang-lua">-- Is the current architecture x86
- package:is_arch("x86")
- -- Is the current architecture x64 or x86_64
- package:is_arch("x64", "x86_64")
- </code></pre>
- <h4 id="packageis_targetos">package:is_targetos</h4>
- <ul>
- <li>Wether the currently targeted OS is one of the given OS</li>
- </ul>
- <pre><code class="lang-lua">-- Is the currently targeted OS windows?
- package:is_targetos("windows")
- -- Is the currently targeted OS android or iphoneos?
- package:is_targetos("android", "iphoneos")
- </code></pre>
- <h4 id="packageis_targetarch">package:is_targetarch</h4>
- <ul>
- <li>Wether the currently targeted architecture is one of the given architectures</li>
- </ul>
- <pre><code class="lang-lua">-- Is the currently targeted architecture x86
- package:is_targetarch("x86")
- -- Is the currently targeted architecture x64 or x86_64
- package:is_targetarch("x64", "x86_64")
- </code></pre>
- <h4 id="packagealias">package:alias</h4>
- <ul>
- <li>Get the alias of the package</li>
- </ul>
- <p>If the user sets an alias like so:</p>
- <pre><code class="lang-lua">add_requires("libsdl", {alias = "sdl"})
- </code></pre>
- <p>This alias can be retrieved by</p>
- <pre><code class="lang-lua">-- returns "sdl"
- package:alias()
- </code></pre>
- <h4 id="packageurls">package:urls</h4>
- <ul>
- <li>Get the URLs of the package</li>
- </ul>
- <p>Retrieve the URLs set by:</p>
- <pre><code class="lang-lua">add_urls("https://example.com/library-$(version).zip")
- -- or so
- set_urls("https://example.com/library-$(version).zip")
- </code></pre>
- <p>Then write this:</p>
- <pre><code class="lang-lua">-- returns the table {"https://example.com/library-$(version).zip"}
- package:urls()
- </code></pre>
- <h4 id="packagedep">package:dep</h4>
- <ul>
- <li>Get a dependency of the package by name. The name needs to be a dependency of the package.</li>
- </ul>
- <pre><code class="lang-lua">local python = package:dep("python")
- -- returns "python"
- python:name()
- </code></pre>
- <h4 id="packagedeps">package:deps</h4>
- <ul>
- <li>Get all dependencies of the package</li>
- </ul>
- <pre><code class="lang-lua">-- prints the names of all dependencies
- for _,dep in pairs(package:deps()) do
- print(dep:name())
- end
- </code></pre>
- <h4 id="packagesourcehash">package:sourcehash</h4>
- <ul>
- <li>Get the sha256 checksum of an URL alias</li>
- </ul>
- <p>If the checksum is provided like so:</p>
- <pre><code class="lang-lua">add_urls("https://example.com/library-$(version).zip", {alias = "example"})
- add_versions("example:2.4.1", "29f9983cc7196e882c4bc3d23d7492f9c47574c7cf658afafe7d00c185429941")
- </code></pre>
- <p>You can retrieve the checksum like so:</p>
- <pre><code class="lang-lua">-- returns "29f9983cc7196e882c4bc3d23d7492f9c47574c7cf658afafe7d00c185429941"
- package:sourcehash("example")
- -- or so
- package:sourcehash(package:url_alias(package:urls()[1]))
- </code></pre>
- <h4 id="packagekind">package:kind</h4>
- <ul>
- <li>Get the kind of the package. Can be any of:<ul>
- <li>binary</li>
- <li>toolchain (is also binary)</li>
- <li>library (default)</li>
- <li>template <a href="https://github.com/xmake-io/xmake/issues/2138">#2138</a></li>
- <li>headeronly</li>
- </ul>
- </li>
- </ul>
- <h4 id="packageis_binary">package:is_binary</h4>
- <ul>
- <li>Wether the package is of kind binary</li>
- </ul>
- <h4 id="packageis_toolchain">package:is_toolchain</h4>
- <ul>
- <li>Wether the package is of kind toolchain</li>
- </ul>
- <h4 id="packageis_library">package:is_library</h4>
- <ul>
- <li>Wether the package is of kind library</li>
- </ul>
- <h4 id="packageis_toplevel">package:is_toplevel</h4>
- <ul>
- <li>Wether the package is directly required by the user (e.g. xmake.lua)</li>
- </ul>
- <h4 id="packageis_thirdparty">package:is_thirdparty</h4>
- <ul>
- <li>Wether the package is provided by a thirdparty package manager (e.g. brew, conan, vcpkg)</li>
- </ul>
- <h4 id="packageis_debug">package:is_debug</h4>
- <ul>
- <li>Wether the package is build with debug mode (Same as <code>package:config("debug")</code>)</li>
- </ul>
- <h4 id="packageis_supported">package:is_supported</h4>
- <ul>
- <li>Wether the package is supported by the current platform and architecture</li>
- </ul>
- <h4 id="packagedebug">package:debug</h4>
- <ul>
- <li>Wether the the package gets built with debug mode (deprecated: use <a href="#packageis_debug"><code>package:is_debug</code></a> instead)</li>
- </ul>
- <h4 id="packageis_cross">package:is_cross</h4>
- <ul>
- <li>Wether the package is getting cross-compiled</li>
- </ul>
- <h4 id="packagecachedir">package:cachedir</h4>
- <ul>
- <li>Get the cache directory of the package</li>
- </ul>
- <h4 id="packageinstalldir">package:installdir</h4>
- <ul>
- <li>Get the installation directory of the package. Can also be used to get a subdirectory. If the given directory tree does not exist it will be created.</li>
- </ul>
- <pre><code class="lang-lua">-- returns the installation directory
- package:installdir()
- -- returns the subdirectory include inside the installation directory
- package:installdir("include")
- -- returns the subdirectory include/files
- package:installdir("include", "files")
- </code></pre>
- <h4 id="packagescriptdir">package:scriptdir</h4>
- <ul>
- <li>Get the directory where the xmake.lua of the package lies</li>
- </ul>
- <h4 id="packageenvs">package:envs</h4>
- <ul>
- <li>Get the exported environment variables of the package</li>
- </ul>
- <h4 id="packagegetenv">package:getenv</h4>
- <ul>
- <li>Get the given environment variable</li>
- </ul>
- <pre><code class="lang-lua">-- returns a table
- package:getenv("PATH")
- </code></pre>
- <h4 id="packagesetenv">package:setenv</h4>
- <ul>
- <li>Set the given environment variable. Overwrites the variable</li>
- </ul>
- <pre><code class="lang-lua">-- sets PATH to {"bin", "lib"}
- package:setenv("PATH", "bin", "lib")
- </code></pre>
- <h4 id="packageaddenv">package:addenv</h4>
- <ul>
- <li>Add the given values to the environment variable</li>
- </ul>
- <pre><code class="lang-lua">-- adds "bin" and "lib" to PATH
- package:addenv("PATH", "bin", "lib")
- </code></pre>
- <h4 id="packageversions">package:versions</h4>
- <ul>
- <li>Get all version strings of the package. Returns a table containing all versions as strings</li>
- </ul>
- <h4 id="packageversion">package:version</h4>
- <ul>
- <li>Get the version of the package</li>
- </ul>
- <pre><code class="lang-lua">local version = package:version()
- -- get the major version
- version:major()
- -- get the minor version
- version:minor()
- -- get the patch version
- version:patch()
- </code></pre>
- <h4 id="packageversion_str">package:version_str</h4>
- <ul>
- <li>Get the version of the package as string</li>
- </ul>
- <h4 id="packageconfig">package:config</h4>
- <ul>
- <li>Get the given configuration value of the package</li>
- </ul>
- <pre><code class="lang-lua">-- if configurations are set like so
- add_require("example", {configs = {enable_x = true, value_y = 6}})
- -- these values can be retrieved like so
- -- returns true
- package:config("enable_x")
- -- returns 6
- package:config("value_y")
- </code></pre>
- <h4 id="packageconfig_set">package:config_set</h4>
- <ul>
- <li>Set the given configuration value of the package</li>
- </ul>
- <pre><code class="lang-lua">package:config_set("enable_x", true)
- package:config_set("value_y", 6)
- </code></pre>
- <h4 id="packageconfigs">package:configs</h4>
- <ul>
- <li>Get all configurations of the package</li>
- </ul>
- <pre><code class="lang-lua">-- returns a table with the configuration names as keys and their values as values
- local configs = package:configs()
- local enable_x = configs["enable_x"]
- local value_y = configs["value_y"]
- </code></pre>
- <h4 id="packagebuildhash">package:buildhash</h4>
- <ul>
- <li>Get the build hash of the package</li>
- </ul>
- <h4 id="packagepatches">package:patches</h4>
- <ul>
- <li>Get all patches of the current version</li>
- </ul>
- <pre><code class="lang-lua">-- returns a table with all patches
- local patches = package:patches()
- -- each element contains the keys "url" and "sha256"
- local url = patches[1]["url"]
- local sha256 = patches[1]["sha256"]
- </code></pre>
- <h4 id="packagehas_cfuncs">package:has_cfuncs</h4>
- <ul>
- <li>Wether the package has the given C functions</li>
- </ul>
- <p>This should be used inside <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_cfuncs("foo"))
- -- you can also add configs
- assert(package:has_cfuncs("bar", {includes = "foo_bar.h"}))
- assert(package:has_cfuncs("blob", {includes = "blob.h", configs = {defines = "USE_BLOB"}}))
- -- you can even set the language
- assert(package:has_cfuncs("bla", {configs = {languages = "c99"}}))
- end)
- </code></pre>
- <h4 id="packagehas_cxxfuncs">package:has_cxxfuncs</h4>
- <ul>
- <li>Wether the package has the given C++ functions</li>
- </ul>
- <p>This should be used inside <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_cxxfuncs("foo"))
- -- you can also add configs
- assert(package:has_cxxfuncs("bar", {includes = "foo_bar.hpp"}))
- assert(package:has_cxxfuncs("blob", {includes = "blob.hpp", configs = {defines = "USE_BLOB"}}))
- -- you can even set the language
- assert(package:has_cxxfuncs("bla", {configs = {languages = "cxx17"}}))
- end)
- </code></pre>
- <h4 id="packagehas_ctypes">package:has_ctypes</h4>
- <ul>
- <li>Wether the package has the given C types</li>
- </ul>
- <p>This should be used inside <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_ctypes("foo"))
- -- you can also add configs
- assert(package:has_ctypes("bar", {includes = "foo_bar.h"}))
- assert(package:has_ctypes("blob", {includes = "blob.h", configs = {defines = "USE_BLOB"}}))
- -- you can even set the language
- assert(package:has_ctypes("bla", {configs = {languages = "c99"}}))
- end)
- </code></pre>
- <h4 id="packagehas_cxxtypes">package:has_cxxtypes</h4>
- <ul>
- <li>Wether the package has the given C++ types</li>
- </ul>
- <p>This should be used inside <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_cxxtypes("foo"))
- -- you can also add configs
- assert(package:has_cxxtypes("bar", {includes = "foo_bar.hpp"}))
- assert(package:has_cxxtypes("blob", {includes = "blob.hpp", configs = {defines = "USE_BLOB"}}))
- -- you can even set the language
- assert(package:has_cxxtypes("bla", {configs = {languages = "cxx17"}}))
- end)
- </code></pre>
- <h4 id="packagehas_cincludes">package:has_cincludes</h4>
- <ul>
- <li>Wether the package has the given C header files</li>
- </ul>
- <p>This should be used in <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_cincludes("foo.h"))
- end)
- </code></pre>
- <h4 id="packagehas_cxxincludes">package:has_cxxincludes</h4>
- <ul>
- <li>Wether the package has the given C++ header files</li>
- </ul>
- <p>This should be used in <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:has_cxxincludes("foo.hpp"))
- end)
- </code></pre>
- <h4 id="packagecheck_csnippets">package:check_csnippets</h4>
- <ul>
- <li>Wether the given C snippet can be compiled and linked</li>
- </ul>
- <p>This should be used in <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:check_csnippets({test = [[
- #define USE_BLOB
- #include <blob.h>
- void test(int argc, char** argv) {
- foo bar;
- printf("%s", bar.blob);
- }
- ]]}, {configs = {languages = "c99"}, includes = "foo.h"}))
- end)
- </code></pre>
- <h4 id="packagecheck_cxxsnippets">package:check_cxxsnippets</h4>
- <ul>
- <li>Wether the given C++ snippet can be compiled and linked</li>
- </ul>
- <p>This should be used in <code>on_test</code> like so:</p>
- <pre><code class="lang-lua">on_test(function (package)
- assert(package:check_cxxsnippets({test = [[
- #define USE_BLOB
- #include <blob.hpp>
- void test(int argc, char** argv) {
- foo bar();
- std::cout << bar.blob;
- }
- ]]}, {configs = {languages = "cxx11"}, includes = "foo.hpp"}))
- end)
- </code></pre>
- <h4 id="packagecheck_fcsnippets">package:check_fcsnippets</h4>
- <ul>
- <li>Wether the given Fortran snippet can be compiled and linked</li>
- </ul>
- <p>see above</p>
- </article>
- </body>
- </html>
|