Skip to content

Commit

Permalink
vcxproj: handle resource files, too
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho committed Sep 18, 2024
1 parent 1941190 commit 68dab01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 16 additions & 1 deletion contrib/buildsystems/Generators/Vcxproj.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
9 changes: 5 additions & 4 deletions contrib/buildsystems/engine.pl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub parseMakeOutput
next;
}

if($text =~ / -c /) {
if($text =~ / -c / || $text =~ / -i \S+\.rc /) {
# compilation
handleCompileLine($text, $line);

Expand Down Expand Up @@ -263,15 +263,15 @@ 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);
} elsif ($part =~ /^.?-D/) {
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";
Expand Down Expand Up @@ -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
Expand All @@ -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"}});
Expand Down

0 comments on commit 68dab01

Please sign in to comment.