Alien-Xmake-Project
view release on metacpan or search on metacpan
```
...->set_xmakever( '2.9.1' )
```
Sets the minimum xmake version required to build the project.
### Global options and defaults
- `set_config( $name, $value )`
```
...->set_config( 'plat', 'windows' )
```
Sets a global configuration item that applies to the whole project.
- `set_defaultplat( @plats )`
```
...->set_defaultplat( 'windows' )
```
Sets the default platform used when none is given on the command line.
- `set_defaultarchs( @archs )`
```
...->set_defaultarchs( 'x86_64' )
```
Sets the default architectures used when none are given.
- `set_defaultmode( @modes )`
```
...->set_defaultmode( 'release' )
```
Sets the default build mode(s) used when none are given.
- `set_allowedplats( @plats )`
```
...->set_allowedplats( 'windows', 'linux', 'macosx' )
```
Whitelists the platforms the project may be built for.
- `set_allowedarchs( @archs )`
```
...->set_allowedarchs( 'x86', 'x86_64' )
```
Whitelists the architectures the project may be built for.
- `set_allowedmodes( @modes )`
```
...->set_allowedmodes( 'debug', 'release' )
```
Whitelists the build modes the project supports.
- `set_runtimes( @runtimes )`
```
...->set_runtimes( 'MT', 'MD' )
```
Sets the runtime flavour(s), e.g. `MT`/`MD` on MSVC.
### Global scope (applies to every target)
- `set_toolchains( @names )`
```
...->set_toolchains( 'clang' )
```
Declares the toolchain(s) to use project-wide.
- `set_toolset( %pairs )`
```perl
...->set_toolset( cc => 'gcc', cxx => 'g++' )
```
Sets the tool programs used by the toolchain, as a table of `name => program` pairs.
- `set_plat( $plat )`
```
...->set_plat( 'windows' )
```
Pins the target platform for the whole project.
- `set_arch( $arch )`
```
...->set_arch( 'x86_64' )
```
Pins the target architecture for the whole project.
- `set_languages( @langs )`
```
...->set_languages( 'c99', 'cxx11' )
```
Sets the language standards for every target.
### Structure
- `add_moduledirs( @dirs )`
```
...->add_moduledirs( 'modules' )
```
Adds extra module search directories.
- `add_plugindirs( @dirs )`
```
...->add_plugindirs( 'plugins' )
```
Adds extra plugin search directories.
- `includes( @files )`
```
...->includes( 'build/config.lua' )
```
Includes other build files.
- `add_rules( @rules )`
```
...->add_rules( 'mode.debug', 'mode.release' )
```
Adds rule names to the whole project.
- `add_addons( @addons )`
```
...->add_addons( 'tools.xmake' )
```
Enables addons.
### Packages and repositories
- `add_requires( @packages )`
```perl
...->add_requires( 'zlib', { system => true } )
```
Adds project-wide package requirements. A trailing hashref becomes an options table; version strings pass through
verbatim, and booleans must be real `true`/`false` (xmake expects `true`, not `1`).
- `add_requireconfs( @configs )`
```perl
...->add_requireconfs( 'zlib', { configs => { shared => true } } )
```
Overrides requirement configs. Accepts a trailing options hashref.
- `add_repositories( @repos )`
```
...->add_repositories( 'myrepo', 'https://github.com/user/repo' )
```
Registers package repositories. Accepts a trailing options hashref.
### Domain builders
- `target( $name )`
```
...->target( 'app' )
```
Begins a `target(...)` block and returns a ["Target builder"](#target-builder).
- `option( $name )`
```
...->option( 'with_foo' )
```
Begins a `option(...)` block and returns the ["Option builder"](#option-builder). Passing a trailing hashref instead emits the inline
table form.
- `rule( $name )`
## Target builder
Each method is chainable and corresponds to the same-named `xmake.lua` statement inside a `target(...)` block. A
trailing hashref is emitted as an options table; `true`/`false` emit bare Lua booleans.
- `set_kind( $kind )`
```
...->set_kind( 'binary' )
```
Sets the kind of target: `binary` (executable), `static`, `shared`, `object`, `headeronly`, `phony`.
- **naming and output**
- `set_basename( $name )`
```
...->set_basename( 'myapp' )
```
Overrides the base (file) name of the generated target.
- `set_filename( $name )`
```
...->set_filename( 'myapp.exe' )
```
Overrides the full file name of the generated binary/library, including extension if desired.
- `set_prefixname( $name )`
```
...->set_prefixname( 'lib' ) # static lib -> libfoo.a
```
Sets the prefix prepended to the target output file name.
- `set_suffixname( $name )`
```
...->set_suffixname( 'd' ) # myapp -> myappd
```
Sets the suffix appended to the target output file name.
- `set_extension( $ext )`
```
...->set_extension( '.exe' )
```
Sets the output file extension; calling with no argument clears a toolchain default.
- `set_strip( $level )`
```
...->set_strip( 'all' )
```
Sets the strip mode applied at link time: `debug` (strip debug symbols only), `all` (strip all symbols), `none`.
Combined with `set_symbols('debug')`, a separate debug-symbol file (dSYM/pdb/.sym) is also generated.
- `set_group( $group )`
```
...->set_group( 'Library' )
```
Assigns the target to a project group, used by IDE generators to nest targets in folders.
- `set_objectdir( $dir )`
```
...->set_objectdir( '$(builddir)/.objs' )
```
Sets the directory for intermediate object files.
- `set_dependir( $dir )`
```
...->set_dependir( '$(builddir)/.deps' )
```
Sets the directory for compile dependency (`.deps`) files.
- `set_installdir( $dir )`
```
...->set_installdir( '$(buildir)/lib' )
```
Sets the directory into which the target's install files are placed on `install`.
- `set_prefixdir( $dir )`
```
...->set_prefixdir( 'usr/local' )
```
Sets the directory to strip as a prefix when installing relative paths.
- **enablement and options**
- `set_default( $bool )`
```
...->set_default( false )
```
Sets whether the target is built by default. Pass a real `false` to opt out.
- `set_enabled( $bool )`
```
...->set_enabled( true )
```
Sets whether the target is enabled at all; a disabled target is not built or used.
- `set_options( @opts )`
```
...->set_options( 'with_foo' )
```
Makes the target depend on the named project `option(...)` values.
- `add_options( @opts )`
```
...->add_options( 'with_bar' )
```
Adds additional `option(...)` requirement(s) to the target.
- **compile model**
- `set_warnings( $level )`
```
...->set_warnings( 'all' )
```
Sets the compiler warning level; xmake maps the abstract level to the right flag per compiler. Available levels:
`none`, `less`, `more`, `extra`, `pedantic`, `all`, `allextra`, `everything`, `error`.
- `set_optimize( $level )`
```
...->set_optimize( 'fastest' )
```
Sets the compile optimization level; each level maps to the appropriate flag for the target compiler. Available levels:
`none`, `fast`, `faster`, `fastest`, `smallest`, `aggressive`.
- `set_symbols( $level )`
```
...->set_symbols( 'debug' )
...->set_symbols( 'debug', 'hidden' )
```
Sets the debug-symbol mode. Levels may be combined: `none`, `debug`, `hidden`, plus the msvc-only refinements
`edit` and `embed`.
- `set_fpmodels( @models )`
```
...->set_fpmodels( 'fast', 'except' )
```
Sets the floating-point compilation mode: `fast`, `strict`, `except`, `noexcept`, `precise` (the default). Models
may be combined, but `fast` conflicts with `precise`/`strict`.
- `set_exceptions( @modes )`
```
...->set_exceptions( 'cxx' )
```
Enables or disables C++ / Objective-C exceptions: `cxx`, `no-cxx`, `objc`, `no-objc`. xmake picks the
compiler-specific flag.
- `set_encodings( @encodings )`
```
...->set_encodings( 'utf-8' )
...->set_encodings( 'source:utf-8', 'target:gb2312' )
```
Sets the source and/or target executable encoding. A bare encoding applies to both; prefix with `source:` or
`target:` for one side.
- `set_policy( $name, $value )`
```
...->set_policy( 'build.warning', true )
```
Sets a build policy for this target. See the xmake builtin-policies reference for the full list.
- `set_pcheader( $header )`
```
...->set_pcheader( 'common.h' )
```
Sets the C precompiled header.
- `set_pcxxheader( $header )`
```
...->set_pcxxheader( 'common.hpp' )
```
Sets the C++ precompiled header.
- `set_pmheader( $header )`
```
...->set_pmheader( 'common.h' )
```
${define HAS_PTHREAD}
${define HAS_WCHAR}
```
- **scoped conditions (when)**
`when( $condition, $body )` wraps a group of statements in a Lua `if/then/end` block so they only apply when a
compile-time predicate holds (`is_plat` `is_os` `is_arch` `is_host` `is_mode` `is_kind` `is_config`
`has_config` `has_package`, or any Lua expression, including negations like `not is_plat("windows")`). `$body` is a
code ref whose `-`>...>> chained calls back into the same builder, an arrayref of raw Lua lines, or a single raw
Lua line string. Inner statements are indented one level and `end` closes the block:
```perl
...->when( 'is_plat("windows", "linux")', sub {
...->add_links( 'pthread', 'm', 'dl' );
} )
...->when( 'is_arch("arm.*")', 'add_defines("ARM")' )
emits:
if is_plat("windows", "linux") then
add_links("pthread", "m", "dl")
end
if is_arch("arm.*") then
add_defines("ARM")
end
```
`when` is also available at the project (root/global) scope to guard `add_rules`/`add_requires`/`includes` and any
root statement.
- **raw hooks and escape hatch**
Hooks take raw Lua function bodies: `on_load` `on_config` `on_build` `on_build_file` `before_build` `after_build`
`on_link` `on_clean` `on_install` `on_uninstall` `on_run`. Strings that begin with `function` are emitted
unquoted; other strings are quoted and joined as arguments:
```js
...->on_build( 'function (target) print(target:name()) end' )
...->on_install( 'windows', 'function (target) end' )
```
`lua( @lines )` pushes raw Lua lines straight into the target body (escape hatch).
## Option builder
An `option(...)` block describes a configurable build option. Every method is chainable. A trailing hashref becomes an
options table; `true`/`false` emit bare Lua booleans. Note that an option created with the inline table form (`option('name', { ... })`) cannot be extended with these setters.
- `set_default( $value )`
```
...->set_default( true )
```
Sets the option's default value.
- `set_values( @vals )`
```
...->set_values( 'debug', 'release' )
```
Sets the list of allowed values for the option.
- `set_showmenu( $bool )`
```
...->set_showmenu( true )
```
Sets whether to show the option in the `xmake f --help` menu.
- `set_category( $category )`
```
...->set_category( 'Features' )
```
Groups the option under a category in the menu.
- `set_description( $text )`
```
...->set_description( 'Enable the foo feature' )
```
Sets a human-readable description shown in the menu.
- `add_deps( @opts )`
```
...->add_deps( 'with_toolchain' )
```
Requires the named other options to be resolved first.
- `add_links( @libs )`
```
...->add_links( 'm', 'dl' )
```
Adds libraries the option links when enabled.
- `add_linkdirs( @dirs )`
```
...->add_linkdirs( 'lib' )
```
Adds library search directories for the option.
- `add_rpathdirs( @dirs )`
```
...->add_rpathdirs( '$ORIGIN' )
```
Adds runtime library search directories for the option.
```
...->add_sourcefiles( 'src/*.c' )
```
Adds source files to this component.
- `add_installfiles( @files )`
```
...->add_installfiles( 'LICENSE' )
```
Adds extra install files to this component.
- `on_load( $body )`
```js
...->on_load( 'function (component) end' )
```
Injects a raw-Lua hook (takes a raw Lua function body).
- `before_installcmd( $body )` `on_installcmd( $body )` `after_installcmd( $body )`
`before_uninstallcmd( $body )` `on_uninstallcmd( $body )` `after_uninstallcmd( $body )`
```js
...->on_installcmd( 'function (cmd) end' )
```
Injects raw-Lua hooks around the component's install/uninstall commands (each takes raw Lua function bodies). `lua(
@lines )` pushes raw Lua lines straight into the component body.
# OPTION TABLES AND BOOLEANS
Any method that in xmake takes a trailing table accepts a Perl hashref as its last argument. It is rendered with
bracket keys so any string key is valid Lua:
```perl
$t->add_files('src/*.cpp', { unity_group => 'core' }); # add_files("src/*.cpp", {["unity_group"]="core"})
```
Use the v5.36+ `true`/`false` keywords for booleans so xmake receives a real boolean, not the string `"1"`:
```perl
$p->add_requires('zlib', { shared => true });
```
Key order in tables is deterministic (sorted).
# EXAMPLES
A dependency-driven executable and a shared library with a test, built from Perl:
```perl
use v5.40;
use Alien::Xmake::Project;
my $p = Alien::Xmake::Project->new(file => 'xmake.lua');
$p->set_project('app')->set_version('0.1.0');
$p->add_rules('mode.debug', 'mode.release');
$p->add_requires('zlib', { configs => { shared => true } });
$p->target('core')
->set_kind('shared')
->add_files('src/core/*.cpp')
->add_packages('zlib');
$p->target('app')
->set_kind('binary')
->add_files('src/main.cpp')
->add_deps('core')
->add_packages('zlib')
->set_languages('c++20')
->add_values('wasm.preloadfiles', 'src/assets/app.js')
->on_install('windows', 'function (target) end');
$p->save;
$p->xmake->configure(mode => 'release');
$p->xmake->build;
$p->xmake->test;
$p->xmake->project(kind => 'vsxmake'); # feed any IDE generator
```
# SEE ALSO
[Alien::Xmake](https://metacpan.org/pod/Alien%3A%3AXmake), the example in `eg/xmake_project.pl`
# LICENSE
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License
2\. Other copyrights, terms, and conditions may apply to data transmitted through this module.
# AUTHOR
Sanko Robinson [https://github.com/sanko](https://github.com/sanko)
( run in 2.738 seconds using v1.01-cache-2.11-cpan-c32d3c3b8f1 )