Alien-Xmake-Project

 view release on metacpan or  search on metacpan

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

    ...->set_project( 'libobseum' )

Sets the project name at the top of the build file.

=item C<set_version( $version )>

    ...->set_version( '0.1.0' )

Sets the project version string.

=item C<set_xmakever( $version )>

    ...->set_xmakever( '2.9.1' )

Sets the minimum xmake version required to build the project.

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

Sets the default architectures used when none are given.

=item C<set_defaultmode( @modes )>

    ...->set_defaultmode( 'release' )

Sets the default build mode(s) used when none are given.

=item C<set_allowedplats( @plats )>

    ...->set_allowedplats( 'windows', 'linux', 'macosx' )

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

=head3 Global scope (applies to every target)

=over

=item C<set_toolchains( @names )>

    ...->set_toolchains( 'clang' )

Declares the toolchain(s) to use project-wide.

=item C<set_toolset( %pairs )>

    ...->set_toolset( cc => 'gcc', cxx => 'g++' )

Sets the tool programs used by the toolchain, as a table of C<name =E<gt> program> pairs.

=item C<set_plat( $plat )>

    ...->set_plat( 'windows' )

Pins the target platform for the whole project.

=item C<set_arch( $arch )>

    ...->set_arch( 'x86_64' )

Pins the target architecture for the whole project.

=item C<set_languages( @langs )>

    ...->set_languages( 'c99', 'cxx11' )

Sets the language standards for every target.

=back

=head3 Structure

=over

=item C<add_moduledirs( @dirs )>

    ...->add_moduledirs( 'modules' )

Adds extra module search directories.

=item C<add_plugindirs( @dirs )>

    ...->add_plugindirs( 'plugins' )

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

=head3 Packages and repositories

=over

=item C<add_requires( @packages )>

    ...->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 C<true>/C<false> (xmake expects C<true>, not C<1>).

=item C<add_requireconfs( @configs )>

    ...->add_requireconfs( 'zlib', { configs => { shared => true } } )

Overrides requirement configs. Accepts a trailing options hashref.

=item C<add_repositories( @repos )>

    ...->add_repositories( 'myrepo', 'https://github.com/user/repo' )

Registers package repositories. Accepts a trailing options hashref.

=back

=head3 Domain builders

=over

=item C<target( $name )>

    ...->target( 'app' )

Begins a C<target(...)> block and returns a L</Target builder>.

=item C<option( $name )>

    ...->option( 'with_foo' )

Begins a C<option(...)> block and returns the L</Option builder>. Passing a trailing hashref instead emits the inline
table form.

=item C<rule( $name )>

    ...->rule( 'markdown' )

Begins a C<rule(...)> block and returns the L</Rule builder>.

=item C<toolchain( $name )>

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

    ...->show( 'host' )

Runs C<xmake show> queries via L<Alien::Xmake/show> and returns the parsed results (a list of lines, a list of names
for list queries, or a decoded structure when C<format =E<gt> 'json'>).

=back

=head2 Target builder

Each method is chainable and corresponds to the same-named C<xmake.lua> statement inside a C<target(...)> block. A
trailing hashref is emitted as an options table; C<true>/C<false> emit bare Lua booleans.

=over

=item C<set_kind( $kind )>

    ...->set_kind( 'binary' )

Sets the kind of target: C<binary> (executable), C<static>, C<shared>, C<object>, C<headeronly>, C<phony>.

=over

=item B<naming and output>

=over

=item C<set_basename( $name )>

    ...->set_basename( 'myapp' )

Overrides the base (file) name of the generated target.

=item C<set_filename( $name )>

    ...->set_filename( 'myapp.exe' )

Overrides the full file name of the generated binary/library, including extension if desired.

=item C<set_prefixname( $name )>

    ...->set_prefixname( 'lib' )   # static lib -> libfoo.a

Sets the prefix prepended to the target output file name.

=item C<set_suffixname( $name )>

    ...->set_suffixname( 'd' )     # myapp -> myappd

Sets the suffix appended to the target output file name.

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

Sets the directory for intermediate object files.

=item C<set_dependir( $dir )>

    ...->set_dependir( '$(builddir)/.deps' )

Sets the directory for compile dependency (C<.deps>) files.

=item C<set_installdir( $dir )>

    ...->set_installdir( '$(buildir)/lib' )

Sets the directory into which the target's install files are placed on C<install>.

=item C<set_prefixdir( $dir )>

    ...->set_prefixdir( 'usr/local' )

Sets the directory to strip as a prefix when installing relative paths.

=back

=item B<enablement and options>

=over

=item C<set_default( $bool )>

    ...->set_default( false )

Sets whether the target is built by default. Pass a real C<false> to opt out.

=item C<set_enabled( $bool )>

    ...->set_enabled( true )

Sets whether the target is enabled at all; a disabled target is not built or used.

=item C<set_options( @opts )>

    ...->set_options( 'with_foo' )

Makes the target depend on the named project C<option(...)> values.

=item C<add_options( @opts )>

    ...->add_options( 'with_bar' )

Adds additional C<option(...)> requirement(s) to the target.

=back

=item B<compile model>

=over

