Skip to content

Commit 1297721

Browse files
committed
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 <[email protected]>
1 parent 8f92d58 commit 1297721

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

contrib/buildsystems/Generators/Vcxproj.pm

+16-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ sub createProject {
8989
$defines =~ s/>/&gt;/g;
9090
$defines =~ s/\'//g;
9191

92+
my $rcdefines = $defines;
93+
$rcdefines =~ s/(?<!\\)"/\\$&/g;
94+
9295
my $dir = $vcxproj;
9396
$dir =~ s/\/[^\/]*$//;
9497
die "Could not create the directory $dir for $label project!\n" unless (-d "$dir" || mkdir "$dir");
@@ -203,6 +206,9 @@ EOM
203206
<PreprocessorDefinitions>WIN32;_DEBUG;$defines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
204207
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
205208
</ClCompile>
209+
<ResourceCompile>
210+
<PreprocessorDefinitions>WIN32;_DEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
211+
</ResourceCompile>
206212
<Link>
207213
<GenerateDebugInformation>true</GenerateDebugInformation>
208214
</Link>
@@ -216,6 +222,9 @@ EOM
216222
<FunctionLevelLinking>true</FunctionLevelLinking>
217223
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
218224
</ClCompile>
225+
<ResourceCompile>
226+
<PreprocessorDefinitions>WIN32;NDEBUG;$rcdefines;%(PreprocessorDefinitions)</PreprocessorDefinitions>
227+
</ResourceCompile>
219228
<Link>
220229
<GenerateDebugInformation>true</GenerateDebugInformation>
221230
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -225,9 +234,15 @@ EOM
225234
<ItemGroup>
226235
EOM
227236
foreach(@sources) {
228-
print F << "EOM";
237+
if (/\.rc$/) {
238+
print F << "EOM";
239+
<ResourceCompile Include="$_" />
240+
EOM
241+
} else {
242+
print F << "EOM";
229243
<ClCompile Include="$_" />
230244
EOM
245+
}
231246
}
232247
print F << "EOM";
233248
</ItemGroup>

contrib/buildsystems/engine.pl

+5-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ sub parseMakeOutput
165165
next;
166166
}
167167

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

@@ -263,15 +263,15 @@ sub handleCompileLine
263263
if ("$part" eq "-o") {
264264
# ignore object file
265265
shift @parts;
266-
} elsif ("$part" eq "-c") {
266+
} elsif ("$part" eq "-c" || "$part" eq "-i") {
267267
# ignore compile flag
268268
} elsif ($part =~ /^.?-I/) {
269269
push(@incpaths, $part);
270270
} elsif ($part =~ /^.?-D/) {
271271
push(@defines, $part);
272272
} elsif ($part =~ /^-/) {
273273
push(@cflags, $part);
274-
} elsif ($part =~ /\.(c|cc|cpp)$/) {
274+
} elsif ($part =~ /\.(c|cc|cpp|rc)$/) {
275275
$sourcefile = $part;
276276
} else {
277277
die "Unhandled compiler option @ line $lineno: $part";
@@ -358,7 +358,7 @@ sub handleLinkLine
358358
push(@libs, $part);
359359
} elsif ($part eq 'invalidcontinue.obj') {
360360
# ignore - known to MSVC
361-
} elsif ($part =~ /\.o$/) {
361+
} elsif ($part =~ /\.(o|res)$/) {
362362
push(@objfiles, $part);
363363
} elsif ($part =~ /\.obj$/) {
364364
# do nothing, 'make' should not be producing .obj, only .o files
@@ -371,6 +371,7 @@ sub handleLinkLine
371371
foreach (@objfiles) {
372372
my $sourcefile = $_;
373373
$sourcefile =~ s/\.o$/.c/;
374+
$sourcefile =~ s/\.res$/.rc/;
374375
push(@sources, $sourcefile);
375376
push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
376377
push(@defines, @{$compile_options{"${sourcefile}_DEFINES"}});

0 commit comments

Comments
 (0)