Exemple #1
0
        public void ConfigureAll(
            Project.Configuration configuration,
            Target target)
        {
            string mySourceRootPath = Util.NormalizePath(this.SourceRootPath, target.Platform);

            // Set configuration name with the default composition logic.
            configuration.Name = Util.ComposeConfigurationName(target);

            // Compose default project path.
            configuration.ProjectPath = string.Format(
                Util.NormalizePath("./projects/{0}/{1}", target.Platform),
                this.Name,
                Util.ComposeProjectPath(target));

            // The output and intermediate paths is always the same by default.
            configuration.IntermediatePath = Util.NormalizePath(@"[conf.ProjectPath]\obj\$(PlatformTarget)\$(Configuration)", target.Platform);
            configuration.TargetPath       = this.ComposeTargetPath(configuration, target);

            // Always add the project's source and header folders.
            configuration.IncludePrivatePaths.Add(Util.NormalizePath(@"[project.SourceRootPath]\src", target.Platform));
            configuration.IncludePaths.Add(Util.NormalizePath(@"[project.SourceRootPath]\include", target.Platform));

            // The pre-compiled header.
            if (this.UseDefaultPrecompiledHeader == true)
            {
                // Add the pre-compiled header with the default names.
                configuration.PrecompHeader = this.Name + "_PCH.h";
                configuration.PrecompSource = this.Name + "_PCH.cpp";
            }

            // Post build script.
            if (this.UseDefaultPostBuildScript == true)
            {
                string postBuildScriptPath = Util.NormalizePath($"../../../../{mySourceRootPath}/misc/PostBuild.", target.Platform);
                if (Util.IsMswinPlatform(target.Platform) == true)
                {
                    postBuildScriptPath += "bat";
                }
                else
                {
                    postBuildScriptPath += "sh";
                }

                string projectToSrcRootPath = Util.NormalizePath($"../../../../{mySourceRootPath}", target.Platform);
                string postBuildArgs        = $"\"{configuration.TargetPath}\" \"{projectToSrcRootPath}\"";

                configuration.EventPostBuild.Add($"{postBuildScriptPath} {postBuildArgs} {this.DefaultPostBuildScriptArgs}");
            }

            // Set the project output type according to the target's output type.
            if (this.IsApplication == true)
            {
                configuration.Output = Configuration.OutputType.Exe;
            }
            else
            {
                if (target.OutputType == OutputType.Dll)
                {
                    configuration.Output = Configuration.OutputType.Dll;
                }
                else
                {
                    configuration.Output = Configuration.OutputType.Lib;
                }
            }

            // Set default character set to Unicode.
            configuration.Options.Add(Options.Vc.General.CharacterSet.Unicode);

            // Do custom configurations.
            this.CustomConfigure(configuration, target);
        }
Exemple #2
0
        protected virtual void WriteWindowsKitsOverrides(IVcxprojGenerationContext context, IFileGenerator fileGenerator)
        {
            KitsRootEnum? kitsRootWritten = null;
            for (DevEnv devEnv = context.DevelopmentEnvironmentsRange.MinDevEnv; devEnv <= context.DevelopmentEnvironmentsRange.MaxDevEnv; devEnv = (DevEnv)((int)devEnv << 1))
            {
                // there's no need to write the properties with older versions of vs, as we override
                // completely the VC++ directories entries in the vcxproj
                if (devEnv < DevEnv.vs2015)
                    continue;

                KitsRootEnum kitsRootVersion = KitsRootPaths.GetUseKitsRootForDevEnv(devEnv);
                if (kitsRootWritten == null)
                    kitsRootWritten = kitsRootVersion;
                else if (kitsRootWritten != kitsRootVersion)
                    throw new Error($"Different values of kitsRoot in the same vcxproj {context.ProjectFileName}");
                else
                    continue;

                string windowsSdkDirKey = FileGeneratorUtilities.RemoveLineTag;
                string windowsSdkDirValue = FileGeneratorUtilities.RemoveLineTag;

                string UniversalCRTSdkDir_10 = FileGeneratorUtilities.RemoveLineTag;
                string UCRTContentRoot = FileGeneratorUtilities.RemoveLineTag;

                string targetPlatformVersionString = FileGeneratorUtilities.RemoveLineTag;
                if (kitsRootVersion != KitsRootEnum.KitsRoot81) // 8.1 is the default value for vs2015 and vs2017, so only specify a different platformVersion if we need to
                    targetPlatformVersionString = KitsRootPaths.GetWindowsTargetPlatformVersionForDevEnv(devEnv).ToVersionString();

                if (devEnv.OverridenWindowsPath())
                {
                    windowsSdkDirValue = Util.EnsureTrailingSeparator(KitsRootPaths.GetRoot(kitsRootVersion));
                    switch (kitsRootVersion)
                    {
                        case KitsRootEnum.KitsRoot:
                            windowsSdkDirKey = "WindowsSdkDir_80";
                            break;
                        case KitsRootEnum.KitsRoot81:
                            windowsSdkDirKey = "WindowsSdkDir_81";
                            break;
                        case KitsRootEnum.KitsRoot10:
                            {
                                windowsSdkDirKey = "WindowsSdkDir_10";
                                UniversalCRTSdkDir_10 = windowsSdkDirValue;

                                // this variable is found in Windows Kits\10\DesignTime\CommonConfiguration\Neutral\uCRT.props
                                // it is always read from the registry unless overridden, so we need to explicitly set it
                                UCRTContentRoot = windowsSdkDirValue;
                            }
                            break;
                        default:
                            throw new NotImplementedException($"Unsupported kitsRoot '{kitsRootVersion}'");
                    }
                }

                using (fileGenerator.Declare("windowsSdkDirKey", windowsSdkDirKey))
                using (fileGenerator.Declare("windowsSdkDirValue", windowsSdkDirValue))
                using (fileGenerator.Declare("UniversalCRTSdkDir_10", UniversalCRTSdkDir_10))
                using (fileGenerator.Declare("UCRTContentRoot", UCRTContentRoot))
                using (fileGenerator.Declare("targetPlatformVersion", targetPlatformVersionString))
                {
                    fileGenerator.Write(_windowsSDKOverridesBegin);

                    // vs2015 specific, we need to set the UniversalCRTSdkDir to $(UniversalCRTSdkDir_10) because it is not done in the .props
                    if (devEnv == DevEnv.vs2015 && !string.Equals(UniversalCRTSdkDir_10, FileGeneratorUtilities.RemoveLineTag, StringComparison.Ordinal))
                    {
                        using (fileGenerator.Declare("custompropertyname", "UniversalCRTSdkDir"))
                        using (fileGenerator.Declare("custompropertyvalue", "$(UniversalCRTSdkDir_10)"))
                        {
                            fileGenerator.Write(fileGenerator.Resolver.Resolve(Vcxproj.Template.Project.CustomProperty));
                        }
                    }
                    fileGenerator.Write(_windowsSDKOverridesEnd);
                }
            }
        }