From 6a82ebb2730dfeb29398dbea2effaaa6127f5476 Mon Sep 17 00:00:00 2001 From: Bob Brown Date: Wed, 25 Aug 2021 10:57:44 -0700 Subject: [PATCH] Fix presets for msvc compilers with x86 outputs (#2072) --- src/kit.ts | 12 +++++++++++- src/preset.ts | 7 +++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/kit.ts b/src/kit.ts index 5eab1964..9ea4c499 100644 --- a/src/kit.ts +++ b/src/kit.ts @@ -548,7 +548,7 @@ export function kitHostTargetArch(hostArch: string, targetArch?: string, amd64Al // instead of hard coding for win32 and x86. // Currently, there is no need of a similar overwrite operation on hostArch, // because CMake host target does not have the same name mismatch with VS. - targetArch = vsArchFromGeneratorPlatform[targetArch] || targetArch; + targetArch = targetArchFromGeneratorPlatform(targetArch); return (hostArch === targetArch) ? hostArch : `${hostArch}_${targetArch}`; } @@ -839,6 +839,16 @@ const vsArchFromGeneratorPlatform: {[key: string]: string} = { win32: 'x86' }; +/** + * Turns 'win32' into 'x86' for target architecture. + */ +export function targetArchFromGeneratorPlatform(generatorPlatform?: string) { + if (!generatorPlatform) { + return undefined; + } + return vsArchFromGeneratorPlatform[generatorPlatform] || generatorPlatform; +} + /** * Preferred CMake VS generators by VS version */ diff --git a/src/preset.ts b/src/preset.ts index 79a9743e..d89acf4e 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -7,7 +7,7 @@ import * as logging from '@cmt/logging'; import { EnvironmentVariables, execute } from '@cmt/proc'; import { expandString, ExpansionOptions } from '@cmt/expand'; import paths from '@cmt/paths'; -import { effectiveKitEnvironment, getKitEnvironmentVariablesObject, Kit } from '@cmt/kit'; +import { effectiveKitEnvironment, getKitEnvironmentVariablesObject, Kit, targetArchFromGeneratorPlatform } from '@cmt/kit'; import { compareVersions, vsInstallations } from '@cmt/installs/visual-studio'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); @@ -666,9 +666,8 @@ async function expandConfigurePresetHelper(folder: string, const kit = kits[i]; if (kit.visualStudio && !kit.compilers) { const version = vsVersions.get(kit.visualStudio); - if (kit.preferredGenerator && - (kit.visualStudioArchitecture === arch || kit.preferredGenerator.platform === arch) && - kit.preferredGenerator.toolset === ('host=' + toolset.host)) { + if (kit.preferredGenerator && targetArchFromGeneratorPlatform(kit.preferredGenerator.platform) === arch && + (kit.visualStudioArchitecture === toolset.host || kit.preferredGenerator.toolset === ('host=' + toolset.host))) { if (toolset.version && version?.startsWith(toolset.version)) { latestVsVersion = version; latestVsIndex = i;