Skip to content

Commit 0f6a169

Browse files
authored
Fix: VS CMake Generator Finder can Now Find MSVS 2019+ Automatically (#32)
2 parents 2e88344 + d6bc1a7 commit 0f6a169

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/argumentBuilder.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export class ArgumentBuilder {
2020
const defines = await this.buildDefines();
2121
baseCommand += ` ${ defines.map(d => `-D${d[0]}="${d[1]}"`).join(" ")}`;
2222
if (this.options.generatorToUse !== 'native') {
23-
baseCommand += ` -G"${this.options.generatorToUse}"`;
23+
let generatorString = ` -G"${this.options.generatorToUse}"`;
24+
if(generatorString.match(/Visual\s+Studio\s+\d+\s+\d+\s-A/)) {
25+
generatorString = generatorString.replace(/\s-A/, '');
26+
generatorString += ` -A ${this.config.arch}`;
27+
}
28+
baseCommand += generatorString;
2429
}
2530
console.log(baseCommand)
2631
return baseCommand;

src/lib.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export async function defaultBuildOptions(configs: BuildOptions, buildmode: Buil
212212
let ninja: string | null;
213213
let make: string | null;
214214
if (configs.generatorToUse === undefined) {
215-
console.log('no generator specified, checking ninja');
215+
console.log('no generator specified in package.json, checking ninja');
216216
ninja = await ninjaP;
217217
if (!ninja) {
218218
console.log('ninja not found, checking make');

src/util.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import splitargs from 'splitargs2';
33
import { PathLike, stat as rawStat, StatOptions, Stats } from 'fs-extra';
44

55
export const GET_CMAKE_VS_GENERATOR = async (cmake: string, arch: string): Promise<string> => {
6+
const archString = arch === 'x64' ? 'Win64' : arch === "x86" ? '' : null;
7+
if(archString === null) {
8+
console.error('Failed to find valid VS gen, using native. Good Luck.');
9+
return 'native';
10+
}
11+
612
const generators = await EXEC_CAPTURE(`"${cmake}" -G`);
713
const hasCR = generators.includes('\r\n');
814
const output = hasCR ? generators.split('\r\n') : generators.split('\n');
@@ -19,23 +25,24 @@ export const GET_CMAKE_VS_GENERATOR = async (cmake: string, arch: string): Promi
1925
// Some descriptions are multi-line
2026
continue;
2127
}
22-
genParts[0] = genParts[0].trim();
28+
/**
29+
* Current MSVS compiler selected in Windows generally is prefixed with "* "
30+
*/
31+
genParts[0] = genParts[0].replace(/^(\* )/, "").trim();
2332

2433
// eslint-disable-next-line optimize-regex/optimize-regex
25-
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+\s+\[arch\]/)) {
34+
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+(\s+\[arch\])?/)) {
2635
console.log('Found generator: ', genParts[0]);
2736
// The first entry is usually the latest entry
2837
useVSGen = genParts[0];
2938
break;
3039
}
3140
}
32-
if (arch === 'x64') {
33-
useVSGen = useVSGen.replace('[arch]', 'Win64').trim();
34-
} else if (arch === 'x86') {
35-
useVSGen = useVSGen.replace('[arch]', '').trim();
41+
const useSwitch = !useVSGen.match(/.*\[arch\]/);
42+
if(useSwitch) {
43+
useVSGen += " -A" // essentially using this as a flag
3644
} else {
37-
console.error('Failed to find valid VS gen, using native. Good Luck.');
38-
return 'native';
45+
useVSGen = useVSGen.replace('[arch]', archString).trim();
3946
}
4047
return useVSGen;
4148
}

0 commit comments

Comments
 (0)