/// <inheritdoc />
        public override void SetupEnvironment(BuildOptions options)
        {
            base.SetupEnvironment(options);

            options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_GDK");
            options.CompileEnv.PreprocessorDefinitions.Add("WINAPI_FAMILY=WINAPI_FAMILY_GAMES");
            options.CompileEnv.PreprocessorDefinitions.Add("_ATL_NO_DEFAULT_LIBS");
            options.CompileEnv.PreprocessorDefinitions.Add("__WRL_NO_DEFAULT_LIB__");

            options.LinkEnv.InputLibraries.Add("xgameruntime.lib");
            options.LinkEnv.InputLibraries.Add("xgameplatform.lib");
            options.LinkEnv.InputLibraries.Add("Microsoft.Xbox.Services.142.GDK.C.lib");

            var toolsetPath = WindowsPlatformBase.GetToolsets()[Toolset];
            var toolsPath   = WindowsPlatformBase.GetVCToolPath64(Toolset);

            if (options.CompileEnv.UseDebugCRT)
            {
                throw new Exception("Don't use debug CRT on GDK.");
            }
            var name            = Path.GetFileName(toolsetPath);
            var redistToolsPath = Path.Combine(toolsPath, "..", "..", "..", "..", "..", "..", "Redist/MSVC/");
            var paths           = Directory.GetDirectories(redistToolsPath, name.Substring(0, 5) + "*");

            redistToolsPath = Path.Combine(paths[0], "x64", "Microsoft.VC" + (int)Toolset + ".CRT");
            redistToolsPath = Utilities.RemovePathRelativeParts(redistToolsPath);
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "concrt140.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_1.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_2.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "msvcp140_codecvt_ids.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vccorlib140.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vcruntime140.dll"));
            options.DependencyFiles.Add(Path.Combine(redistToolsPath, "vcruntime140_1.dll"));
        }
