Skip to content

Commit 1f9c204

Browse files
diefbell-grabcadaminya
authored andcommitted
fix: fix VS CMake generator finder
Co-Authored-By: Dief Bell <[email protected]>
1 parent 2e88344 commit 1f9c204

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-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

+13-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,22 @@ 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+
genParts[0] = genParts[0].replace(/^(\* )/, "").trim();
2329

2430
// eslint-disable-next-line optimize-regex/optimize-regex
25-
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+\s+\[arch\]/)) {
31+
if (genParts[0].match(/Visual\s+Studio\s+\d+\s+\d+(\s+\[arch\])?/)) {
2632
console.log('Found generator: ', genParts[0]);
2733
// The first entry is usually the latest entry
2834
useVSGen = genParts[0];
2935
break;
3036
}
3137
}
32-
if (arch === 'x64') {
33-
useVSGen = useVSGen.replace('[arch]', 'Win64').trim();
34-
} else if (arch === 'x86') {
35-
useVSGen = useVSGen.replace('[arch]', '').trim();
38+
39+
const useSwitch = !useVSGen.match(/.*\[arch\]/);
40+
if(useSwitch) {
41+
useVSGen += " -A" // essentially using this as a flag
3642
} else {
37-
console.error('Failed to find valid VS gen, using native. Good Luck.');
38-
return 'native';
43+
useVSGen = useVSGen.replace('[arch]', archString).trim();
3944
}
4045
return useVSGen;
4146
}

0 commit comments

Comments
 (0)