Пример #1
0
        protected override bool CompileCore(
            CompilerOutputType outputType,
            SupportedArchitecture architecture,
            IEnumerable <string> libraries,
            IEnumerable <string> sourceFilePaths,
            string targetFilePath,
            CompilerOption options,
            IDictionary <string, string> defineConstants)
        {
            ArgumentBuilder builder = new ArgumentBuilder("-", String.Empty);

            if (options.HasFlag(CompilerOption.GenerateSymbols))
            {
                builder.AppendNamedArgument("g", null);
            }

            if (options.HasFlag(CompilerOption.OptimizeLevel1))
            {
                builder.AppendNamedArgument("O1", null);
            }
            else if (options.HasFlag(CompilerOption.OptimizeLevel2))
            {
                builder.AppendNamedArgument("O2", null);
            }
            else if (options.HasFlag(CompilerOption.OptimizeLevel3))
            {
                builder.AppendNamedArgument("O3", null);
            }
            else
            {
                builder.AppendNamedArgument("O0", null);
            }

            // Enable pthreads
            if (options.HasFlag(CompilerOption.SupportThreading))
            {
                builder.AppendNamedArgument("pthread", null);
            }

            // Just use C++ 11
            builder.AppendNamedArgument("std", "c++11", "=");

            switch (outputType)
            {
            case CompilerOutputType.SharedLibrary:
                builder.AppendNamedArgument("shared", null);
                builder.AppendNamedArgument("fpic", null);
                break;

            case CompilerOutputType.ObjectFile:
                builder.AppendNamedArgument("c", null);
                builder.AppendNamedArgument("fpic", null);
                break;

            case CompilerOutputType.Unspecified:
            // Treat Unspecified as Executable, since executable is the default
            case CompilerOutputType.Executable:
                // Compiling an executable does not have a command line option, it's the default
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(outputType), "Unhandled output type: " + outputType);
            }

            switch (architecture)
            {
            case SupportedArchitecture.x64:
                builder.AppendNamedArgument("m", "64");
                DefineConstant(builder, "DEBUGGEE_ARCH", "64");
                break;

            case SupportedArchitecture.x86:
                builder.AppendNamedArgument("m", "32");
                DefineConstant(builder, "DEBUGGEE_ARCH", "32");
                break;

            case SupportedArchitecture.arm:
                builder.AppendNamedArgument("m", "arm");
                DefineConstant(builder, "DEBUGGEE_ARCH", "ARM");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(architecture), "Unhandled target architecture: " + architecture);
            }

            // Define a constant for the platform name.
            DefineConstant(builder, "DEBUGGEE_PLATFORM", GetPlatformName());

            this.SetAdditionalArguments(builder);

            builder.AppendNamedArgument("o", targetFilePath);

            foreach (string sourceFilePath in sourceFilePaths)
            {
                builder.AppendArgument(sourceFilePath);
            }

            foreach (string library in libraries)
            {
                builder.AppendNamedArgument("l", library);
            }

            foreach (var defineConstant in defineConstants)
            {
                DefineConstant(builder, defineConstant.Key, defineConstant.Value);
            }

            return(0 == this.RunCompiler(builder.ToString(), targetFilePath));
        }
