Alien-Xmake-Project

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN


    ```
    ...->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' )
    ```

README.md  view on Meta::CPAN


    ```
    ...->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' )
    ```

README.md  view on Meta::CPAN

            ```

            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 )`

README.md  view on Meta::CPAN

            ```
            ...->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`.

README.md  view on Meta::CPAN


    ```
    ...->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 )
    ```

README.md  view on Meta::CPAN

# 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')

eg/xmake_project.pl  view on Meta::CPAN

        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')
    ->set_warnings('all')
    ->set_optimize('fastest')

lib/Alien/Xmake/Project.pod  view on Meta::CPAN

Whitelists the platforms the project may be built for.

=item C<set_allowedarchs( @archs )>

    ...->set_allowedarchs( 'x86', 'x86_64' )

Whitelists the architectures the project may be built for.

=item C<set_allowedmodes( @modes )>

    ...->set_allowedmodes( 'debug', 'release' )

Whitelists the build modes the project supports.

=item C<set_runtimes( @runtimes )>

    ...->set_runtimes( 'MT', 'MD' )

Sets the runtime flavour(s), e.g. C<MT>/C<MD> on MSVC.

=back

lib/Alien/Xmake/Project.pod  view on Meta::CPAN

Adds extra plugin search directories.

=item C<includes( @files )>

    ...->includes( 'build/config.lua' )

Includes other build files.

=item C<add_rules( @rules )>

    ...->add_rules( 'mode.debug', 'mode.release' )

Adds rule names to the whole project.

=item C<add_addons( @addons )>

    ...->add_addons( 'tools.xmake' )

Enables addons.

=back

lib/Alien/Xmake/Project.pod  view on Meta::CPAN

=item C<set_extension( $ext )>

    ...->set_extension( '.exe' )

Sets the output file extension; calling with no argument clears a toolchain default.

=item C<set_strip( $level )>

    ...->set_strip( 'all' )

Sets the strip mode applied at link time: C<debug> (strip debug symbols only), C<all> (strip all symbols), C<none>.
Combined with C<set_symbols('debug')>, a separate debug-symbol file (dSYM/pdb/.sym) is also generated.

=item C<set_group( $group )>

    ...->set_group( 'Library' )

Assigns the target to a project group, used by IDE generators to nest targets in folders.

=item C<set_objectdir( $dir )>

    ...->set_objectdir( '$(builddir)/.objs' )

lib/Alien/Xmake/Project.pod  view on Meta::CPAN


=item C<set_optimize( $level )>

    ...->set_optimize( 'fastest' )

Sets the compile optimization level; each level maps to the appropriate flag for the target compiler. Available levels:
C<none>, C<fast>, C<faster>, C<fastest>, C<smallest>, C<aggressive>.

=item C<set_symbols( $level )>

    ...->set_symbols( 'debug' )
    ...->set_symbols( 'debug', 'hidden' )

Sets the debug-symbol mode. Levels may be combined: C<none>, C<debug>, C<hidden>, plus the msvc-only refinements
C<edit> and C<embed>.

=item C<set_fpmodels( @models )>

    ...->set_fpmodels( 'fast', 'except' )

Sets the floating-point compilation mode: C<fast>, C<strict>, C<except>, C<noexcept>, C<precise> (the default). Models
may be combined, but C<fast> conflicts with C<precise>/C<strict>.

=item C<set_exceptions( @modes )>

lib/Alien/Xmake/Project.pod  view on Meta::CPAN

=over

=item C<set_default( $value )>

    ...->set_default( true )

Sets the option's default value.

=item C<set_values( @vals )>

    ...->set_values( 'debug', 'release' )

Sets the list of allowed values for the option.

=item C<set_showmenu( $bool )>

    ...->set_showmenu( true )

Sets whether to show the option in the C<xmake f --help> menu.

=item C<set_category( $category )>

lib/Alien/Xmake/Project.pod  view on Meta::CPAN


=head1 EXAMPLES

A dependency-driven executable and a shared library with a test, built from 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')

t/001_project.t  view on Meta::CPAN

