Alien-Xmake-Project
view release on metacpan or search on metacpan
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 )`
- **content and deps**
Otherwise-identical statements grouped by shared semantics; each is chainable.
- `add_files( @patterns )`
```
...->add_files( 'src/*.cpp' )
```
Adds source files or glob patterns to compile.
- `remove_files( @patterns )`
```
...->remove_files( 'src/old.cpp' )
```
Removes source files/patterns previously added.
- `remove_headerfiles( @files )`
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' )
eg/xmake_project.pl view on Meta::CPAN
int main() {
std::puts("hello from Alien::Xmake::Project");
return 0;
}
CPP
my $p = Alien::Xmake::Project->new(
file => 'xmake.lua', # where save() writes the build file
yes => 1 # auto-confirm prompts (never hang on a TTY)
);
# project identity at the global scope
$p->set_project('demo')->set_version('0.1.0')->set_xmakever('3.1.1');
$p->add_rules( 'mode.debug', 'mode.release' );
# Targets:
# target() returns a builder; every set_*/add_* call returns it too, so the
# whole description is one long chain. add_requires() would pull from xrepo
# (needs network) - omitted here to keep the demo building offline.
$p->target('demo')
->set_kind('binary')
->set_languages('c++20')
lib/Alien/Xmake/Project.pm view on Meta::CPAN
method add_requireconfs (@args) {
push @$root, Alien::Xmake::Project::Util::_stmt( 'add_requireconfs', @args );
$self;
}
method add_repositories (@args) {
push @$root, Alien::Xmake::Project::Util::_stmt( 'add_repositories', @args );
$self;
}
# scope root/global statements behind a Lua condition (see ::Target::when).
method when ( $predicate, $body ) {
my $start = @$root;
if ( ref($body) eq 'ARRAY' ) { push @$root, @$body; }
elsif ( ref($body) eq 'CODE' ) { $body->($self); }
elsif ( defined $body ) { push @$root, $body; }
my @inner = @$root[ $start .. $#$root ];
@$root = @$root[ 0 .. $start - 1 ];
push @$root, "if $predicate then";
push @$root, map {" $_"} @inner;
push @$root, 'end';
lib/Alien/Xmake/Project.pod view on Meta::CPAN
=back
=head3 Global options and defaults
=over
=item C<set_config( $name, $value )>
...->set_config( 'plat', 'windows' )
Sets a global configuration item that applies to the whole project.
=item C<set_defaultplat( @plats )>
...->set_defaultplat( 'windows' )
Sets the default platform used when none is given on the command line.
=item C<set_defaultarchs( @archs )>
...->set_defaultarchs( 'x86_64' )
lib/Alien/Xmake/Project.pod view on Meta::CPAN
=item B<content and deps>
Otherwise-identical statements grouped by shared semantics; each is chainable.
=over
=item C<add_files( @patterns )>
...->add_files( 'src/*.cpp' )
Adds source files or glob patterns to compile.
=item C<remove_files( @patterns )>
...->remove_files( 'src/old.cpp' )
Removes source files/patterns previously added.
=item C<remove_headerfiles( @files )>
...->remove_headerfiles( 'src/old.h' )
lib/Alien/Xmake/Project.pod view on Meta::CPAN
emits:
if is_plat("windows", "linux") then
add_links("pthread", "m", "dl")
end
if is_arch("arm.*") then
add_defines("ARM")
end
C<when> is also available at the project (root/global) scope to guard C<add_rules>/C<add_requires>/C<includes> and any
root statement.
=item B<raw hooks and escape hatch>
Hooks take raw Lua function bodies: C<on_load> C<on_config> C<on_build> C<on_build_file> C<before_build> C<after_build>
C<on_link> C<on_clean> C<on_install> C<on_uninstall> C<on_run>. Strings that begin with C<function> are emitted
unquoted; other strings are quoted and joined as arguments:
...->on_build( 'function (target) print(target:name()) end' )
...->on_install( 'windows', 'function (target) end' )
( run in 0.799 second using v1.01-cache-2.11-cpan-1236ad508bc )