Exemple #2
0
        /// <inheritdoc />
        public override void LogInfo()
        {
            var sdkPath = WindowsPlatformBase.GetSDKs()[SDK];

            Log.Info(string.Format("Using Windows Toolset {0} ({1})", Toolset, sdkPath));
            Log.Info(string.Format("Using Windows SDK {0} ({1})", WindowsPlatformBase.GetSDKVersion(SDK), _vcToolPath));
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UWPToolchain"/> class.
        /// </summary>
        /// <param name="platform">The platform.</param>
        /// <param name="architecture">The target architecture.</param>
        /// <param name="toolsetVer">The target platform toolset version.</param>
        /// <param name="sdkVer">The target platform SDK version.</param>
        public UWPToolchain(UWPPlatform platform, TargetArchitecture architecture, WindowsPlatformToolset toolsetVer = WindowsPlatformToolset.Latest, WindowsPlatformSDK sdkVer = WindowsPlatformSDK.Latest)
            : base(platform, architecture, toolsetVer, sdkVer)
        {
            var visualStudio = VisualStudioInstance.GetInstances().FirstOrDefault(x => x.Version == VisualStudioVersion.VisualStudio2017 || x.Version == VisualStudioVersion.VisualStudio2019);

            if (visualStudio == null)
            {
                throw new Exception("Missing Visual Studio 2017 or newer. It's required to build for UWP.");
            }
            _usingDirs.Add(Path.Combine(visualStudio.Path, "VC", "vcpackages"));

            var sdks  = WindowsPlatformBase.GetSDKs();
            var sdk10 = sdks.FirstOrDefault(x => x.Key != WindowsPlatformSDK.v8_1).Value;

            if (sdk10 == null)
            {
                throw new Exception("Missing Windows 10 SDK. It's required to build for UWP.");
            }
            var sdk10Ver = WindowsPlatformBase.GetSDKVersion(SDK).ToString();

            _usingDirs.Add(Path.Combine(sdk10, "References"));
            _usingDirs.Add(Path.Combine(sdk10, "References", sdk10Ver));
            _usingDirs.Add(Path.Combine(sdk10, "References", "CommonConfiguration", "Neutral"));
            _usingDirs.Add(Path.Combine(sdk10, "UnionMetadata", sdk10Ver));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GDKToolchain"/> class.
 /// </summary>
 /// <param name="platform">The platform.</param>
 /// <param name="architecture">The architecture.</param>
 protected GDKToolchain(GDKPlatform platform, TargetArchitecture architecture)
     : base(platform, architecture, WindowsPlatformBase.GetToolsets().Keys.Where(x => x <= WindowsPlatformToolset.v142).Max(), WindowsPlatformSDK.v10_0_19041_0)
 {
     // Setup system paths
     SystemIncludePaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\GameKit\\Include"));
     SystemLibraryPaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\GameKit\\Lib\\amd64"));
     SystemLibraryPaths.Add(Path.Combine(GDK.Instance.RootPath, "GRDK\\ExtensionLibraries\\Xbox.Services.API.C\\DesignTime\\CommonConfiguration\\Neutral\\Lib\\Release\\" + Toolset));
 }
Exemple #5
0
        /// <summary>
        /// Gets the C++/CX metadata file directory.
        /// </summary>
        /// <returns>The folder path or null if not found.</returns>
        protected string GetCppCXMetadataDirectory()
        {
            var toolsets       = WindowsPlatformBase.GetToolsets();
            var vcToolChainDir = toolsets[Toolset];

            switch (Toolset)
            {
            case WindowsPlatformToolset.v141: return(Path.Combine(vcToolChainDir, "lib", "x86", "store", "references"));

            case WindowsPlatformToolset.v140: return(Path.Combine(vcToolChainDir, "lib", "store", "references"));

            default: return(null);
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowsToolchainBase"/> class.
        /// </summary>
        /// <param name="platform">The platform.</param>
        /// <param name="architecture">The target architecture.</param>
        /// <param name="toolsetVer">The target platform toolset version.</param>
        /// <param name="sdkVer">The target platform SDK version.</param>
        protected WindowsToolchainBase(WindowsPlatformBase platform, TargetArchitecture architecture, WindowsPlatformToolset toolsetVer, WindowsPlatformSDK sdkVer)
            : base(platform, architecture)
        {
            var toolsets = WindowsPlatformBase.GetToolsets();
            var sdks     = WindowsPlatformBase.GetSDKs();

            // Pick the overriden toolset
            if (Configuration.Compiler != null)
            {
                if (Enum.TryParse(Configuration.Compiler, out WindowsPlatformToolset compiler))
                {
                    toolsetVer = compiler;
                }
            }

            // Pick the newest installed Visual Studio version if using the default toolset
            if (toolsetVer == WindowsPlatformToolset.Default)
            {
                if (VisualStudioInstance.HasIDE(VisualStudioVersion.VisualStudio2019))
                {
                    toolsetVer = WindowsPlatformToolset.v142;
                }
                else if (VisualStudioInstance.HasIDE(VisualStudioVersion.VisualStudio2017))
                {
                    toolsetVer = WindowsPlatformToolset.v141;
                }
                else
                {
                    toolsetVer = WindowsPlatformToolset.v140;
                }
            }
            // Pick the latest toolset
            else if (toolsetVer == WindowsPlatformToolset.Latest)
            {
                toolsetVer = toolsets.Keys.Max();
            }

            // Pick the latest SDK
            if (sdkVer == WindowsPlatformSDK.Latest)
            {
                sdkVer = sdks.Keys.Max();
            }

            // Get tools
            Toolset = toolsetVer;
            SDK     = sdkVer;
            if (!toolsets.ContainsKey(Toolset))
            {
                throw new Exception(string.Format("Missing toolset {0} for platform Windows", Toolset));
            }
            if (!sdks.ContainsKey(SDK))
            {
                throw new Exception(string.Format("Missing SDK {0} for platform Windows", SDK));
            }

            // Get the tools paths
            string vcToolPath;

            if (Architecture == TargetArchitecture.x64)
            {
                vcToolPath = WindowsPlatformBase.GetVCToolPath64(Toolset);
            }
            else
            {
                vcToolPath = WindowsPlatformBase.GetVCToolPath32(Toolset);
            }
            _vcToolPath   = vcToolPath;
            _compilerPath = Path.Combine(vcToolPath, "cl.exe");
            _linkerPath   = Path.Combine(vcToolPath, "link.exe");
            _libToolPath  = Path.Combine(vcToolPath, "lib.exe");
            _xdcmakePath  = Path.Combine(vcToolPath, "xdcmake.exe");

            // Add Visual C++ toolset include and library paths
            var vcToolChainDir = toolsets[Toolset];

            SystemIncludePaths.Add(Path.Combine(vcToolChainDir, "include"));
            switch (Toolset)
            {
            case WindowsPlatformToolset.v140:
            {
                switch (Architecture)
                {
                case TargetArchitecture.AnyCPU: break;

                case TargetArchitecture.ARM:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "arm"));
                    break;

                case TargetArchitecture.ARM64:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "arm64"));
                    break;

                case TargetArchitecture.x86:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib"));
                    break;

                case TargetArchitecture.x64:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "amd64"));
                    break;

                default: throw new InvalidArchitectureException(architecture);
                }

                // When using Visual Studio 2015 toolset and using pre-Windows 10 SDK, find a Windows 10 SDK and add the UCRT include paths
                if (SDK == WindowsPlatformSDK.v8_1)
                {
                    var sdk = sdks.FirstOrDefault(x => x.Key != WindowsPlatformSDK.v8_1);
                    if (sdk.Value == null)
                    {
                        throw new Exception("Combination of Windows Toolset v140 and Windows SDK 8.1 requires the Universal CRT to be installed.");
                    }

                    var    sdkVersionName = WindowsPlatformBase.GetSDKVersion(sdk.Key).ToString();
                    string includeRootDir = Path.Combine(sdk.Value, "include", sdkVersionName);
                    SystemIncludePaths.Add(Path.Combine(includeRootDir, "ucrt"));

                    string libraryRootDir = Path.Combine(sdk.Value, "lib", sdkVersionName);
                    switch (Architecture)
                    {
                    case TargetArchitecture.AnyCPU: break;

                    case TargetArchitecture.ARM:
                        SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "arm"));
                        break;

                    case TargetArchitecture.ARM64:
                        SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "arm64"));
                        break;

                    case TargetArchitecture.x86:
                        SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x86"));
                        break;

                    case TargetArchitecture.x64:
                        SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x64"));
                        break;

                    default: throw new InvalidArchitectureException(architecture);
                    }
                }
                break;
            }

            case WindowsPlatformToolset.v141:
            case WindowsPlatformToolset.v142:
            {
                switch (Architecture)
                {
                case TargetArchitecture.AnyCPU: break;

                case TargetArchitecture.ARM:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "arm"));
                    break;

                case TargetArchitecture.ARM64:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "arm64"));
                    break;

                case TargetArchitecture.x86:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "x86"));
                    break;

                case TargetArchitecture.x64:
                    SystemLibraryPaths.Add(Path.Combine(vcToolChainDir, "lib", "x64"));
                    break;

                default: throw new InvalidArchitectureException(architecture);
                }
                break;
            }

            default: throw new ArgumentOutOfRangeException();
            }

            // Add Windows SDK include and library paths
            var windowsSdkDir = sdks[SDK];

            switch (SDK)
            {
            case WindowsPlatformSDK.v8_1:
            {
                string includeRootDir = Path.Combine(windowsSdkDir, "include");
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "shared"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "um"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "winrt"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "ucrt"));

                string libraryRootDir = Path.Combine(windowsSdkDir, "lib", "winv6.3");
                switch (Architecture)
                {
                case TargetArchitecture.AnyCPU: break;

                case TargetArchitecture.ARM:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "arm"));
                    break;
                }

                case TargetArchitecture.ARM64:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "arm64"));
                    break;
                }

                case TargetArchitecture.x86:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x86"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x86"));
                    var binRootDir = Path.Combine(windowsSdkDir, "bin", "x86");
                    _resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
                    _makepriPath          = Path.Combine(binRootDir, "makepri.exe");
                    break;
                }

                case TargetArchitecture.x64:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x64"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x64"));
                    var binRootDir = Path.Combine(windowsSdkDir, "bin", "x64");
                    _resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
                    _makepriPath          = Path.Combine(binRootDir, "makepri.exe");
                    break;
                }

                default: throw new InvalidArchitectureException(architecture);
                }
                break;
            }

            case WindowsPlatformSDK.v10_0_10240_0:
            case WindowsPlatformSDK.v10_0_10586_0:
            case WindowsPlatformSDK.v10_0_14393_0:
            case WindowsPlatformSDK.v10_0_15063_0:
            case WindowsPlatformSDK.v10_0_16299_0:
            case WindowsPlatformSDK.v10_0_17134_0:
            case WindowsPlatformSDK.v10_0_17763_0:
            case WindowsPlatformSDK.v10_0_18362_0:
            case WindowsPlatformSDK.v10_0_19041_0:
            {
                var    sdkVersionName = WindowsPlatformBase.GetSDKVersion(SDK).ToString();
                string includeRootDir = Path.Combine(windowsSdkDir, "include", sdkVersionName);
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "ucrt"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "shared"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "um"));
                SystemIncludePaths.Add(Path.Combine(includeRootDir, "winrt"));

                string libraryRootDir = Path.Combine(windowsSdkDir, "lib", sdkVersionName);
                switch (Architecture)
                {
                case TargetArchitecture.AnyCPU: break;

                case TargetArchitecture.ARM:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "arm"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "arm"));
                    break;
                }

                case TargetArchitecture.ARM64:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "arm64"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "arm64"));
                    break;
                }

                case TargetArchitecture.x86:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x86"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x86"));
                    var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, "x86");
                    _resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
                    _makepriPath          = Path.Combine(binRootDir, "makepri.exe");
                    break;
                }

                case TargetArchitecture.x64:
                {
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "ucrt", "x64"));
                    SystemLibraryPaths.Add(Path.Combine(libraryRootDir, "um", "x64"));
                    var binRootDir = Path.Combine(windowsSdkDir, "bin", sdkVersionName, "x64");
                    _resourceCompilerPath = Path.Combine(binRootDir, "rc.exe");
                    _makepriPath          = Path.Combine(binRootDir, "makepri.exe");
                    break;
                }

                default: throw new InvalidArchitectureException(architecture);
                }
                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(SDK));
            }
        }