QMake-Project
view release on metacpan or search on metacpan
lib/QMake/Project.pm view on Meta::CPAN
return $out;
}
# Given a qmake $command line (single string containing both command and args),
# parses it and returns a hashref with the following:
#
# qmake => path to the qmake binary
# makefile => path to the makefile
# projectfiles => arrayref, paths to the project (.pro) file(s)
# args => arrayref, all args not covered by any of the above
#
sub _parse_qmake_command
{
my ($self, $command) = @_;
my $qmake;
my $makefile;
my @projectfiles;
my @args;
# Getopt callbacks to accept a known qmake option onto @args
my $sub_accept_option_with_value = sub {
# Getopt already removes the -, we need to put it back
my ($option, $value) = @_;
push @args, "-$option", "$value";
};
my $sub_accept_option_without_value = sub {
my ($option) = @_;
push @args, "-$option";
};
# Getopt callback to accept an unknown qmake argument.
# This includes determining whether the argument should be handled as a
# .pro file; the logic for this must match qmake's own logic in option.cpp.
my $sub_accept_nonoption = sub {
my ($arg) = @_;
if ($arg =~ m{=}) {
# Arg containing '=' => it is a user variable assignment.
# Nothing special to be done.
push @args, $arg;
}
elsif ($arg =~ m{^-}) {
# Arg starts with '-' => it is probably a qmake argument we haven't
# handled. For example, a new qmake argument added after this
# script was created. In this case, our code needs to be updated
# to handle it safely, so we'll warn about it, then keep going.
warn __PACKAGE__ . ": in ($command), the meaning of $arg is unknown.\n";
push @args, $arg;
}
else {
# Otherwise, it is a .pro file.
push @projectfiles, $arg;
}
};
Getopt::Long::Configure( 'permute', 'pass_through' );
{
local @ARGV = $self->_split_command_to_words( $command );
# The first element is the qmake binary itself
$qmake = shift @ARGV;
GetOptions(
# All of these options are directly accepted into @args with no
# special behavior
map( { $_ => $sub_accept_option_without_value } qw(
project
makefile
Wnone
Wall
Wparser
Wlogic
Wdeprecated
d
help
v
after
norecursive
recursive
nocache
nodepend
nomoc
nopwd
macx
unix
win32
)),
map( { $_ => $sub_accept_option_with_value } qw(
unset=s
query=s
cache=s
spec=s
t=s
tp=s
)),
# "-o <Makefile>" tells us which makefile to use
'o=s' => sub { (undef, $makefile) = @_ },
# anything else should be either a variable assignment or
# a .pro file, pass it to our function for handling these
'<>' => $sub_accept_nonoption,
) || croak __PACKAGE__.": command ($command) could not be parsed";
}
return {
qmake => $qmake,
makefile => $makefile,
projectfiles => \@projectfiles,
args => \@args,
};
}
# Given a single string representing a qmake command, split it into
# a list of arguments as qmake's own main() would receive
sub _split_command_to_words
{
my ($self, $cmd) = @_;
( run in 0.422 second using v1.01-cache-2.11-cpan-ff9377addf4 )