vcxproj: handle resource files, too

On Windows, we also compile a "resource" file, which is similar to
source code, but contains metadata (such as the program version).

So far, we did not compile it in `MSVC` mode, only when compiling Git
for Windows with the GNU C Compiler.

In preparation for including it also when compiling with MS Visual C,
let's teach our `vcxproj` generator to handle those sort of files, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2021-04-07 15:15:08 +02:00
committed by Matthew Cheetham
parent 08d8457dbb
commit c4889abaed
2 changed files with 21 additions and 5 deletions

View File

@@ -89,6 +89,9 @@ sub createProject {
$defines =~ s/>/&gt;/g;
$defines =~ s/\'//g;
my $rcdefines = $defines;
$rcdefines =~ s/(?<!\\)"/\\$&/g;
my $dir = $vcxproj;
$dir =~ s/\/[^\/]*$//;
die "Could not create the directory $dir for $label project!\n" unless (-d "$dir" || mkdir "$dir");
@@ -203,6 +206,9 @@ EOM
<PreprocessorDefinitions>WIN32;_DEBUG;$defines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
@@ -216,6 +222,9 @@ EOM
<FunctionLevelLinking>true</FunctionLevelLinking>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -225,9 +234,15 @@ EOM
<ItemGroup>
EOM
foreach(@sources) {
print F << "EOM";
if (/\.rc$/) {
print F << "EOM";
<ResourceCompile Include="$_" />
EOM
} else {
print F << "EOM";
<ClCompile Include="$_" />
EOM
}
}
print F << "EOM";
</ItemGroup>

View File

@@ -165,7 +165,7 @@ sub parseMakeOutput
next;
}
if($text =~ / -c /) {
if($text =~ / -c / || $text =~ / -i \S+\.rc /) {
# compilation
handleCompileLine($text, $line);
@@ -263,7 +263,7 @@ sub handleCompileLine
if ("$part" eq "-o") {
# ignore object file
shift @parts;
} elsif ("$part" eq "-c") {
} elsif ("$part" eq "-c" || "$part" eq "-i") {
# ignore compile flag
} elsif ($part =~ /^.?-I/) {
push(@incpaths, $part);
@@ -271,7 +271,7 @@ sub handleCompileLine
push(@defines, $part);
} elsif ($part =~ /^-/) {
push(@cflags, $part);
} elsif ($part =~ /\.(c|cc|cpp)$/) {
} elsif ($part =~ /\.(c|cc|cpp|rc)$/) {
$sourcefile = $part;
} else {
die "Unhandled compiler option @ line $lineno: $part";
@@ -358,7 +358,7 @@ sub handleLinkLine
push(@libs, $part);
} elsif ($part eq 'invalidcontinue.obj') {
# ignore - known to MSVC
} elsif ($part =~ /\.o$/) {
} elsif ($part =~ /\.(o|res)$/) {
push(@objfiles, $part);
} elsif ($part =~ /\.obj$/) {
# do nothing, 'make' should not be producing .obj, only .o files
@@ -372,6 +372,7 @@ sub handleLinkLine
my $sourcefile = $_;
$sourcefile =~ s/^headless-git\.o$/compat\/win32\/headless.c/;
$sourcefile =~ s/\.o$/.c/;
$sourcefile =~ s/\.res$/.rc/;
push(@sources, $sourcefile);
push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
push(@defines, @{$compile_options{"${sourcefile}_DEFINES"}});