contrib / buildsystems / Generators / QMake.pmon commit Merge branch 'mh/diff-indent-heuristic' (e704c61)
   1package Generators::QMake;
   2require Exporter;
   3
   4use strict;
   5use vars qw($VERSION);
   6
   7our $VERSION = '1.00';
   8our(@ISA, @EXPORT, @EXPORT_OK, @AVAILABLE);
   9@ISA = qw(Exporter);
  10
  11BEGIN {
  12    push @EXPORT_OK, qw(generate);
  13}
  14
  15sub generate {
  16    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
  17
  18    my @libs = @{$build_structure{"LIBS"}};
  19    foreach (@libs) {
  20        createLibProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
  21    }
  22
  23    my @apps = @{$build_structure{"APPS"}};
  24    foreach (@apps) {
  25        createAppProject($_, $git_dir, $out_dir, $rel_dir, %build_structure);
  26    }
  27
  28    createGlueProject($git_dir, $out_dir, $rel_dir, %build_structure);
  29    return 0;
  30}
  31
  32sub createLibProject {
  33    my ($libname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
  34    print "Generate $libname lib project\n";
  35    $rel_dir = "../$rel_dir";
  36
  37    my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_SOURCES"}})));
  38    my $defines = join(" \\\n\t", sort(@{$build_structure{"LIBS_${libname}_DEFINES"}}));
  39    my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"LIBS_${libname}_INCLUDES"}})));
  40    my $cflags  = join(" ", sort(@{$build_structure{"LIBS_${libname}_CFLAGS"}}));
  41
  42    my $cflags_debug = $cflags;
  43    $cflags_debug =~ s/-MT/-MTd/;
  44    $cflags_debug =~ s/-O.//;
  45
  46    my $cflags_release = $cflags;
  47    $cflags_release =~ s/-MTd/-MT/;
  48
  49    my @tmp  = @{$build_structure{"LIBS_${libname}_LFLAGS"}};
  50    my @tmp2 = ();
  51    foreach (@tmp) {
  52        if (/^-LTCG/) {
  53        } elsif (/^-L/) {
  54            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
  55        }
  56        push(@tmp2, $_);
  57    }
  58    my $lflags = join(" ", sort(@tmp));
  59
  60    my $target = $libname;
  61    $target =~ s/\//_/g;
  62    $defines =~ s/-D//g;
  63    $defines =~ s/"/\\\\"/g;
  64    $includes =~ s/-I//g;
  65    mkdir "$target" || die "Could not create the directory $target for lib project!\n";
  66    open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
  67    print F << "EOM";
  68TEMPLATE = lib
  69TARGET = $target
  70DESTDIR = $rel_dir
  71
  72CONFIG -= qt
  73CONFIG += static
  74
  75QMAKE_CFLAGS =
  76QMAKE_CFLAGS_RELEASE = $cflags_release
  77QMAKE_CFLAGS_DEBUG = $cflags_debug
  78QMAKE_LIBFLAGS = $lflags
  79
  80DEFINES += \\
  81        $defines
  82
  83INCLUDEPATH += \\
  84        $includes
  85
  86SOURCES += \\
  87        $sources
  88EOM
  89    close F;
  90}
  91
  92sub createAppProject {
  93    my ($appname, $git_dir, $out_dir, $rel_dir, %build_structure) = @_;
  94    print "Generate $appname app project\n";
  95    $rel_dir = "../$rel_dir";
  96
  97    my $sources = join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_SOURCES"}})));
  98    my $defines = join(" \\\n\t", sort(@{$build_structure{"APPS_${appname}_DEFINES"}}));
  99    my $includes= join(" \\\n\t", sort(map("$rel_dir/$_", @{$build_structure{"APPS_${appname}_INCLUDES"}})));
 100    my $cflags  = join(" ", sort(@{$build_structure{"APPS_${appname}_CFLAGS"}}));
 101
 102    my $cflags_debug = $cflags;
 103    $cflags_debug =~ s/-MT/-MTd/;
 104    $cflags_debug =~ s/-O.//;
 105
 106    my $cflags_release = $cflags;
 107    $cflags_release =~ s/-MTd/-MT/;
 108
 109    my $libs;
 110    foreach (sort(@{$build_structure{"APPS_${appname}_LIBS"}})) {
 111        $_ =~ s/\//_/g;
 112        $libs .= " $_";
 113    }
 114    my @tmp  = @{$build_structure{"APPS_${appname}_LFLAGS"}};
 115    my @tmp2 = ();
 116    foreach (@tmp) {
 117        # next if ($_ eq "-NODEFAULTLIB:MSVCRT.lib");
 118        if (/^-LTCG/) {
 119        } elsif (/^-L/) {
 120            $_ =~ s/^-L/-LIBPATH:$rel_dir\//;
 121        }
 122        push(@tmp2, $_);
 123    }
 124    my $lflags = join(" ", sort(@tmp));
 125
 126    my $target = $appname;
 127    $target =~ s/\.exe//;
 128    $target =~ s/\//_/g;
 129    $defines =~ s/-D//g;
 130    $defines =~ s/"/\\\\"/g;
 131    $includes =~ s/-I//g;
 132    mkdir "$target" || die "Could not create the directory $target for app project!\n";
 133    open F, ">$target/$target.pro" || die "Could not open $target/$target.pro for writing!\n";
 134    print F << "EOM";
 135TEMPLATE = app
 136TARGET = $target
 137DESTDIR = $rel_dir
 138
 139CONFIG -= qt embed_manifest_exe
 140CONFIG += console
 141
 142QMAKE_CFLAGS =
 143QMAKE_CFLAGS_RELEASE = $cflags_release
 144QMAKE_CFLAGS_DEBUG = $cflags_debug
 145QMAKE_LFLAGS = $lflags
 146LIBS   = $libs
 147
 148DEFINES += \\
 149        $defines
 150
 151INCLUDEPATH += \\
 152        $includes
 153
 154win32:QMAKE_LFLAGS += -LIBPATH:$rel_dir
 155else: QMAKE_LFLAGS += -L$rel_dir
 156
 157SOURCES += \\
 158        $sources
 159EOM
 160    close F;
 161}
 162
 163sub createGlueProject {
 164    my ($git_dir, $out_dir, $rel_dir, %build_structure) = @_;
 165    my $libs = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"LIBS"}}));
 166    my $apps = join(" \\ \n", map("\t$_|$_.pro", @{$build_structure{"APPS"}}));
 167    $libs =~ s/\.a//g;
 168    $libs =~ s/\//_/g;
 169    $libs =~ s/\|/\//g;
 170    $apps =~ s/\.exe//g;
 171    $apps =~ s/\//_/g;
 172    $apps =~ s/\|/\//g;
 173
 174    my $filename = $out_dir;
 175    $filename =~ s/.*\/([^\/]+)$/$1/;
 176    $filename =~ s/\/$//;
 177    print "Generate glue project $filename.pro\n";
 178    open F, ">$filename.pro" || die "Could not open $filename.pro for writing!\n";
 179    print F << "EOM";
 180TEMPLATE = subdirs
 181CONFIG += ordered
 182SUBDIRS += \\
 183$libs \\
 184$apps
 185EOM
 186    close F;
 187}
 188
 1891;