Alien-ROOT
view release on metacpan or search on metacpan
inc/inc_Module-Build/Module/Build/WithXSpp.pm view on Meta::CPAN
package Module::Build::WithXSpp;
use strict;
use warnings;
use Module::Build;
use ExtUtils::CppGuess ();
our @ISA = qw(Module::Build);
our $VERSION = '0.12';
# TODO
# - configurable set of xsp and xspt files (and XS typemaps?)
# => works via directories for now.
# - configurable includes/C-preamble for the XS?
# => Works in the .xsp files, but the order of XS++ inclusion
# is undefined.
# - configurable C++ source folder(s) (works, needs docs)
# => to be documented another time. This is really not a feature that
# should be commonly used.
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
# This gives us the correct settings for the C++ compile (hopefully)
my $guess = ExtUtils::CppGuess->new();
if (defined $args{extra_compiler_flags}) {
if (ref($args{extra_compiler_flags})) {
$guess->add_extra_compiler_flags($_) for @{$args{extra_compiler_flags}};
}
else {
$guess->add_extra_compiler_flags($args{extra_compiler_flags})
}
delete $args{extra_compiler_flags};
}
if (defined $args{extra_linker_flags}) {
if (ref($args{extra_linker_flags})) {
$guess->add_extra_linker_flags($_) for @{$args{extra_linker_flags}};
}
else {
$guess->add_extra_linker_flags($args{extra_linker_flags})
}
delete $args{extra_linker_flags};
}
# add the typemap modules to the build dependencies
my $build_requires = $args{build_requires}||{};
my $extra_typemap_modules = $args{extra_typemap_modules}||{};
# FIXME: This prevents any potential subclasses from fudging with the extra typemaps?
foreach my $module (keys %$extra_typemap_modules) {
if (not defined $build_requires->{$module}
or defined($extra_typemap_modules->{$module})
&& $build_requires->{$module} < $extra_typemap_modules->{$module})
{
$build_requires->{$module} = $extra_typemap_modules->{$module};
}
}
$args{build_requires} = $build_requires;
# Construct object using C++ options guess
my $self = $class->SUPER::new(
%args,
$guess->module_build_options # FIXME find a way to let the user override this
);
push @{$self->extra_compiler_flags},
map "-I$_",
(@{$self->cpp_source_dirs||[]}, $self->build_dir);
$self->_init(\%args);
return $self;
}
sub _init {
my $self = shift;
my $args = shift;
}
sub auto_require {
my ($self) = @_;
my $p = $self->{properties};
if ($self->dist_name ne 'Module-Build-WithXSpp'
and $self->auto_configure_requires)
{
if (not exists $p->{configure_requires}{'Module::Build::WithXSpp'}) {
(my $ver = $VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only
$self->_add_prereq('configure_requires', 'Module::Build::WithXSpp', $ver);
}
if (not exists $p->{configure_requires}{'ExtUtils::CppGuess'}) {
(my $ver = $ExtUtils::CppGuess::VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only
$self->_add_prereq('configure_requires', 'ExtUtils::CppGuess', $ver);
}
if (not exists $p->{build_requires}{'ExtUtils::CppGuess'}
and eval("require ExtUtils::XSpp;")
and defined $ExtUtils::XSpp::VERSION)
{
(my $ver = $ExtUtils::XSpp::VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only
$self->_add_prereq('build_requires', 'ExtUtils::XSpp', $ver);
}
}
$self->SUPER::auto_require();
return;
}
sub ACTION_create_buildarea {
my $self = shift;
mkdir($self->build_dir);
$self->add_to_cleanup($self->build_dir);
}
sub ACTION_code {
my $self = shift;
$self->depends_on('create_buildarea');
$self->depends_on('generate_typemap');
$self->depends_on('generate_main_xs');
my $files = {};
foreach my $ext (qw(c cc cxx cpp C)) {
foreach my $dir (@{$self->cpp_source_dirs||[]}) {
my $this = $self->_find_file_by_type($ext, $dir);
$files = $self->_merge_hashes($files, $this);
}
inc/inc_Module-Build/Module/Build/WithXSpp.pm view on Meta::CPAN
You do not have to set these dependencies yourself unless
you need to set the required versions manually.
=head2 Include files
Unfortunately, including the perl headers produces quite some pollution and
redefinition of common symbols. Therefore, it may be necessary to include
some of your headers before including the perl headers. Specifically,
this is the case for MSVC compilers and the standard library headers.
Therefore, if you care about that platform in the least, you should use the C<early_includes>
option when creating a C<Module::Build::WithXSpp> object to list headers
to include before the perl headers. If such a supplied header file starts with
a double quote, C<#include "..."> is used, otherwise C<#include E<lt>...E<gt>>
is the default. Example:
Module::Build::WithXSpp->new(
early_includes => [qw(
"mylocalheader.h"
<mysystemheader.h>
)]
)
=head1 JUMP START FOR THE IMPATIENT
There are as many ways to start a new CPAN distribution as there
are CPAN distributions. Choose your favourite
(I just do C<h2xs -An My::Module>), then apply a few
changes to your setup:
=over 2
=item *
Obliterate any F<Makefile.PL>.
This is what your F<Build.PL> should look like:
use strict;
use warnings;
use 5.006001;
use Module::Build::WithXSpp;
my $build = Module::Build::WithXSpp->new(
module_name => 'My::Module',
license => 'perl',
dist_author => q{John Doe <john_does_mail_address>},
dist_version_from => 'lib/My/Module.pm',
build_requires => { 'Test::More' => 0, },
extra_typemap_modules => {
'ExtUtils::Typemaps::ObjectMap' => '0',
# ...
},
);
$build->create_build_script;
If you need to link against some library C<libfoo>, add this to
the options:
extra_linker_flags => [qw(-lfoo)],
There is C<extra_compiler_flags>, too, if you need it.
=item *
You create two folders in the main distribution folder:
F<src> and F<xsp>.
=item *
You put any C++ code that you want to build and include
in the module into F<src/>. All the typical C(++) file
extensions are recognized and will be compiled to object files
and linked into the module. And headers in that folder will
be accessible for C<#include E<lt>myheader.hE<gt>>.
For good measure, move a copy of F<ppport.h> to that directory.
See L<Devel::PPPort>.
=item *
You do not write normal XS files. Instead, you write XS++ and
put it into the F<xsp/> folder in files with the C<.xsp>
extension. Do not worry, you can include verbatim XS blocks
in XS++. For details on XS++, see L<ExtUtils::XSpp>.
=item *
If you need to do any XS type mapping, put your typemaps
into a F<.map> file in the C<xsp> directory. Alternatively,
search CPAN for an appropriate typemap module (cf.
L<ExtUtils::Typemaps::Default> for an explanation).
XS++ typemaps belong into F<.xspt> files in the same directory.
=item *
In this scheme, F<lib/> only contains Perl module files (and POD).
If you started from a pure-Perl distribution, don't forget to add
these magic two lines to your main module:
require XSLoader;
XSLoader::load('My::Module', $VERSION);
=back
=head1 SEE ALSO
L<Module::Build> upon which this module is based.
L<ExtUtils::XSpp> implements XS++. The C<ExtUtils::XSpp> distribution
contains an F<examples> directory with a usage example of this module.
L<ExtUtils::Typemaps> implements progammatic modification (merging)
of C/XS typemaps. C<ExtUtils::Typemaps> was renamed from C<ExtUtils::Typemap>
since the original name conflicted with the core F<typemap> file on
case-insensitive file systems.
L<ExtUtils::Typemaps::Default> explains the concept of having typemaps
shipped as modules.
L<ExtUtils::Typemaps::ObjectMap> is such a typemap module and
probably very useful for any XS++ module.
( run in 0.361 second using v1.01-cache-2.11-cpan-119454b85a5 )