Ejemplo n.º 1
0
        protected void FixupPrecompiledHeaderOptions(IGenerationContext context)
        {
            var options        = context.Options;
            var cmdLineOptions = context.CommandLineOptions;
            var conf           = context.Configuration;

            if (options["UsePrecompiledHeader"] == "NotUsing")
            {
                options["UsePrecompiledHeader"] = FileGeneratorUtilities.RemoveLineTag;
            }
            else
            {
                Strings pathsToConsider = new Strings(context.ProjectSourceCapitalized);
                pathsToConsider.AddRange(context.Project.AdditionalSourceRootPaths);
                pathsToConsider.AddRange(GetIncludePaths(context));

                string pchFileSourceRelative = context.Options["PrecompiledHeaderThrough"];

                string pchFileVcxprojRelative = null;
                bool   foundPchInclude        = false;

                foreach (var includePath in pathsToConsider)
                {
                    var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative);
                    if (conf.Project.ResolvedSourceFiles.Contains(pchFile))
                    {
                        pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true);
                        foundPchInclude        = true;
                        break;
                    }
                }

                if (!foundPchInclude)
                {
                    foreach (var includePath in pathsToConsider)
                    {
                        var pchFile = Util.PathGetAbsolute(includePath, pchFileSourceRelative);
                        if (Util.FileExists(pchFile))
                        {
                            pchFileVcxprojRelative = Util.PathGetRelative(context.ProjectDirectory, pchFile, true);
                            foundPchInclude        = true;
                            break;
                        }
                    }
                }

                if (!foundPchInclude)
                {
                    throw new Error($"Sharpmake couldn't locate the PCH '{pchFileSourceRelative}' in {conf}");
                }

                context.Options["PrecompiledHeaderThrough"] = pchFileVcxprojRelative;
            }
        }
Ejemplo n.º 2
0
            public static string Get <T>(Project.Configuration conf, string fallback = RemoveLineTag, string rootpath = null)
                where T : PathOption
            {
                var option = Options.GetObject <T>(conf);

                if (option == null)
                {
                    return(fallback);
                }
                if (!string.IsNullOrEmpty(rootpath))
                {
                    return(Util.PathGetRelative(rootpath, option.Path, true));
                }
                return(option.Path);
            }
Ejemplo n.º 3
0
            protected override IEnumerable <string> GetIncludePathsImpl(IGenerationContext context)
            {
                var includePaths1 = new OrderableStrings();

                var includePaths2 = new OrderableStrings();

                includePaths2.AddRange(context.Configuration.IncludePrivatePaths);
                includePaths2.AddRange(context.Configuration.IncludePaths);
                includePaths2.AddRange(context.Configuration.DependenciesIncludePaths);

                Options.Vc.RemoteBuild.RelativeDirectory relativeDirectoryOption = Options.GetObject <Options.Vc.RemoteBuild.RelativeDirectory>(context.Configuration);
                if (relativeDirectoryOption != null)
                {
                    string basePath = relativeDirectoryOption.Value.TrimEnd(Util.WindowsSeparator);

                    Options.Vc.RemoteBuild.ProjectDirectory projectDirectoryOption = Options.GetObject <Options.Vc.RemoteBuild.ProjectDirectory>(context.Configuration);
                    if (projectDirectoryOption != null)
                    {
                        basePath += Util.WindowsSeparator + projectDirectoryOption.Value.TrimEnd(Util.WindowsSeparator);
                    }

                    for (int i = 0; i < includePaths2.Count; ++i)
                    {
                        string includePath = includePaths2[i];

                        foreach (var variable in Options.GetObjects <Options.Vc.RemoteBuild.Variable>(context.Configuration))
                        {
                            includePath = includePath.Replace(@"$(" + variable.Key + @")", variable.Value);
                        }

                        string remotePath = Util.PathGetRelative(basePath, includePath.TrimEnd(Util.WindowsSeparator));

                        if (remotePath != includePath)
                        {
                            includePaths1.Add(remotePath);
                        }
                    }
                }

                includePaths1.AddRange(includePaths2);

                return(includePaths1);
            }