=item C<set_warnings( $level )>

    ...->set_warnings( 'all' )

Sets the compiler warning level; xmake maps the abstract level to the right flag per compiler. Available levels:
C<none>, C<less>, C<more>, C<extra>, C<pedantic>, C<all>, C<allextra>, C<everything>, C<error>.

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

    ...->set_exceptions( 'cxx' )

Enables or disables C++ / Objective-C exceptions: C<cxx>, C<no-cxx>, C<objc>, C<no-objc>. xmake picks the
compiler-specific flag.

=item C<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 C<source:> or
C<target:> for one side.

=item C<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.

=item C<set_pcheader( $header )>

    ...->set_pcheader( 'common.h' )

Sets the C precompiled header.

=item C<set_pcxxheader( $header )>

    ...->set_pcxxheader( 'common.hpp' )

Sets the C++ precompiled header.

=item C<set_pmheader( $header )>

    ...->set_pmheader( 'common.h' )

Sets the Objective-C precompiled header.

=item C<set_pmxxheader( $header )>

    ...->set_pmxxheader( 'common.hh' )

Sets the Objective-C++ precompiled header.

=item C<set_runtimes( @runtimes )>

    ...->set_runtimes( 'MD' )

Sets the runtime library flavour(s). On MSVC this selects the C runtime: C<MT>, C<MTd>, C<MD>, C<MDd>; on Android/iOS
it selects the C++ STL implementation: C<c++_static>, C<c++_shared>.

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


    ${define HAS_PTHREAD}
    ${define HAS_WCHAR}

=item B<scoped conditions (when)>

C<when( $condition, $body )> wraps a group of statements in a Lua C<if/then/end> block so they only apply when a
compile-time predicate holds (C<is_plat> C<is_os> C<is_arch> C<is_host> C<is_mode> C<is_kind> C<is_config>
C<has_config> C<has_package>, or any Lua expression, including negations like C<not is_plat("windows")>). C<$body> is a
code ref whose C<->E<gt>...>> 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 C<end> closes the block:

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

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

C<lua( @lines )> pushes raw Lua lines straight into the target body (escape hatch).

=back

=back

=head2 Option builder

An C<option(...)> block describes a configurable build option. Every method is chainable. A trailing hashref becomes an
options table; C<true>/C<false> emit bare Lua booleans. Note that an option created with the inline table form (C<<
option('name', { ... }) >>) cannot be extended with these setters.

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

    ...->set_category( 'Features' )

Groups the option under a category in the menu.

=item C<set_description( $text )>

    ...->set_description( 'Enable the foo feature' )

Sets a human-readable description shown in the menu.

=item C<add_deps( @opts )>

    ...->add_deps( 'with_toolchain' )

Requires the named other options to be resolved first.

=item C<add_links( @libs )>

    ...->add_links( 'm', 'dl' )

Adds libraries the option links when enabled.

=item C<add_linkdirs( @dirs )>

    ...->add_linkdirs( 'lib' )

Adds library search directories for the option.

=item C<add_rpathdirs( @dirs )>

    ...->add_rpathdirs( '$ORIGIN' )

Adds runtime library search directories for the option.

=item C<add_cincludes( @headers )>

    ...->add_cincludes( 'math.h' )

Probes for the presence of the given C headers.

=item C<add_cxxincludes( @headers )>

    ...->add_cxxincludes( 'vector' )

Probes for the presence of the given C++ headers.

=item C<add_ctypes( @types )>

    ...->add_ctypes( 'wchar_t' )

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

    ...->set_description( 'The core runtime library' )

Sets the description of the component.

=item C<set_default( $bool )>

    ...->set_default( true )

Sets whether the component is selected by default. Pass a real C<false> to deselect.

=item C<add_sourcefiles( @files )>

    ...->add_sourcefiles( 'src/*.c' )

Adds source files to this component.

=item C<add_installfiles( @files )>

    ...->add_installfiles( 'LICENSE' )

Adds extra install files to this component.

=item C<on_load( $body )>

    ...->on_load( 'function (component) end' )

Injects a raw-Lua hook (takes a raw Lua function body).

=item C<before_installcmd( $body )> C<on_installcmd( $body )> C<after_installcmd( $body )>
C<before_uninstallcmd( $body )> C<on_uninstallcmd( $body )> C<after_uninstallcmd( $body )>

    ...->on_installcmd( 'function (cmd) end' )

Injects raw-Lua hooks around the component's install/uninstall commands (each takes raw Lua function bodies). C<lua(
@lines )> pushes raw Lua lines straight into the component body.

=back

=head1 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:

    $t->add_files('src/*.cpp', { unity_group => 'core' });   # add_files("src/*.cpp", {["unity_group"]="core"})

Use the v5.36+ C<true>/C<false> keywords for booleans so xmake receives a real boolean, not the string C<"1">:

    $p->add_requires('zlib', { shared => true });

Key order in tables is deterministic (sorted).

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

=head1 SEE ALSO

L<Alien::Xmake>, the example in C<eg/xmake_project.pl>

=head1 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.

=head1 AUTHOR

Sanko Robinson L<https://github.com/sanko>

=cut



( run in 1.264 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )