示例#1
0
        void CompileClang(IEnumerable <string> files)
        {
            var xcodePath = XcodeToolchain.GetXcodeToolchainPath();
            var clangBin  = Path.Combine(xcodePath, "usr/bin/clang");
            var monoPath  = ManagedToolchain.FindMonoPath();

            var args = new List <string> {
                $"-D{DLLExportDefine}",
                "-framework CoreFoundation",
                $"-I\"{monoPath}/include/mono-2.0\"",
                $"-L\"{monoPath}/lib/\" -lmonosgen-2.0",
                string.Join(" ", files.ToList())
            };

            switch (Options.GeneratorKind)
            {
            case GeneratorKind.ObjectiveC:
                args.Add("-ObjC");
                args.Add("-lobjc");
                break;

            case GeneratorKind.CPlusPlus:
                args.Add("-x c++");
                break;
            }

            var invocation = string.Join(" ", args);

            Invoke(clangBin, invocation);
        }
示例#2
0
        bool CompileSwift(IEnumerable <string> files)
        {
            if (!Platform.IsMacOS)
            {
                throw new NotImplementedException();
            }

            var xcodePath = XcodeToolchain.GetXcodeToolchainPath();
            var swiftcBin = Path.Combine(xcodePath, "usr/bin/swiftc");

            var moduleName = Path.GetFileNameWithoutExtension(Project.Assemblies[0]);

            var swiftVersion = 4;

            var sdkPath = Path.Combine(XcodeToolchain.GetXcodePath(),
                                       "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs");
            var sdk = Directory.EnumerateDirectories(sdkPath).First();

            bool compileSuccess = true;

            foreach (var file in files)
            {
                var args = new List <string>
                {
                    "-emit-module",
                    $"-emit-module-path {Options.OutputDir}",
                    $"-module-name {moduleName}",
                    $"-swift-version {swiftVersion}",
                    $"-sdk {sdk}",
                    $"-I \"{MonoSdkPath}/include/mono-2.0\"",
                };

                var bridgingHeader = Directory.EnumerateFiles(Options.OutputDir, "*.h")
                                     .SingleOrDefault(header => Path.GetFileNameWithoutExtension(header) ==
                                                      Path.GetFileNameWithoutExtension(file));

                args.Add($"-import-objc-header {bridgingHeader}");

                args.Add(file);

                var invocation = string.Join(" ", args);
                var output     = Invoke(swiftcBin, invocation);

                compileSuccess &= output.ExitCode == 0;
            }

            return(compileSuccess);
        }
示例#3
0
        public void SetupXcode()
        {
            var builtinsPath = XcodeToolchain.GetXcodeBuiltinIncludesFolder();

            addSystemIncludeDirs(builtinsPath);

            var cppIncPath = XcodeToolchain.GetXcodeCppIncludesFolder();

            addSystemIncludeDirs(cppIncPath);

            var includePath = XcodeToolchain.GetXcodeIncludesFolder();

            addSystemIncludeDirs(includePath);

            NoBuiltinIncludes  = true;
            NoStandardIncludes = true;

            addArguments("-stdlib=libc++");
        }
示例#4
0
        bool CompileClangMac(IEnumerable <string> files)
        {
            var xcodePath = XcodeToolchain.GetXcodeToolchainPath();
            var clangBin  = Path.Combine(xcodePath, "usr/bin/clang");

            var args = new List <string> {
                "-Wno-typedef-redefinition",
                $"-D{DLLExportDefine}",
                "-framework CoreFoundation",
                $"-I\"{MonoSdkPath}/include/mono-2.0\"",
                $"-L\"{MonoSdkPath}/lib/\" -lmonosgen-2.0",
                string.Join(" ", files.ToList())
            };

            var sysroot = Path.Combine(XcodeToolchain.GetXcodeIncludesFolder(), "../..");

            args.Add($"-isysroot {sysroot}");

            if (Options.Compilation.Target == CompilationTarget.SharedLibrary)
            {
                var name       = Path.GetFileNameWithoutExtension(Project.Assemblies[0]);
                var libName    = $"lib{name}.dylib";
                var outputPath = Path.Combine(Options.OutputDir, libName);
                args.Add($"-dynamiclib -install_name {libName} -o {outputPath}");
            }

            switch (Options.GeneratorKind)
            {
            case GeneratorKind.ObjectiveC:
                args.Add("-ObjC");
                args.Add("-lobjc");
                break;

            case GeneratorKind.CPlusPlus:
                args.Add("-x c++");
                break;
            }

            var invocation = string.Join(" ", args);
            var output     = Invoke(clangBin, invocation);

            return(output.ExitCode == 0);
        }
示例#5
0
        public void SetupXcode()
        {
            var cppIncPath = XcodeToolchain.GetXcodeCppIncludesFolder();

            AddSystemIncludeDirs(cppIncPath);

            var builtinsPath = XcodeToolchain.GetXcodeBuiltinIncludesFolder();

            AddSystemIncludeDirs(UseXcodeBuiltins ? builtinsPath : BuiltinsDir);

            var includePath = XcodeToolchain.GetXcodeIncludesFolder();

            AddSystemIncludeDirs(includePath);

            NoBuiltinIncludes  = true;
            NoStandardIncludes = true;

            AddArguments("-fgnuc-version=4.2.1");
            AddArguments("-stdlib=libc++");
        }