Пример #2
0
        protected override bool CompileCore(
            CompilerOutputType outputType,
            SupportedArchitecture architecture,
            IEnumerable <string> libraries,
            IEnumerable <string> sourceFilePaths,
            string targetFilePath,
            CompilerOption options,
            IDictionary <string, string> defineConstants)
        {
            ArgumentBuilder clBuilder   = new ArgumentBuilder("/", ":");
            ArgumentBuilder linkBuilder = new ArgumentBuilder("/", ":");

            foreach (var defineConstant in defineConstants)
            {
                DefineConstant(clBuilder, defineConstant.Key, defineConstant.Value);
            }
            DefineConstant(clBuilder, "_WIN32");

            // Suppresses error C4996 for 'getenv' (in debuggees/kitchensink/src/environment.cpp)
            DefineConstant(clBuilder, "_CRT_SECURE_NO_WARNINGS");

            if (options.HasFlag(CompilerOption.GenerateSymbols))
            {
                clBuilder.AppendNamedArgument("ZI", null);
                clBuilder.AppendNamedArgument("Debug", null);
            }

            if (!options.HasFlag(CompilerOption.OptimizeLevel1) &&
                !options.HasFlag(CompilerOption.OptimizeLevel2) &&
                !options.HasFlag(CompilerOption.OptimizeLevel3))
            {
                // Disable optimization
                clBuilder.AppendNamedArgument("Od", null);
            }

            // Add options that are set by default in VS
            AddDefaultOptions(clBuilder);

            if (this.Settings.Properties != null)
            {
                // Get the include folders from the compiler properties
                string rawIncludes;
                if (!this.Settings.Properties.TryGetValue("Include", out rawIncludes))
                {
                    rawIncludes = String.Empty;
                }

                IEnumerable <string> includes = rawIncludes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
                foreach (string include in includes)
                {
                    clBuilder.AppendNamedArgumentQuoted("I", include, string.Empty);
                }

                // Get the lib folders from the compiler properties
                string rawLibs;
                if (!this.Settings.Properties.TryGetValue("Lib", out rawLibs))
                {
                    rawLibs = String.Empty;
                }

                IEnumerable <string> libs = rawLibs.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim());
                foreach (string lib in libs)
                {
                    linkBuilder.AppendNamedArgumentQuoted("LIBPATH", lib);
                }
            }

            switch (outputType)
            {
            case CompilerOutputType.SharedLibrary:
                // Create.DLL
                clBuilder.AppendNamedArgument("LD", null);
                clBuilder.AppendNamedArgument("Fo", Path.GetDirectoryName(targetFilePath) + Path.DirectorySeparatorChar);
                clBuilder.AppendNamedArgument("Fe", targetFilePath);
                break;

            case CompilerOutputType.ObjectFile:
                // Name obj
                clBuilder.AppendNamedArgument("Fo", targetFilePath);
                break;

            case CompilerOutputType.Unspecified:
            // Treat Unspecified as Executable, since executable is the default
            case CompilerOutputType.Executable:
                // Compiling an executable does not have a command line option, it's the default
                // Name exe
                clBuilder.AppendNamedArgument("Fo", Path.GetDirectoryName(targetFilePath) + Path.DirectorySeparatorChar);
                clBuilder.AppendNamedArgument("Fe", targetFilePath);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(outputType), "Unhandled output type: " + outputType);
            }

            // Specify the PDB name
            clBuilder.AppendNamedArgument("Fd", Path.ChangeExtension(targetFilePath, "pdb"));

            // Define a constant for the platform name.
            DefineConstant(clBuilder, "DEBUGGEE_PLATFORM", GetPlatformName());
            DefineConstant(clBuilder, "DEBUGGEE_COMPILER", "Visual C++");

            foreach (string sourceFilePath in sourceFilePaths)
            {
                clBuilder.AppendArgument(sourceFilePath);
            }

            foreach (string library in libraries)
            {
                clBuilder.AppendArgument(library);
            }

            switch (architecture)
            {
            case SupportedArchitecture.x64:
                DefineConstant(clBuilder, "DEBUGGEE_ARCH", "64");
                linkBuilder.AppendNamedArgument("MACHINE", "X64");
                break;

            case SupportedArchitecture.x86:
                DefineConstant(clBuilder, "DEBUGGEE_ARCH", "32");
                linkBuilder.AppendNamedArgument("MACHINE", "X86");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(architecture), "Unhandled target architecture: " + architecture);
            }

            // Pass the linker arguments (Note, the link parameter doesn't use the ":" suffix)
            clBuilder.AppendNamedArgument("link", linkBuilder.ToString(), overrideSuffix: " ");

            return(0 == this.RunCompiler(clBuilder.ToString(), targetFilePath));
        }