Skip to content

Commit 8147022

Browse files
set language standard for PCH compilation too
1 parent e2ec188 commit 8147022

File tree

1 file changed

+66
-41
lines changed

1 file changed

+66
-41
lines changed

tools/hxcpp/Compiler.hx

Lines changed: 66 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ private class FlagInfo
2727
}
2828
}
2929

30+
enum Language {
31+
C;
32+
Cxx;
33+
ObjC;
34+
ObjCxx;
35+
}
36+
3037
class Compiler
3138
{
3239
private var mFlags:Array<FlagInfo>;
@@ -127,15 +134,21 @@ class Compiler
127134

128135
function addIdentity(ext:String,ioArgs:Array<String>)
129136
{
137+
var lang = switch ext {
138+
case "c": C;
139+
case "m": ObjC;
140+
case "mm": ObjCxx;
141+
case "cpp", "c++", "cc", "cxx": Cxx;
142+
default: null;
143+
}
130144
if (mAddGCCIdentity)
131145
{
132-
var identity = switch(ext)
146+
var identity = switch (lang)
133147
{
134-
case "c" : "c";
135-
case "m" : "objective-c";
136-
case "mm" : "objective-c++";
137-
case "cpp" : "c++";
138-
case "c++" : "c++";
148+
case C : "c";
149+
case ObjC : "objective-c";
150+
case ObjCxx : "objective-c++";
151+
case Cxx : "c++";
139152
default:"";
140153
}
141154
if (identity!="")
@@ -144,6 +157,49 @@ class Compiler
144157
ioArgs.push(identity);
145158
}
146159
}
160+
return lang;
161+
}
162+
163+
function addStandard(lang: Language, inFile: {
164+
var mCStandard:Int;
165+
var mCxxStandard:Int;
166+
var mObjCStandard:Int;
167+
var mObjCxxStandard:Int;
168+
}, args:Array<String>) {
169+
switch (lang) {
170+
case C:
171+
if (inFile.mCStandard != null) {
172+
if (BuildTool.isMsvc()) {
173+
if (inFile.mCStandard > 17) {
174+
args.push('/std:clatest');
175+
} else if (inFile.mCStandard >= 11) {
176+
args.push('/std:c${inFile.mCStandard}');
177+
}
178+
} else {
179+
args.push('-std=c${inFile.mCStandard}');
180+
}
181+
}
182+
case ObjC:
183+
if (inFile.mObjCStandard != null) {
184+
args.push('-std=c${inFile.mObjCStandard}');
185+
}
186+
case ObjCxx:
187+
if (inFile.mObjCxxStandard != null) {
188+
args.push('-std=c++${inFile.mObjCxxStandard}');
189+
}
190+
case Cxx:
191+
if (inFile.mCxxStandard != null) {
192+
if (BuildTool.isMsvc()) {
193+
if (inFile.mCxxStandard > 20) {
194+
args.push('/std:c++latest');
195+
} else if (inFile.mCStandard >= 14) {
196+
args.push('/std:c++${inFile.mCxxStandard}');
197+
}
198+
} else {
199+
args.push('-std=c++${inFile.mCxxStandard}');
200+
}
201+
}
202+
}
147203
}
148204

149205
function addOptimTags(tagFilter:Array<String>)
@@ -190,42 +246,10 @@ class Compiler
190246
Log.error("Unkown extension for " + inFile.mName);
191247

192248

193-
addIdentity(ext,args);
194-
switch (ext) {
195-
case "c":
196-
if(inFile.mCStandard != null) {
197-
if(BuildTool.isMsvc()) {
198-
if (inFile.mCStandard > 17) {
199-
args.push('/std:clatest');
200-
} else if (inFile.mCStandard >= 11) {
201-
args.push('/std:c${inFile.mCStandard}');
202-
}
203-
} else {
204-
args.push('-std=c${inFile.mCStandard}');
205-
}
206-
}
207-
case "m":
208-
if(inFile.mObjCStandard != null) {
209-
args.push('-std=c${inFile.mObjCStandard}');
210-
}
211-
case "mm":
212-
if(inFile.mObjCxxStandard != null) {
213-
args.push('-std=c++${inFile.mObjCxxStandard}');
214-
}
215-
case "cpp", "c++", "cc":
216-
if(inFile.mCxxStandard != null) {
217-
if (BuildTool.isMsvc()) {
218-
if (inFile.mCxxStandard > 20) {
219-
args.push('/std:c++latest');
220-
} else if (inFile.mCStandard >= 14) {
221-
args.push('/std:c++${inFile.mCxxStandard}');
222-
}
223-
} else {
224-
args.push('-std=c++${inFile.mCxxStandard}');
225-
}
226-
}
249+
var lang = addIdentity(ext,args);
250+
if (lang != null) {
251+
addStandard(lang, inFile, args);
227252
}
228-
229253
var allowPch = false;
230254

231255
if (asm)
@@ -608,6 +632,7 @@ class Compiler
608632

609633
args = args.concat( mPCHFlags );
610634

635+
addStandard(Cxx, inGroup, args);
611636

612637
//Log.info("", "Make pch dir " + dir );
613638
PathManager.mkdir(dir);

0 commit comments

Comments
 (0)