示例#6
0
        private bool CompileInlines(Module module)
        {
            var pro        = string.Format("{0}.pro", module.InlinesLibraryName);
            var path       = Path.Combine(this.Context.Options.OutputDir, pro);
            var proBuilder = new StringBuilder();
            var qtModules  = string.Join(" ", from header in module.Headers
                                         where !header.EndsWith(".h", StringComparison.Ordinal)
                                         select header.Substring("Qt".Length).ToLowerInvariant());

            switch (qtModules)
            {
            // QtTest is only library which has a "lib" suffix to its module alias for qmake
            case "test":
                qtModules += "lib";
                break;

            // HACK: work around https://bugreports.qt.io/browse/QTBUG-54030
            case "bluetooth":
                qtModules += " network";
                break;
            }

            proBuilder.AppendFormat("QT += {0}\n", qtModules);
            proBuilder.Append("CONFIG += c++11\n");
            proBuilder.Append("QMAKE_CXXFLAGS += -fkeep-inline-functions\n");
            proBuilder.AppendFormat("TARGET = {0}\n", module.InlinesLibraryName);
            proBuilder.Append("TEMPLATE = lib\n");
            proBuilder.AppendFormat("SOURCES += {0}\n", Path.ChangeExtension(pro, "cpp"));
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                proBuilder.Append("LIBS += -loleaut32 -lole32");
            }
            File.WriteAllText(path, proBuilder.ToString());
            string error;

            // HACK: Clang does not support -fkeep-inline-functions so force compilation with (the real) GCC on OS X
            ProcessHelper.Run(this.qmake, string.Format("{0}\"{1}\"", Platform.IsMacOS ? "-spec macx-g++ " : string.Empty, path), out error);
            if (!string.IsNullOrEmpty(error))
            {
                Console.WriteLine(error);
                return(false);
            }
            var makefile = File.Exists(Path.Combine(this.Context.Options.OutputDir, "Makefile.Release")) ? "Makefile.Release" : "Makefile";

            if (Platform.IsMacOS)
            {
                // HACK: Clang does not support -fkeep-inline-functions so force compilation with (the real) GCC on OS X
                var makefilePath = Path.Combine(this.Context.Options.OutputDir, makefile);
                var script       = new StringBuilder(File.ReadAllText(makefilePath));
                var xcodePath    = XcodeToolchain.GetXcodePath();
                script.Replace(Path.Combine(xcodePath, "Contents", "Developer", "usr", "bin", "gcc"), "/usr/local/bin/gcc");
                script.Replace(Path.Combine(xcodePath, "Contents", "Developer", "usr", "bin", "g++"), "/usr/local/bin/g++");
                File.WriteAllText(makefilePath, script.ToString());
            }
            ProcessHelper.Run(this.make, string.Format("-j{0} -f {1}", Environment.ProcessorCount + 1, makefile), out error, true);
            if (!string.IsNullOrEmpty(error))
            {
                Console.WriteLine(error);
                return(false);
            }
            return(true);
        }
 internal IOSAppMainModuleFormat(XcodeToolchain toolchain) : base(
         new IOSAppMainModuleLinker(toolchain).WithBundledStaticLibraryDependencies(true))
 {
 }
示例#8
0
        void CompileCode()
        {
            var files = GetOutputFiles("c");

            switch (Options.Language)
            {
            case GeneratorKind.ObjectiveC:
                files = files.Concat(GetOutputFiles("mm"));
                break;

            case GeneratorKind.CPlusPlus:
                files = files.Concat(GetOutputFiles("cpp"));
                break;
            }

            const string exportDefine = "MONO_M2N_DLL_EXPORT";

            if (Platform.IsWindows)
            {
                List <ToolchainVersion> vsSdks;
                MSVCToolchain.GetVisualStudioSdks(out vsSdks);

                if (vsSdks.Count == 0)
                {
                    throw new Exception("Visual Studio SDK was not found on your system.");
                }

                var vsSdk = vsSdks.FirstOrDefault();
                var clBin = Path.GetFullPath(
                    Path.Combine(vsSdk.Directory, "..", "..", "VC", "bin", "cl.exe"));

                var monoPath = ManagedToolchain.FindMonoPath();
                var output   = Options.LibraryName ??
                               Path.GetFileNameWithoutExtension(Options.Project.Assemblies[0]);
                output = Path.Combine(Options.OutputDir, output);
                var invocation = string.Format(
                    "/nologo /D{0} -I\"{1}\\include\\mono-2.0\" {2} \"{1}\\lib\\monosgen-2.0.lib\" {3} {4}",
                    exportDefine, monoPath, string.Join(" ", files.ToList()),
                    Options.CompileSharedLibrary ? "/LD" : string.Empty,
                    output);

                var vsVersion = (VisualStudioVersion)(int)vsSdk.Version;
                var includes  = MSVCToolchain.GetSystemIncludes(vsVersion);

                Dictionary <string, string> envVars = null;
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("INCLUDE")))
                {
                    envVars            = new Dictionary <string, string>();
                    envVars["INCLUDE"] = string.Join(";", includes);

                    var clLib = Path.GetFullPath(
                        Path.Combine(vsSdk.Directory, "..", "..", "VC", "lib"));
                    envVars["LIB"] = clLib;
                }

                InvokeCompiler(clBin, invocation, envVars);

                return;
            }
            else if (Platform.IsMacOS)
            {
                var xcodePath = XcodeToolchain.GetXcodeToolchainPath();
                var clangBin  = Path.Combine(xcodePath, "usr/bin/clang");
                var monoPath  = ManagedToolchain.FindMonoPath();

                var invocation = string.Format(
                    "-D{0} -framework CoreFoundation -I\"{1}/include/mono-2.0\" " +
                    "-L\"{1}/lib/\" -lmonosgen-2.0 {2}",
                    exportDefine, monoPath, string.Join(" ", files.ToList()));

                InvokeCompiler(clangBin, invocation);

                return;
            }

            throw new NotImplementedException();
        }
示例#9
0
 internal IOSAppMainModuleFormat(XcodeToolchain toolchain) : base(
         new IOSAppMainModuleLinker(toolchain))
 {
 }