Skip to content

Commit c6ee42c

Browse files
committed
Migrated to the target used by Qt as opposed to a hard-coded one.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 4f5a911 commit c6ee42c

8 files changed

+30
-11
lines changed

CppSharp Qt plan.odt

65 Bytes
Binary file not shown.

QtSharp.CLI/Program.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static int Main(string[] args)
2222
Console.WriteLine("The specified qmake does not exist.");
2323
return -1;
2424
}
25-
string makePath = args[1];
26-
if (!File.Exists(makePath))
25+
string make = args[1];
26+
if (!File.Exists(make))
2727
{
2828
Console.WriteLine("The specified make does not exist.");
2929
return -1;
@@ -59,12 +59,18 @@ public static int Main(string[] args)
5959
return -1;
6060
}
6161
string docs = ProcessHelper.Run(qmake, "-query QT_INSTALL_DOCS", out error);
62+
string output = ProcessHelper.Run(Path.Combine(Path.GetDirectoryName(make), "gcc"), "-v", out error);
63+
if (string.IsNullOrEmpty(output))
64+
{
65+
output = error;
66+
}
67+
string target = Regex.Match(output, @"Target:\s*(?<target>[^\r\n]+)").Groups["target"].Value;
68+
string compilerVersion = Regex.Match(output, @"gcc\s+version\s+(?<version>\S+)").Groups["version"].Value;
6269
foreach (string libFile in libFiles)
6370
{
6471
if (libFile == "libQt5Core.a")
6572
{
66-
string module = Regex.Match(libFile, @"Qt\d?(?<module>\w+)\.\w+$").Groups["module"].Value;
67-
ConsoleDriver.Run(new QtSharp(qmake, makePath, headers, module, libs, libFile, docs));
73+
ConsoleDriver.Run(new QtSharp(qmake, make, headers, libs, libFile, target, compilerVersion, docs));
6874
}
6975
}
7076
return 0;

QtSharp/QtSharp.cs

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Reflection;
5+
using System.Text.RegularExpressions;
46
using CppSharp;
57
using CppSharp.AST;
68
using CppSharp.Generators;
@@ -17,24 +19,28 @@ public class QtSharp : ILibrary
1719
private readonly string module;
1820
private readonly string libraryPath;
1921
private readonly string library;
22+
private readonly string target;
23+
private readonly string compilerVersion;
2024
private readonly string docs;
2125

22-
public QtSharp(string qmake, string make, string includePath, string module, string libraryPath, string library, string docs)
26+
public QtSharp(string qmake, string make, string includePath, string libraryPath, string library, string target, string compilerVersion, string docs)
2327
{
2428
this.qmake = qmake;
2529
this.includePath = includePath;
26-
this.module = module;
30+
this.module = Regex.Match(library, @"Qt\d?(?<module>\w+)\.\w+$").Groups["module"].Value;
2731
this.libraryPath = libraryPath;
2832
this.library = library;
29-
this.make = make;
33+
this.target = target;
34+
this.compilerVersion = compilerVersion;
35+
this.make = make;
3036
this.docs = docs;
3137
}
3238

3339
public void Preprocess(Driver driver, ASTContext lib)
3440
{
3541
string qtModule = "Qt" + this.module;
3642
string moduleIncludes = Path.Combine(this.includePath, qtModule);
37-
foreach (TranslationUnit unit in lib.TranslationUnits)
43+
foreach (TranslationUnit unit in lib.TranslationUnits.Where(u => u.FilePath != "<invalid>"))
3844
{
3945
if (Path.GetDirectoryName(unit.FilePath) != moduleIncludes)
4046
{
@@ -147,6 +153,9 @@ public void Setup(Driver driver)
147153
driver.Options.GeneratorKind = GeneratorKind.CSharp;
148154
string qtModule = "Qt" + this.module;
149155
driver.Options.Is32Bit = true;
156+
driver.Options.NoBuiltinIncludes = true;
157+
driver.Options.MicrosoftMode = false;
158+
driver.Options.TargetTriple = this.target;
150159
driver.Options.Abi = CppAbi.Itanium;
151160
driver.Options.LibraryName = string.Format("{0}Sharp", qtModule);
152161
driver.Options.OutputNamespace = qtModule;
@@ -158,11 +167,15 @@ public void Setup(Driver driver)
158167
driver.Options.IgnoreParseWarnings = true;
159168
driver.Options.CheckSymbols = true;
160169
driver.Options.Headers.Add(qtModule);
161-
driver.Options.IncludeDirs.Add(this.includePath);
170+
string gccPath = Path.GetDirectoryName(Path.GetDirectoryName(this.make));
171+
driver.Options.IncludeDirs.Add(Path.Combine(gccPath, this.target, "include"));
172+
driver.Options.IncludeDirs.Add(Path.Combine(gccPath, "lib", "gcc", this.target, this.compilerVersion, "include"));
173+
driver.Options.IncludeDirs.Add(Path.Combine(gccPath, "lib", "gcc", this.target, this.compilerVersion, "include", "c++"));
174+
driver.Options.IncludeDirs.Add(Path.Combine(gccPath, "lib", "gcc", this.target, this.compilerVersion, "include", "c++", this.target));
175+
driver.Options.IncludeDirs.Add(this.includePath);
162176
driver.Options.IncludeDirs.Add(Path.Combine(this.includePath, qtModule));
163177
driver.Options.LibraryDirs.Add(this.libraryPath);
164178
driver.Options.Libraries.Add(this.library);
165-
driver.Options.Defines.Add("_MSC_FULL_VER=170050215");
166179
if (this.module == "Core")
167180
{
168181
string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

References/CppSharp.AST.dll

0 Bytes
Binary file not shown.

References/CppSharp.Generator.dll

-512 Bytes
Binary file not shown.

References/CppSharp.Parser.dll

512 Bytes
Binary file not shown.

References/CppSharp.Runtime.dll

0 Bytes
Binary file not shown.

References/CppSharp.dll

512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)