コード例 #1
0
        private void GenerateConfOptions(GenerationContext context)
        {
            // generate all configuration options once...
            var projectOptionsGen           = new ProjectOptionsGenerator();
            var projectConfigurationOptions = new Dictionary <Project.Configuration, Options.ExplicitOptions>();

            context.SetProjectConfigurationOptions(projectConfigurationOptions);
            foreach (Project.Configuration conf in context.ProjectConfigurations)
            {
                context.Configuration = conf;

                // set generator information
                var platformVcxproj    = context.PresentPlatforms[conf.Platform];
                var configurationTasks = PlatformRegistry.Get <Project.Configuration.IConfigurationTasks>(conf.Platform);
                conf.GeneratorSetGeneratedInformation(
                    platformVcxproj.ExecutableFileExtension,
                    platformVcxproj.PackageFileExtension,
                    configurationTasks.GetDefaultOutputExtension(Project.Configuration.OutputType.Dll),
                    platformVcxproj.ProgramDatabaseFileExtension);

                projectConfigurationOptions.Add(conf, new Options.ExplicitOptions());
                context.CommandLineOptions = new ProjectOptionsGenerator.VcxprojCmdLineOptions();

                projectOptionsGen.GenerateOptions(context);
                GenerateOptions(context);

                context.Reset(); // just a safety, not necessary to clean up
            }
        }
コード例 #2
0
        public CompileCommandFactory(CompileCommandGenerationContext context)
        {
            var isClang     = context.Configuration.Platform.IsUsingClang();
            var isMicrosoft = context.Configuration.Platform.IsMicrosoft();

            _compiler         = isClang ? "clang.exe" : "clang-cl.exe";
            _config           = context.Configuration;
            _outputExtension  = isMicrosoft ? ".obj" : ".o";
            _outputDirectory  = _config.IntermediatePath;
            _projectDirectory = context.ProjectDirectoryCapitalized;
            _flags            = isClang ? s_clangFlags : s_vcFlags;

            s_optionGenerator.GenerateOptions(context, ProjectOptionGenerationLevel.Compiler);
            var argsList = new List <string>();

            argsList.Add(isClang ? "-c" : "/c");

            // Precomp arguments flags are actually written by the bff generator (see bff.template.cs)
            // Therefore, the CommandLineOptions entries only contain the pch name and file.
            if (_config.PrecompSource != null)
            {
                _precompFile = Path.Combine(_projectDirectory, context.Options[PrecompFileKey]);

                string name;
                if (_flags.ContainsKey(CompilerFlags.PrecompPath))
                {
                    argsList.Add(string.Format(_flags[CompilerFlags.PrecompPath], _precompFile));
                    name = context.Options[PrecompNameKey];
                }
                else
                {
                    name = _precompFile;
                }

                _createPrecompArgument = string.Format(_flags[CompilerFlags.CreatePrecomp], name);
                _usePrecompArgument    = string.Format(_flags[CompilerFlags.UsePrecomp], name);
            }

            // AdditionalCompilerOptions are referenced from Options in the bff template.
            context.CommandLineOptions.Add(AdditionalOptionsKey, context.Options[AdditionalOptionsKey]);

            FillIncludeDirectoriesOptions(context);

            var validOptions = context.CommandLineOptions
                               .Where(IsValidOption)
                               .ToDictionary(kvp => kvp.Key, FlattenMultilineArgument);

            if (isMicrosoft)
            {
                // Required to avoid errors in VC headers.
                var flag  = isClang ? "-D" : "/D";
                var value = validOptions.ContainsKey("ExceptionHandling") ? 1 : 0;
                argsList.Add($"{flag}_HAS_EXCEPTIONS={value}");
            }

            argsList.AddRange(validOptions.Values);

            _arguments = string.Join(" ", argsList);
        }