Skip to content

Commit 95b5059

Browse files
committed
iwyu integration passes now arch parameter for x64 projects on to iwyu
Fixes #43
1 parent e5c762f commit 95b5059

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

IncludeToolbox/IncludeWhatYouUse/IWYU.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,35 @@ static public string RunIncludeWhatYouUse(string fullFileName, EnvDTE.Project pr
250250
// MSVC specific. See https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions
251251
process.StartInfo.Arguments += "-fms-compatibility -fms-extensions -fdelayed-template-parsing ";
252252
process.StartInfo.Arguments += $"-fmsc-version={VSUtils.GetMSCVerString()} ";
253-
253+
// Architecture
254+
var targetMachine = VSUtils.VCUtils.GetLinkerSetting_TargetMachine(project, out reasonForFailure);
255+
if(!targetMachine.HasValue)
256+
Output.Instance.ErrorMsg("Failed to query for target machine: {0}", reasonForFailure);
257+
else
258+
{
259+
switch (targetMachine.Value)
260+
{
261+
// Most targets give an error of this form:
262+
// "error: unknown target CPU 'x86'"
263+
// It seems iwyu is only really fine with x86-64
264+
265+
/*case VCProjectUtils.Base.TargetMachineType.X86:
266+
process.StartInfo.Arguments += "-march=x86 ";
267+
break;*/
268+
case VCProjectUtils.Base.TargetMachineType.AMD64:
269+
process.StartInfo.Arguments += "-march=x86-64 ";
270+
break;
271+
/*case VCProjectUtils.Base.TargetMachineType.ARM:
272+
process.StartInfo.Arguments += "-march=arm ";
273+
break;
274+
case VCProjectUtils.Base.TargetMachineType.MIPS:
275+
process.StartInfo.Arguments += "-march=mips ";
276+
break;
277+
case VCProjectUtils.Base.TargetMachineType.THUMB:
278+
process.StartInfo.Arguments += "-march=thumb ";
279+
break;*/
280+
}
281+
}
254282

255283
// icwyu options
256284
{

VCProject.Base/IVCHelper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
namespace VCProjectUtils.Base
88
{
9+
// https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.machinetypeoption.aspx
10+
public enum TargetMachineType
11+
{
12+
NotSet = 0,
13+
X86 = 1,
14+
AM33 = 2,
15+
ARM = 3,
16+
EBC = 4,
17+
IA64 = 5,
18+
M32R = 6,
19+
MIPS = 7,
20+
MIPS16 = 8,
21+
MIPSFPU = 9,
22+
MIPSFPU16 = 10,
23+
MIPSR41XX = 11,
24+
SH3 = 12,
25+
SH3DSP = 13,
26+
SH4 = 14,
27+
SH5 = 15,
28+
THUMB = 16,
29+
AMD64 = 17
30+
}
31+
932
public interface IVCHelper
1033
{
1134
bool IsVCProject(EnvDTE.Project project);
@@ -21,5 +44,7 @@ public interface IVCHelper
2144
bool? GetCompilerSetting_ShowIncludes(EnvDTE.Project document, out string reasonForFailure);
2245

2346
string GetCompilerSetting_PreprocessorDefinitions(EnvDTE.Project project, out string reasonForFailure);
47+
48+
TargetMachineType? GetLinkerSetting_TargetMachine(EnvDTE.Project project, out string reasonForFailure);
2449
}
2550
}

VCProject.Base/VCHelper.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using EnvDTE;
22
using Microsoft.VisualStudio.VCProjectEngine;
3+
using VCProjectUtils.Base;
34

45
#if VC14
56
namespace VCProjectUtils.VS14
67
#elif VC15
78
namespace VCProjectUtils.VS15
89
#endif
910
{
10-
public class VCHelper : VCProjectUtils.Base.IVCHelper
11+
public class VCHelper : IVCHelper
1112
{
1213
public bool IsVCProject(Project project)
1314
{
@@ -82,6 +83,34 @@ public static VCCLCompilerTool GetCompilerTool(Project project, out string reaso
8283
return compilerTool;
8384
}
8485

86+
public static VCLinkerTool GetLinkerTool(Project project, out string reasonForFailure)
87+
{
88+
VCProject vcProject = project?.Object as VCProject;
89+
if (vcProject == null)
90+
{
91+
reasonForFailure = "Failed to retrieve VCLinkerTool since project is not a VCProject.";
92+
return null;
93+
}
94+
VCConfiguration activeConfiguration = vcProject.ActiveConfiguration;
95+
var tools = activeConfiguration.Tools;
96+
VCLinkerTool linkerTool = null;
97+
foreach (var tool in activeConfiguration.Tools)
98+
{
99+
linkerTool = tool as VCLinkerTool;
100+
if (linkerTool != null)
101+
break;
102+
}
103+
104+
if (linkerTool == null)
105+
{
106+
reasonForFailure = "Couldn't file a VCLinkerTool in VC++ Project.";
107+
return null;
108+
}
109+
110+
reasonForFailure = "";
111+
return linkerTool;
112+
}
113+
85114
public bool IsCompilableFile(Document document, out string reasonForFailure)
86115
{
87116
return GetVCFileConfigForCompilation(document, out reasonForFailure) != null;
@@ -121,5 +150,14 @@ public string GetCompilerSetting_PreprocessorDefinitions(Project project, out st
121150
VCCLCompilerTool compilerTool = GetCompilerTool(project, out reasonForFailure);
122151
return compilerTool?.PreprocessorDefinitions;
123152
}
153+
154+
public TargetMachineType? GetLinkerSetting_TargetMachine(EnvDTE.Project project, out string reasonForFailure)
155+
{
156+
var linkerTool = GetLinkerTool(project, out reasonForFailure);
157+
if (linkerTool == null)
158+
return null;
159+
else
160+
return (TargetMachineType)linkerTool.TargetMachine;
161+
}
124162
}
125163
}

0 commit comments

Comments
 (0)