CC: | rehsack [...] googlemail.com |
Subject: | [PATCH] Compile C++ with new features of ExtUtils::CBuilder 0.27_04 |
Submitted by Jens Rehsack.
I would like to have tests for this patch before committing it.
-- David
Subject: | patch-use-cxx-to-compile-c++-source.patch |
Index: lib/Module/Build/Base.pm
===================================================================
--- lib/Module/Build/Base.pm (revision 13899)
+++ lib/Module/Build/Base.pm (working copy)
@@ -2728,20 +2728,32 @@
my $p = $self->{properties};
return unless $p->{c_source};
- my $files;
+ my $cfiles;
+ my $cxxfiles;
if (ref($p->{c_source}) eq "ARRAY") {
push @{$p->{include_dirs}}, @{$p->{c_source}};
for my $path (@{$p->{c_source}}) {
- push @$files, @{ $self->rscan_dir($path, file_qr('\.c(c|p|pp|xx|\+\+)?$')) };
+ push @$cfiles, @{ $self->rscan_dir($path, file_qr('\.c$')) };
+ push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.c(c|p|pp|xx|\+\+)$')) };
+ unless( $self->{fs_ignore_case} } ) {
+ push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.C(C|P|PP|XX|\+\+)?$')) };
+ }
}
} else {
push @{$p->{include_dirs}}, $p->{c_source};
- $files = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$'));
+ $cfiles = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$'));
+ $cxxfiles = $self->rscan_dir($p->{c_source}, file_qr('\.c(c|p|pp|xx|\+\+)?$'));
+ unless( $self->{fs_ignore_case} } ) {
+ push @cxx$files, @{ $self->rscan_dir($path, file_qr('\.C(C|P|PP|XX|\+\+)?$')) };
+ }
}
- foreach my $file (@$files) {
+ foreach my $file (@$cfiles) {
push @{$p->{objects}}, $self->compile_c($file);
}
+ foreach my $file (@$cxxfiles) {
+ push @{$p->{objects}}, $self->compile_cxx($file);
+ }
}
sub process_share_dir_files {
@@ -4909,18 +4921,31 @@
my $p = $self->{properties};
return $p->{_have_c_compiler} if defined $p->{_have_c_compiler};
- $self->log_verbose("Checking if compiler tools configured... ");
+ $self->log_verbose("Checking if c compiler tools configured... ");
my $b = eval { $self->cbuilder };
my $have = $b && eval { $b->have_compiler };
$self->log_verbose($have ? "ok.\n" : "failed.\n");
return $p->{_have_c_compiler} = $have;
}
+sub have_cxx_compiler {
+ my ($self) = @_;
+
+ my $p = $self->{properties};
+ return $p->{_have_cxx_compiler} if defined $p->{_have_cxx_compiler};
+
+ $self->log_verbose("Checking if c++ compiler tools configured... ");
+ my $b = eval { $self->cbuilder };
+ my $have = $b && eval { $b->have_cplusplus };
+ $self->log_verbose($have ? "ok.\n" : "failed.\n");
+ return $p->{_have_cxx_compiler} = $have;
+}
+
sub compile_c {
my ($self, $file, %args) = @_;
if ( ! $self->have_c_compiler ) {
- die "Error: no compiler detected to compile '$file'. Aborting\n";
+ die "Error: no c compiler detected to compile '$file'. Aborting\n";
}
my $b = $self->cbuilder;
@@ -4938,6 +4963,29 @@
return $obj_file;
}
+sub compile_cxx {
+ my ($self, $file, %args) = @_;
+
+ if ( ! $self->have_cxx_compiler ) {
+ die "Error: no c++ compiler detected to compile '$file'. Aborting\n";
+ }
+
+ my $b = $self->cbuilder;
+ my $obj_file = $b->object_file($file);
+ $self->add_to_cleanup($obj_file);
+ return $obj_file if $self->up_to_date($file, $obj_file);
+
+ $b->compile(source => $file,
+ defines => $args{defines},
+ object_file => $obj_file,
+ include_dirs => $self->include_dirs,
+ extra_compiler_flags => $self->extra_compiler_flags,
+ 'C++' => 1,
+ );
+
+ return $obj_file;
+}
+
sub link_c {
my ($self, $spec) = @_;
my $p = $self->{properties}; # For convenience
@@ -4961,6 +5009,10 @@
return $spec->{lib_file};
}
+sub link_cxx {
+ goto &link_c;
+}
+
sub compile_xs {
my ($self, $file, %args) = @_;