use Alien::Xmake::Project;
#
my $old = getcwd;
my $dir = path( tempdir( CLEANUP => 1 ) );
#
subtest 'Perl DSL emits a build file' => sub {
    my $p = Alien::Xmake::Project->new( file => "$dir/xmake.lua" );
    ok $p->set_project('dsl')->set_version('0.1.0') eq $p,     'top level chains return the project';
    ok $p->set_xmakever('2.9.1') eq $p,                        'xmakever chains';
    ok $p->add_requires( 'zlib' => { system => true } ) eq $p, 'project add_requires chains';
    ok $p->add_rules( 'mode.release', 'mode.debug' ) eq $p,    'project rules chain';
    my $t = $p->target('cli');
    isa_ok $t, ['Alien::Xmake::Project::Target'], 'target returns a Target builder';
    ok $t->set_kind('binary')->add_files('src/main.cpp') eq $t,                     'target methods chain';
    ok $t->set_languages('c++20')->set_warnings('all') eq $t,                       'target model methods chain';
    ok $t->add_packages('zlib')->add_values( 'wasm.preloadfiles' => 'a.js' ) eq $t, 'target deps/values chain';
    ok $t->configvar_check_links( 'HAS_PTHREAD', [ 'pthread', 'm' ] ) eq $t,        'configvar_check_links chains';
    ok $t->configvar_check_ctypes( 'HAS_WCHAR', 'wchar_t' ) eq $t,                  'configvar_check_ctypes chains';
    ok $t->check_cincludes( 'HAS_STRING_H', 'string.h' ) eq $t,                     'check_cincludes chains';
    ok $t->when( 'is_plat("windows")', sub { $t->add_links('user32') } ) eq $t,     'scoped condition block chains';
    my $o = $p->option('opt')->set_default('1')->add_links('z');

t/001_project.t  view on Meta::CPAN

    my $pk = $p->package('mypkg')->set_homepage('https://example.com')->on_install( 'windows', 'function (package) end' );
    isa_ok $pk, ['Alien::Xmake::Project::Package'], 'package returns a Package builder';
    my $n = $p->namespace( 'nn', 'add_rules("mode.release")' );
    isa_ok $n, ['Alien::Xmake::Project::Namespace'], 'namespace returns a Namespace builder';
    $p->save;
    ok -f "$dir/xmake.lua", 'save wrote the build file';
    my $lua = path("$dir/xmake.lua")->slurp_utf8;
    like $lua, qr/set_project\("dsl"\)/,                                       'project line emitted';
    like $lua, qr/set_xmakever\("2\.9\.1"\)/,                                  'xmakever emitted';
    like $lua, qr/add_requires\("zlib", \{\["system"\]=true\}\)/,              'project require with opts emitted';
    like $lua, qr/add_rules\("mode\.release", "mode\.debug"\)/,                'project rules emitted';
    like $lua, qr/target\("cli"\)/,                                            'target emitted';
    like $lua, qr/set_kind\("binary"\)/,                                       'kind emitted';
    like $lua, qr/add_files\("src\/main\.cpp"\)/,                              'files emitted';
    like $lua, qr/set_languages\("c\+\+20"\)/,                                 'languages emitted';
    like $lua, qr/set_warnings\("all"\)/,                                      'warnings emitted';
    like $lua, qr/add_packages\("zlib"\)/,                                     'packages emitted';
    like $lua, qr/add_values\("wasm\.preloadfiles", "a\.js"\)/,                'values emitted';
    like $lua, qr/configvar_check_links\("HAS_PTHREAD", \{"pthread", "m"\}\)/, 'configvar check links emitted';
    like $lua, qr/configvar_check_ctypes\("HAS_WCHAR", "wchar_t"\)/,           'configvar check ctypes emitted';
    like $lua, qr/check_cincludes\("HAS_STRING_H", "string\.h"\)/,             'check cincludes emitted';

t/001_project.t  view on Meta::CPAN

    );
    for my $c (@cases) {
        my ( $label, $input ) = @$c;
        my $lua    = Alien::Xmake::Project::Util::_lua_value($input);
        my $parsed = $x->lua_json( "return $lua", return => 1 );
        is $parsed, $input, "table renderer round-trips: $label";
    }

    # v5.36 boolean dualvars render as bare true/false; json round-trips them to
    # JSON::PP::Boolean objects (truthy for true, falsy for false).
    my $lua_bool = Alien::Xmake::Project::Util::_lua_value( { shared => !0, debug => !1 } );
    like $lua_bool, qr/\["shared"\]\s*=\s*true/, 'boolean true emitted bare true';
    like $lua_bool, qr/\["debug"\]\s*=\s*false/, 'boolean false emitted bare false';
    my $parsed_bool = $x->lua_json( "return $lua_bool", return => 1 );
    ok $parsed_bool->{shared} ? 1 : 0,     'boolean true round-trips truthy';
    ok !( $parsed_bool->{debug} ? 1 : 0 ), 'boolean false round-trips falsy';

    # A plain integer scalar is intentionally rendered as a quoted string.
    my $lua_int = Alien::Xmake::Project::Util::_lua_value( { count => 5 } );
    like $lua_int, qr/\["count"\]\s*=\s*"5"/, 'plain integer scalar is quoted';
};
#
subtest 'DSL project convenience execution methods' => sub {
    my $conv_dir = path( tempdir( CLEANUP => 1 ) );
    mkdir "$conv_dir/src" or die $!;
    path("$conv_dir/src/main.cpp")->spew_utf8("int main(){ return 0; }\n");



( run in 2.257 seconds using v1.01-cache-2.11-cpan-c32d3c3b8f1 )