Alien-Xmake-Project

 view release on metacpan or  search on metacpan

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


Generates a config file from a C<.in> template.

=item C<set_configvar( $name, $value )>

    ...->set_configvar( 'HAVE_X', '1' )

Sets a config variable substituted into generated config files.

=item C<set_configdir( $dir )>

    ...->set_configdir( '$(projectdir)/config' )

Sets the directory into which generated config files are written.

=back

=item B<compile-time feature detection>

The full C<@builtin/check> helper family is wired in. The first call emits C<includes("@builtin/check")> at the project
root exactly once. Each helper renders C<def, arg> and passes list-style arguments (links, headers, types) as a single
Lua list rather than flattening them; a trailing hashref becomes the options table. Both the plain C<check_*> (defines
the macro) and C<configvar_check_*> (writes C<set_configvar> into the generated config) forms are provided across
C<links> C<syslinks> C<ctypes> C<cxxtypes> C<cfuncs> C<cxxfuncs> C<cincludes> C<cxxincludes> C<csnippets>
C<cxxsnippets> C<features> C<macros> C<sizeof> C<alignof> C<bigendian> C<cflags> C<cxxflags>:

    ...->add_configfiles( 'config.h.in', { filename => 'config.h' } )
    ...->configvar_check_links( 'HAS_PTHREAD', [ 'pthread', 'm', 'dl' ] )
    ...->configvar_check_ctypes( 'HAS_WCHAR', 'wchar_t' )

  with C<config.h.in>:

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



( run in 1.711 second using v1.01-cache-2.11-cpan-54e63673c56 )