Exemplo n.º 1
0
        /// <inheritdoc />
        public override void PreBuild(TaskGraph graph, BuildOptions options)
        {
            base.PreBuild(graph, options);

            // Compile and include resource file if need to
            if (options.Target.Win32ResourceFile != null && !options.Target.IsPreBuilt && options.Target.OutputType == TargetOutputType.Executable)
            {
                var task       = graph.Add <CompileCppTask>();
                var args       = new List <string>();
                var sourceFile = options.Target.Win32ResourceFile;

                // Suppress Startup Banner
                args.Add("/nologo");

                // Language
                args.Add("/l 0x0409");

                // Add preprocessor definitions
                foreach (var definition in options.CompileEnv.PreprocessorDefinitions)
                {
                    args.Add(string.Format("/D \"{0}\"", definition));
                }

                // Add include paths
                foreach (var includePath in options.CompileEnv.IncludePaths)
                {
                    AddIncludePath(args, includePath);
                }

                // Add the resource file to the produced item list
                var outputFile = Path.Combine(options.IntermediateFolder, Path.GetFileNameWithoutExtension(sourceFile) + ".res");
                args.Add(string.Format("/Fo\"{0}\"", outputFile));
                options.LinkEnv.InputFiles.Add(outputFile);

                // Request included files to exist
                var includes = IncludesCache.FindAllIncludedFiles(sourceFile);
                task.PrerequisiteFiles.AddRange(includes);

                // Add the source file
                args.Add(string.Format("\"{0}\"", sourceFile));
                task.ProducedFiles.Add(outputFile);

                task.WorkingDirectory = options.WorkingDirectory;
                task.CommandPath      = _resourceCompilerPath;
                task.CommandArguments = string.Join(" ", args);
                task.PrerequisiteFiles.Add(sourceFile);
                task.Cost = 1;
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath)
        {
            var compileEnvironment = options.CompileEnv;
            var output             = new CompileOutput();

            // Setup arguments shared by all source files
            var commonArgs = new List <string>();

            SetupCompileCppFilesArgs(graph, options, commonArgs, outputPath);
            {
                commonArgs.Add("-c");
                commonArgs.Add("-pipe");
                commonArgs.Add("-x");
                commonArgs.Add("c++");
                commonArgs.Add("-std=c++14");

                commonArgs.Add("-Wdelete-non-virtual-dtor");
                commonArgs.Add("-fno-math-errno");
                commonArgs.Add("-fdiagnostics-format=msvc");

                if (Architecture == TargetArchitecture.ARM || Architecture == TargetArchitecture.ARM64)
                {
                    commonArgs.Add("-fsigned-char");
                }

                if (compileEnvironment.RuntimeTypeInfo)
                {
                    commonArgs.Add("-frtti");
                }
                else
                {
                    commonArgs.Add("-fno-rtti");
                }

                if (compileEnvironment.TreatWarningsAsErrors)
                {
                    commonArgs.Add("-Wall -Werror");
                }

                // TODO: compileEnvironment.IntrinsicFunctions
                // TODO: compileEnvironment.FunctionLevelLinking
                // TODO: compileEnvironment.FavorSizeOrSpeed
                // TODO: compileEnvironment.RuntimeChecks
                // TODO: compileEnvironment.StringPooling
                // TODO: compileEnvironment.BufferSecurityCheck

                if (compileEnvironment.DebugInformation)
                {
                    commonArgs.Add("-glldb");
                }

                commonArgs.Add("-pthread");

                if (compileEnvironment.Optimization)
                {
                    commonArgs.Add("-O2");
                }
                else
                {
                    commonArgs.Add("-O0");
                }

                if (!compileEnvironment.Inlining)
                {
                    commonArgs.Add("-fno-inline-functions");
                    commonArgs.Add("-fno-inline");
                }

                if (compileEnvironment.EnableExceptions)
                {
                    commonArgs.Add("-fexceptions");
                }
                else
                {
                    commonArgs.Add("-fno-exceptions");
                }
            }

            // Add preprocessor definitions
            foreach (var definition in compileEnvironment.PreprocessorDefinitions)
            {
                commonArgs.Add(string.Format("-D \"{0}\"", definition));
            }

            // Add include paths
            foreach (var includePath in compileEnvironment.IncludePaths)
            {
                commonArgs.Add(string.Format("-I\"{0}\"", includePath.Replace('\\', '/')));
            }

            // Compile all C++ files
            var args = new List <string>();

            foreach (var sourceFile in sourceFiles)
            {
                var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile);
                var task           = graph.Add <CompileCppTask>();

                // Use shared arguments
                args.Clear();
                args.AddRange(commonArgs);

                // Object File Name
                var objFile = Path.Combine(outputPath, sourceFilename + ".o");
                args.Add(string.Format("-o \"{0}\"", objFile.Replace('\\', '/')));
                output.ObjectFiles.Add(objFile);
                task.ProducedFiles.Add(objFile);

                // Source File Name
                args.Add("\"" + sourceFile.Replace('\\', '/') + "\"");

                // Request included files to exist
                var includes = IncludesCache.FindAllIncludedFiles(sourceFile);
                task.PrerequisiteFiles.AddRange(includes);

                // Compile
                task.WorkingDirectory = options.WorkingDirectory;
                task.CommandPath      = ClangPath;
                task.CommandArguments = string.Join(" ", args);
                task.PrerequisiteFiles.Add(sourceFile);
                task.InfoMessage = Path.GetFileName(sourceFile);
                task.Cost        = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting
            }

            return(output);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath)
        {
            var compileEnvironment = options.CompileEnv;
            var output             = new CompileOutput();

            // Setup arguments shared by all source files
            var commonArgs = new List <string>();

            SetupCompileCppFilesArgs(graph, options, commonArgs);
            {
                // Suppress Startup Banner
                commonArgs.Add("/nologo");

                // Compile Without Linking
                commonArgs.Add("/c");

                // Generate Intrinsic Functions
                if (compileEnvironment.IntrinsicFunctions)
                {
                    commonArgs.Add("/Oi");
                }

                // Enable Function-Level Linking
                if (compileEnvironment.FunctionLevelLinking)
                {
                    commonArgs.Add("/Gy");
                }
                else
                {
                    commonArgs.Add("/Gy-");
                }

                // List Include Files
                //commonArgs.Add("/showIncludes");

                // Code Analysis
                commonArgs.Add("/analyze-");

                // Remove unreferenced COMDAT
                commonArgs.Add("/Zc:inline");

                // Favor Small Code, Favor Fast Code
                if (compileEnvironment.FavorSizeOrSpeed == FavorSizeOrSpeed.FastCode)
                {
                    commonArgs.Add("/Ot");
                }
                else if (compileEnvironment.FavorSizeOrSpeed == FavorSizeOrSpeed.SmallCode)
                {
                    commonArgs.Add("/Os");
                }

                // Run-Time Error Checks
                if (compileEnvironment.RuntimeChecks && !compileEnvironment.CompileAsWinRT)
                {
                    commonArgs.Add("/RTC1");
                }

                // Enable Additional Security Checks
                if (compileEnvironment.RuntimeChecks)
                {
                    commonArgs.Add("/sdl");
                }

                // Inline Function Expansion
                if (compileEnvironment.Inlining)
                {
                    commonArgs.Add("/Ob2");
                }

                if (compileEnvironment.DebugInformation)
                {
                    // Debug Information Format
                    commonArgs.Add("/Zi");

                    // Enhance Optimized Debugging
                    commonArgs.Add("/Zo");
                }

                if (compileEnvironment.Optimization)
                {
                    // Enable Most Speed Optimizations
                    commonArgs.Add("/Ox");

                    // Generate Intrinsic Functions
                    commonArgs.Add("/Oi");

                    // Frame-Pointer Omission
                    commonArgs.Add("/Oy");

                    if (compileEnvironment.WholeProgramOptimization)
                    {
                        // Whole Program Optimization
                        commonArgs.Add("/GL");
                    }
                }
                else
                {
                    // Disable compiler optimizations (Debug)
                    commonArgs.Add("/Od");

                    // Frame-Pointer Omission
                    commonArgs.Add("/Oy-");
                }

                // Full Path of Source Code File in Diagnostics
                commonArgs.Add("/FC");

                // Report Internal Compiler Errors
                commonArgs.Add("/errorReport:prompt");

                // Exception Handling Model
                if (!compileEnvironment.CompileAsWinRT)
                {
                    if (compileEnvironment.EnableExceptions)
                    {
                        commonArgs.Add("/EHsc");
                    }
                    else
                    {
                        commonArgs.Add("/D_HAS_EXCEPTIONS=0");
                    }
                }

                // Eliminate Duplicate Strings
                if (compileEnvironment.StringPooling)
                {
                    commonArgs.Add("/GF");
                }
                else
                {
                    commonArgs.Add("/GF-");
                }

                // Use Run-Time Library
                if (compileEnvironment.UseDebugCRT)
                {
                    commonArgs.Add("/MDd");
                }
                else
                {
                    commonArgs.Add("/MD");
                }

                // Specify floating-point behavior
                commonArgs.Add("/fp:fast");
                commonArgs.Add("/fp:except-");

                // Buffer Security Check
                if (compileEnvironment.BufferSecurityCheck)
                {
                    commonArgs.Add("/GS");
                }
                else
                {
                    commonArgs.Add("/GS-");
                }

                // Enable Run-Time Type Information
                if (compileEnvironment.RuntimeTypeInfo)
                {
                    commonArgs.Add("/GR");
                }
                else
                {
                    commonArgs.Add("/GR-");
                }

                // Treats all compiler warnings as errors
                if (compileEnvironment.TreatWarningsAsErrors)
                {
                    commonArgs.Add("/WX");
                }
                else
                {
                    commonArgs.Add("/WX-");
                }

                // Show warnings
                // TODO: compile with W4 and fix all warnings
                commonArgs.Add("/W3");

                // Silence macro redefinition warning
                commonArgs.Add("/wd\"4005\"");

                // wchar_t is Native Type
                commonArgs.Add("/Zc:wchar_t");

                // Common Language Runtime Compilation
                if (compileEnvironment.CompileAsWinRT)
                {
                    commonArgs.Add("/clr");
                }

                // Windows Runtime Compilation
                if (compileEnvironment.WinRTComponentExtensions)
                {
                    commonArgs.Add("/ZW");
                    //commonArgs.Add("/ZW:nostdlib");

                    var dir = GetCppCXMetadataDirectory();
                    if (dir != null)
                    {
                        commonArgs.Add(string.Format("/AI\"{0}\"", dir));
                        commonArgs.Add(string.Format("/FU\"{0}\\platform.winmd\"", dir));
                    }
                }
            }

            // Add preprocessor definitions
            foreach (var definition in compileEnvironment.PreprocessorDefinitions)
            {
                commonArgs.Add(string.Format("/D \"{0}\"", definition));
            }

            // Add include paths
            foreach (var includePath in compileEnvironment.IncludePaths)
            {
                AddIncludePath(commonArgs, includePath);
            }

            // Compile all C++ files
            var args = new List <string>();

            foreach (var sourceFile in sourceFiles)
            {
                var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile);
                var task           = graph.Add <CompileCppTask>();

                // Use shared arguments
                args.Clear();
                args.AddRange(commonArgs);

                if (compileEnvironment.DebugInformation)
                {
                    // Program Database File Name
                    var pdbFile = Path.Combine(outputPath, sourceFilename + ".pdb");
                    args.Add(string.Format("/Fd\"{0}\"", pdbFile));
                    output.DebugDataFiles.Add(pdbFile);
                }

                if (compileEnvironment.GenerateDocumentation)
                {
                    // Process Documentation Comments
                    var docFile = Path.Combine(outputPath, sourceFilename + ".xdc");
                    args.Add(string.Format("/doc\"{0}\"", docFile));
                    output.DocumentationFiles.Add(docFile);
                }

                // Object File Name
                var objFile = Path.Combine(outputPath, sourceFilename + ".obj");
                args.Add(string.Format("/Fo\"{0}\"", objFile));
                output.ObjectFiles.Add(objFile);
                task.ProducedFiles.Add(objFile);

                // Source File Name
                args.Add("\"" + sourceFile + "\"");

                // Request included files to exist
                var includes = IncludesCache.FindAllIncludedFiles(sourceFile);
                task.PrerequisiteFiles.AddRange(includes);

                // Compile
                task.WorkingDirectory = options.WorkingDirectory;
                task.CommandPath      = _compilerPath;
                task.CommandArguments = string.Join(" ", args);
                task.PrerequisiteFiles.Add(sourceFile);
                task.Cost = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting
            }

            return(output);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override CompileOutput CompileCppFiles(TaskGraph graph, BuildOptions options, List <string> sourceFiles, string outputPath)
        {
            var compileEnvironment = options.CompileEnv;
            var output             = new CompileOutput();

            // Setup arguments shared by all source files
            var commonArgs = new List <string>();

            {
                commonArgs.Add("-c");
                commonArgs.Add("-fmessage-length=0");
                commonArgs.Add("-pipe");
                commonArgs.Add("-x");
                commonArgs.Add("objective-c++");
                commonArgs.Add("-std=c++14");
                commonArgs.Add("-stdlib=libc++");
                AddArgsCommon(options, commonArgs);

                switch (Architecture)
                {
                case TargetArchitecture.x64:
                    commonArgs.Add("-msse2");
                    break;
                }

                commonArgs.Add("-Wdelete-non-virtual-dtor");
                commonArgs.Add("-fno-math-errno");
                commonArgs.Add("-fasm-blocks");
                commonArgs.Add("-fpascal-strings");
                commonArgs.Add("-fdiagnostics-format=msvc");

                commonArgs.Add("-Wno-absolute-value");
                commonArgs.Add("-Wno-nullability-completeness");
                commonArgs.Add("-Wno-undef-prefix");
                commonArgs.Add("-Wno-expansion-to-defined");
                commonArgs.Add("-Wno-non-virtual-dtor");

                // Hide all symbols by default
                commonArgs.Add("-fvisibility-inlines-hidden");
                commonArgs.Add("-fvisibility-ms-compat");

                if (compileEnvironment.RuntimeTypeInfo)
                {
                    commonArgs.Add("-frtti");
                }
                else
                {
                    commonArgs.Add("-fno-rtti");
                }

                if (compileEnvironment.TreatWarningsAsErrors)
                {
                    commonArgs.Add("-Wall -Werror");
                }

                // TODO: compileEnvironment.IntrinsicFunctions
                // TODO: compileEnvironment.FunctionLevelLinking
                // TODO: compileEnvironment.FavorSizeOrSpeed
                // TODO: compileEnvironment.RuntimeChecks
                // TODO: compileEnvironment.StringPooling
                // TODO: compileEnvironment.BufferSecurityCheck

                if (compileEnvironment.DebugInformation)
                {
                    commonArgs.Add("-gdwarf-2");
                }

                commonArgs.Add("-pthread");

                if (compileEnvironment.Optimization)
                {
                    commonArgs.Add("-O3");
                }
                else
                {
                    commonArgs.Add("-O0");
                }

                if (!compileEnvironment.Inlining)
                {
                    commonArgs.Add("-fno-inline-functions");
                    commonArgs.Add("-fno-inline");
                }

                if (compileEnvironment.EnableExceptions)
                {
                    commonArgs.Add("-fexceptions");
                }
                else
                {
                    commonArgs.Add("-fno-exceptions");
                }
            }

            // Add preprocessor definitions
            foreach (var definition in compileEnvironment.PreprocessorDefinitions)
            {
                commonArgs.Add(string.Format("-D \"{0}\"", definition));
            }

            // Add include paths
            foreach (var includePath in compileEnvironment.IncludePaths)
            {
                commonArgs.Add(string.Format("-I\"{0}\"", includePath.Replace('\\', '/')));
            }

            // Compile all C++ files
            var args = new List <string>();

            foreach (var sourceFile in sourceFiles)
            {
                var sourceFilename = Path.GetFileNameWithoutExtension(sourceFile);
                var task           = graph.Add <CompileCppTask>();

                // Use shared arguments
                args.Clear();
                args.AddRange(commonArgs);

                // Object File Name
                var objFile = Path.Combine(outputPath, sourceFilename + ".o");
                args.Add(string.Format("-o \"{0}\"", objFile.Replace('\\', '/')));
                output.ObjectFiles.Add(objFile);
                task.ProducedFiles.Add(objFile);

                // Source File Name
                args.Add("\"" + sourceFile.Replace('\\', '/') + "\"");

                // Request included files to exist
                var includes = IncludesCache.FindAllIncludedFiles(sourceFile);
                task.PrerequisiteFiles.AddRange(includes);

                // Compile
                task.WorkingDirectory = options.WorkingDirectory;
                task.CommandPath      = ClangPath;
                task.CommandArguments = string.Join(" ", args);
                task.PrerequisiteFiles.Add(sourceFile);
                task.InfoMessage = Path.GetFileName(sourceFile);
                task.Cost        = task.PrerequisiteFiles.Count; // TODO: include source file size estimation to improve tasks sorting
            }

            return(output);
        }