Skip to content

Commit ae017f6

Browse files
committed
Fix cmake tools integration when switching boards
1 parent c5164be commit ae017f6

File tree

6 files changed

+73
-12
lines changed

6 files changed

+73
-12
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
"category": "Raspberry Pi Pico",
112112
"enablement": "false"
113113
},
114+
{
115+
"command": "raspberry-pi-pico.getCompilerPath",
116+
"title": "Get compiler path",
117+
"category": "Raspberry Pi Pico",
118+
"enablement": "false"
119+
},
114120
{
115121
"command": "raspberry-pi-pico.getChip",
116122
"title": "Get Chip",

scripts/pico_project.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
903903
{{
904904
"name": "Pico",
905905
"compilers": {{
906-
"C": "{cPath}",
907-
"CXX": "{cPath}"
906+
"C": "${{command:raspberry-pi-pico.getCompilerPath}}",
907+
"CXX": "${{command:raspberry-pi-pico.getCompilerPath}}"
908908
}},
909-
"toolchainFile": "{propertiesSdkPath(sdkVersion)}/cmake/preload/toolchains/{CMAKE_TOOLCHAIN_NAME}",
910909
"environmentVariables": {{
911910
"PATH": "${{command:raspberry-pi-pico.getEnvPath}};${{env:PATH}}"
912911
}},

src/commands/configureCmake.mts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Command } from "./command.mjs";
22
import Logger from "../logger.mjs";
33
import { window, workspace } from "vscode";
44
import { configureCmakeNinja } from "../utils/cmakeUtil.mjs";
5+
import Settings, { SettingsKey } from "../settings.mjs";
56

67
export default class ConfigureCmakeCommand extends Command {
78
private _logger: Logger = new Logger("ConfigureCmakeCommand");
@@ -23,6 +24,20 @@ export default class ConfigureCmakeCommand extends Command {
2324
return;
2425
}
2526

27+
const settings = Settings.getInstance();
28+
29+
if (
30+
settings !== undefined &&
31+
settings.getBoolean(SettingsKey.useCmakeTools)
32+
) {
33+
void window.showErrorMessage(
34+
"You must use the CMake Tools extension to configure your build. " +
35+
"To use this extension instead, change the useCmakeTools setting."
36+
);
37+
38+
return;
39+
}
40+
2641
if (await configureCmakeNinja(workspaceFolder.uri)) {
2742
void window.showInformationMessage("CMake has configured your build.");
2843
} else {

src/commands/getPaths.mts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,44 @@ export class GetGDBPathCommand extends CommandWithResult<string> {
111111
}
112112
}
113113

114+
export class GetCompilerPathCommand extends CommandWithResult<string> {
115+
constructor() {
116+
super("getCompilerPath");
117+
}
118+
119+
async execute(): Promise<string> {
120+
if (
121+
workspace.workspaceFolders === undefined ||
122+
workspace.workspaceFolders.length === 0
123+
) {
124+
return "";
125+
}
126+
127+
const workspaceFolder = workspace.workspaceFolders?.[0];
128+
129+
const selectedToolchainAndSDKVersions =
130+
await cmakeGetSelectedToolchainAndSDKVersions(workspaceFolder.uri);
131+
if (selectedToolchainAndSDKVersions === null) {
132+
return "";
133+
}
134+
const toolchainVersion = selectedToolchainAndSDKVersions[1];
135+
136+
let triple = "arm-none-eabi";
137+
if (toolchainVersion.includes("RISCV")) {
138+
if (toolchainVersion.includes("COREV")) {
139+
triple = "riscv32-corev-elf";
140+
} else {
141+
triple = "riscv32-unknown-elf";
142+
}
143+
}
144+
145+
return join(
146+
buildToolchainPath(toolchainVersion), "bin",
147+
triple + `-gcc${process.platform === "win32" ? ".exe" : ""}`
148+
);
149+
}
150+
}
151+
114152
export class GetChipCommand extends CommandWithResult<string> {
115153
constructor() {
116154
super("getChip");

src/extension.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
GetPythonPathCommand,
3737
GetEnvPathCommand,
3838
GetGDBPathCommand,
39+
GetCompilerPathCommand,
3940
GetChipCommand,
4041
GetTargetCommand,
4142
GetChipUppercaseCommand,
@@ -106,6 +107,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
106107
new GetPythonPathCommand(),
107108
new GetEnvPathCommand(),
108109
new GetGDBPathCommand(),
110+
new GetCompilerPathCommand(),
109111
new GetChipCommand(),
110112
new GetChipUppercaseCommand(),
111113
new GetTargetCommand(),

src/utils/cmakeUtil.mts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,6 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
119119
return false;
120120
}
121121

122-
if (settings.getBoolean(SettingsKey.useCmakeTools)) {
123-
await window.showErrorMessage(
124-
"You must use the CMake Tools extension to configure your build. " +
125-
"To use this extension instead, change the useCmakeTools setting."
126-
);
127-
128-
return false;
129-
}
130-
131122
if (existsSync(join(folder.fsPath, "build", "CMakeCache.txt"))) {
132123
// check if the build directory has been moved
133124

@@ -158,6 +149,16 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
158149
}
159150
}
160151

152+
if (settings.getBoolean(SettingsKey.useCmakeTools)) {
153+
// CMake Tools integration is enabled - skip configuration
154+
Logger.info(
155+
LoggerSource.cmake,
156+
"Skipping CMake configuration, as useCmakeTools is set."
157+
);
158+
159+
return false;
160+
}
161+
161162
try {
162163
// check if CMakeLists.txt exists in the root folder
163164
await workspace.fs.stat(

0 commit comments

Comments
 (0)