Ejemplo n.º 4
0
        private void WriteLogs()
        {
            foreach (Project project in _projects.Values)
            {
                string logFileDirectory = Path.Combine(project.SharpmakeCsPath, "log");
                if (!Directory.Exists(logFileDirectory))
                {
                    Directory.CreateDirectory(logFileDirectory);
                }

                string logFile = Path.Combine(logFileDirectory, project.GetType().Name);

                using (TextWriter writer = new StreamWriter(logFile + ".project.log"))
                {
                    LogObject(writer, "", project);
                }

                foreach (Project.Configuration conf in project.Configurations)
                {
                    using (TextWriter writer = new StreamWriter(logFile + "." + conf.Target + ".project.log"))
                    {
                        LogObject(writer, "", conf);
                    }
                }
            }

            foreach (Solution solution in _solutions.Values)
            {
                string logFileDirectory = Path.Combine(solution.SharpmakeCsPath, "log");
                if (!Directory.Exists(logFileDirectory))
                {
                    Directory.CreateDirectory(logFileDirectory);
                }

                FileInfo logFile = new FileInfo(Path.Combine(logFileDirectory, solution.GetType().Name + ".solution.log"));

                using (TextWriter writer = new StreamWriter(logFile.FullName))
                {
                    writer.WriteLine("{0}", solution.Name);
                    LogObject(writer, "", solution);
                    foreach (Solution.Configuration conf in solution.Configurations)
                    {
                        LogObject(writer, "\t", conf);
                        writer.WriteLine("\t{0,-100} {1}" + Path.DirectorySeparatorChar + "{2}.[solution_ext]", conf.Target.GetTargetString(), Util.PathGetRelative(logFile.Directory.FullName, conf.SolutionPath), conf.SolutionFileName);

                        foreach (Solution.Configuration.IncludedProjectInfo configurationProject in conf.IncludedProjectInfos)
                        {
                            Project.Configuration projectConfiguration = configurationProject.Project.GetConfiguration(configurationProject.Target);
                            if (projectConfiguration != null)
                            {
                                writer.WriteLine("\t\t\t{0,-20} {1,-80}", configurationProject.Project.Name, configurationProject.Target.GetTargetString());
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
            public override void SetupSdkOptions(IGenerationContext context)
            {
                var conf   = context.Configuration;
                var devEnv = context.DevelopmentEnvironment;

                // We need to override the executable path for vs2015 because WindowsKit UAP.props does not
                // correctly set the WindowsSDK_ExecutablePath to the bin folder of its current version.
                if (devEnv == DevEnv.vs2015 && !KitsRootPaths.UsesDefaultKitRoot(devEnv))
                {
                    context.Options["ExecutablePath"] = devEnv.GetWindowsExecutablePath(conf.Platform);
                }

                Options.Vc.General.PlatformToolset platformToolset = Options.GetObject <Options.Vc.General.PlatformToolset>(conf);
                if (Options.Vc.General.PlatformToolset.LLVM == platformToolset)
                {
                    Options.Vc.General.PlatformToolset overridenPlatformToolset = Options.Vc.General.PlatformToolset.Default;
                    if (Options.WithArgOption <Options.Vc.General.PlatformToolset> .Get <Options.Clang.Compiler.LLVMVcPlatformToolset>(conf, ref overridenPlatformToolset))
                    {
                        platformToolset = overridenPlatformToolset;
                    }

                    devEnv = platformToolset.GetDefaultDevEnvForToolset() ?? devEnv;

                    context.Options["ExecutablePath"] = ClangForWindows.GetWindowsClangExecutablePath() + ";" + devEnv.GetWindowsExecutablePath(conf.Platform);
                    if (Options.GetObject <Options.Vc.LLVM.UseClangCl>(conf) == Options.Vc.LLVM.UseClangCl.Enable)
                    {
                        context.Options["IncludePath"] = ClangForWindows.GetWindowsClangIncludePath() + ";" + devEnv.GetWindowsIncludePath();
                        context.Options["LibraryPath"] = ClangForWindows.GetWindowsClangLibraryPath() + ";" + devEnv.GetWindowsLibraryPath(conf.Platform, Util.IsDotNet(conf) ? conf.Target.GetFragment <DotNetFramework>() : default(DotNetFramework?));
                    }
                }

                var systemIncludes = new OrderableStrings(conf.DependenciesIncludeSystemPaths);

                systemIncludes.AddRange(conf.IncludeSystemPaths);
                if (systemIncludes.Count > 0)
                {
                    systemIncludes.Sort();
                    string systemIncludesString = Util.PathGetRelative(context.ProjectDirectory, systemIncludes).JoinStrings(";");

                    // this option is mandatory when using /external:I with msvc, so if the user has selected it
                    // we consider that the vcxproj supports ExternalIncludePath
                    if (Options.HasOption <Options.Vc.General.ExternalWarningLevel>(conf))
                    {
                        if (context.Options["ExternalIncludePath"] == FileGeneratorUtilities.RemoveLineTag)
                        {
                            context.Options["ExternalIncludePath"] = systemIncludesString;
                        }
                        else
                        {
                            context.Options["ExternalIncludePath"] += ";" + systemIncludesString;
                        }
                    }
                    else
                    {
                        if (context.Options["IncludePath"] == FileGeneratorUtilities.RemoveLineTag)
                        {
                            context.Options["IncludePath"] = "$(VC_IncludePath);$(WindowsSDK_IncludePath);" + systemIncludesString;
                        }
                        else
                        {
                            context.Options["IncludePath"] += ";" + systemIncludesString;
                        }
                    }
                }
            }
Ejemplo n.º 6
0
 private IEnumerable <string> MakePathsRelative(IGenerationContext context, Func <IGenerationContext, IEnumerable <string> > func)
 {
     return(Util.PathGetRelative(context.ProjectDirectory, new OrderableStrings(func(context))));
 }
Ejemplo n.º 7
0
            public override void SelectPlatformAdditionalDependenciesOptions(IGenerationContext context)
            {
                context.Options["AdditionalLibraryDirectories"] = FileGeneratorUtilities.RemoveLineTag;
                context.Options["AdditionalDependencies"]       = FileGeneratorUtilities.RemoveLineTag;
                context.Options["LibraryDependencies"]          = FileGeneratorUtilities.RemoveLineTag;

                context.CommandLineOptions["AdditionalDependencies"]       = FileGeneratorUtilities.RemoveLineTag;
                context.CommandLineOptions["AdditionalLibraryDirectories"] = FileGeneratorUtilities.RemoveLineTag;
                context.CommandLineOptions["LibraryDependencies"]          = FileGeneratorUtilities.RemoveLineTag;

                var dependencies = new List <Project.Configuration>();

                dependencies.AddRange(context.Configuration.ResolvedPublicDependencies);

                // Sort by the number of dependencies to get a good starting point
                dependencies.Sort((Project.Configuration d0, Project.Configuration d1) =>
                {
                    return(d1.ProjectGuidDependencies.Count.CompareTo(d0.ProjectGuidDependencies.Count));
                });

                var libPaths = new OrderableStrings();
                var libFiles = new OrderableStrings();

                foreach (var dependency in dependencies)
                {
                    string outputFileName = dependency.TargetFileName;

                    string outputPrefix = GetOutputFileNamePrefix(context, dependency.Output);
                    if (!string.IsNullOrEmpty(outputPrefix))
                    {
                        outputFileName = outputPrefix + outputFileName;
                    }

                    string outputExtension = GetDefaultOutputExtension(dependency.Output);
                    if (!string.IsNullOrEmpty(outputExtension))
                    {
                        outputFileName = outputFileName + "." + outputExtension;
                    }

                    string libPath = dependency.IntermediatePath + Util.WindowsSeparator + outputFileName;

                    foreach (var variable in Options.GetObjects <Options.Vc.RemoteBuild.Variable>(context.Configuration))
                    {
                        libPath = libPath.Replace(@"$(" + variable.Key + @")", variable.Value);
                    }

                    string remotePath = Util.PathGetRelative(dependency.ProjectPath.TrimEnd(Util.WindowsSeparator), libPath.TrimEnd(Util.WindowsSeparator));

                    Options.Vc.RemoteBuild.ProjectDirectory projectDirectoryOption = Options.GetObject <Options.Vc.RemoteBuild.ProjectDirectory>(dependency);
                    if (projectDirectoryOption != null)
                    {
                        remotePath = projectDirectoryOption.Value.TrimEnd(Util.WindowsSeparator) + Util.WindowsSeparator + remotePath;

                        // Unlike the include paths, this needs the RemoteRootDir variable and unix separators
                        remotePath = @"$(RemoteRootDir)" + Util.UnixSeparator + remotePath.Replace(Util.WindowsSeparator, Util.UnixSeparator);

                        libPaths.Add(remotePath);
                    }
                }

                foreach (var file in context.Configuration.LibraryFiles)
                {
                    if (file.Contains(Util.WindowsSeparator.ToString()))
                    {
                        string libPath = file;

                        Options.Vc.RemoteBuild.RelativeDirectory relativeDirectoryOption = Options.GetObject <Options.Vc.RemoteBuild.RelativeDirectory>(context.Configuration);
                        if (relativeDirectoryOption != null)
                        {
                            string basePath = relativeDirectoryOption.Value.TrimEnd(Util.WindowsSeparator);

                            foreach (var variable in Options.GetObjects <Options.Vc.RemoteBuild.Variable>(context.Configuration))
                            {
                                libPath = libPath.Replace(@"$(" + variable.Key + @")", variable.Value);
                            }

                            string remotePath = Util.PathGetRelative(basePath, libPath.TrimEnd(Util.WindowsSeparator));

                            remotePath = @"$(RemoteRootDir)" + Util.UnixSeparator + remotePath.Replace(Util.WindowsSeparator, Util.UnixSeparator);

                            libPaths.Add(remotePath);
                        }
                    }
                    else
                    {
                        libFiles.Add(file);
                    }
                }

                context.Options["AdditionalDependencies"] = string.Join(";", libPaths);
                context.Options["LibraryDependencies"]    = string.Join(";", libFiles);
            }