Alien-CSFML
view release on metacpan or search on metacpan
lib/Alien/CSFML.pm view on Meta::CPAN
sub ldflags {
my ( $s, @args ) = @_;
@args = qw[graphics window audio network system] if !scalar @args;
CORE::state $pre;
$pre //= { # Windows dependencies
graphics => [
( ( $s->{'C++'} ? '' : 'c' ) . 'sfml-window' ),
( ( $s->{'C++'} ? '' : 'c' ) . 'sfml-system' ),
qw[opengl32 freetype]
],
window => [ ( ( $s->{'C++'} ? '' : 'c' ) . 'sfml-system' ), qw[opengl32 winmm gdi32] ],
audio => [
( ( $s->{'C++'} ? '' : 'c' ) . 'sfml-system' ),
qw[openal32 flac vorbisenc vorbisfile vorbis ogg]
],
network => [ ( ( $s->{'C++'} ? '' : 'c' ) . 'sfml-system' ), qw[ws2_32] ],
system => [qw[winmm]]
}
if $^O eq 'MSWin32';
join ' ', ' -L' . canonpath( catdir( dist_dir('Alien-CSFML'), 'sfml', 'lib' ) ), (
$s->{'C++'} ? '' : ' -L' . canonpath( catdir( dist_dir('Alien-CSFML'), 'csfml', 'lib' ) ) ),
(
map { '-l' . $_ } (
( grep {/^audio$/} @args ) ?
( @{ $pre->{audio} }, 'sfml-audio', ( $s->{'C++'} ? () : 'csfml-audio' ) ) :
()
), (
( grep {/^graphics$/} @args ) ?
( @{ $pre->{graphics} }, 'sfml-graphics', ( $s->{'C++'} ? () : 'csfml-graphics' ) )
:
()
), (
( grep {/^network$/} @args ) ?
( @{ $pre->{network} }, 'sfml-network', ( $s->{'C++'} ? () : 'csfml-network' ) ) :
()
), (
( grep {/^system$/} @args ) ?
( @{ $pre->{system} }, 'sfml-system', ( $s->{'C++'} ? () : 'csfml-system' ) ) :
()
), (
( grep {/^window$/} @args ) ?
( @{ $pre->{window} }, 'sfml-window', ( $s->{'C++'} ? () : 'csfml-window' ) ) :
()
),
);
}
1;
=pod
=encoding utf-8
=head1 NAME
Alien::CSFML - Build and provide access to the official binding of SFML for the
C language
=head1 Description
This distribution builds and installs CSFML; the official binding of SFML for
the C language. Its API is as close as possible to the C++ API (but in C style,
of course), which makes it a perfect tool for building SFML bindings for other
languages that don't directly support C++ libraries.
=head1 Synopsis
use Alien::CSFML;
use ExtUtils::CBuilder;
my $SF = Alien::CSFML->new( 'C++' => 1 );
my $CC = ExtUtils::CBuilder->new( quiet => 0 );
my $SRC = 'hello_world.cxx';
open( my $FH, '>', $SRC ) || die '...';
syswrite( $FH, <<'') || die '...'; close $FH;
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
my $OBJ = $CC->compile( 'C++' => 1, source => $SRC, include_dirs => [ $SF->include_dirs ] );
my $EXE = $CC->link_executable(
objects => $OBJ,
extra_linker_flags => ' -lstdc++ ' . $SF->ldflags(qw[graphics system window])
);
print system(
(
$^O eq 'MSWin32' ? '' :
'LD_LIBRARY_PATH=' . join( ':', '.', $SF->library_path(1) ) . ' '
) .
'./' . $EXE
) ? 'Aww...' : 'Yay!';
END { unlink grep defined, $SRC, $OBJ, $EXE; }
=head1 Constructor
my $AS = Alien::CSFML->new( );
Per-object configuration options are set in the constructor and include:
=over
=item C<C++>
Specifies that the source file is a C++ source file and sets appropriate
compile and linker flags.
=back
=head1 Methods
( run in 0.918 second using v1.01-cache-2.11-cpan-119454b85a5 )