Skip to content

Commit 5fbcb13

Browse files
fix generator logic (#4033)
* fix generator logic * fix logic * fix logic * fix use of gen.name
1 parent 4a334a6 commit 5fbcb13

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## 1.19.50
44

5-
Bug Fixes:
5+
Bug Fixes:
66

77
- Fix env expansion of all variables (toolchainFile, etc.) in presets. [#4019](https://github.com/microsoft/vscode-cmake-tools/issues/4019)
8+
- Fix generator and preferredGenerator logic. [#4031](https://github.com/microsoft/vscode-cmake-tools/issues/4031), [#4005](https://github.com/microsoft/vscode-cmake-tools/issues/4005), [#4032](https://github.com/microsoft/vscode-cmake-tools/issues/4032)
89

910
## 1.19.49
1011

src/drivers/cmakeDriver.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,17 @@ export abstract class CMakeDriver implements vscode.Disposable {
744744
preferredGenerators.push({ name: "Unix Makefiles" });
745745
}
746746

747-
// If a generator is set in the "cmake.generator" setting, push it to the front
748-
// of the "best generator" logic
747+
// Use the "best generator" logic only if the user did not define a particular
748+
// generator to be used via the `cmake.generator` setting.
749749
if (this.config.generator) {
750-
preferredGenerators.unshift({
750+
this._generator = {
751751
name: this.config.generator,
752752
platform: this.config.platform || undefined,
753753
toolset: this.config.toolset || undefined
754-
});
754+
};
755+
} else {
756+
this._generator = await this.findBestGenerator(preferredGenerators);
755757
}
756-
757-
this._generator = await this.findBestGenerator(preferredGenerators);
758758
}
759759

760760
protected abstract doSetConfigurePreset(needsClean: boolean, cb: () => Promise<void>): Promise<void>;
@@ -1004,7 +1004,7 @@ export abstract class CMakeDriver implements vscode.Disposable {
10041004
return false;
10051005
})();
10061006
if (!generator_present) {
1007-
const vsMatch = /^(Visual Studio \d{2} \d{4})($|\sWin64$|\sARM$)/.exec(gen.name);
1007+
const vsMatch = /^(Visual Studio \d{2} \d{4})($|\sWin64$|\sARM$)/.exec(gen_name);
10081008
if (platform === 'win32' && vsMatch) {
10091009
let possibleArchitecture = vsMatch[2].trim();
10101010
if (possibleArchitecture && possibleArchitecture === "Win64") {
@@ -1016,11 +1016,15 @@ export abstract class CMakeDriver implements vscode.Disposable {
10161016
toolset: gen.toolset
10171017
};
10181018
}
1019-
if (gen.name.toLowerCase().startsWith('xcode') && platform === 'darwin') {
1019+
if (gen_name.toLowerCase().startsWith('xcode') && platform === 'darwin') {
10201020
return gen;
10211021
}
10221022

1023-
// If the generator isn't found, move on to the next one
1023+
// If it is not a common generator that we can find, but it is a known cmake generator (cmakeGenerators), return it.
1024+
// The only caveat is that we should not return a Visual Studio generator on non-Windows platforms.
1025+
if (this.cmakeGenerators.indexOf(gen_name) >= 0 && !this.isCommonGenerator(gen_name) && !(gen_name.startsWith("Visual Studio") && platform !== "win32")) {
1026+
return gen;
1027+
}
10241028
continue;
10251029
} else {
10261030
return gen;

0 commit comments

Comments
 (0)