Skip to content

Commit

Permalink
Add compilation with CMake Tools
Browse files Browse the repository at this point in the history
Adds support for compiling with CMake Tools, instead of this extension

Also compile project whenever raspberry-pi-pico.launchTargetPath is called, to remove need for the preLaunchTask when debugging

Signed-off-by: William Vinnicombe <[email protected]>
  • Loading branch information
will-v-pi committed Apr 8, 2024
1 parent d6ccd9e commit ccb76a5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
"default": true,
"markdownDescription": "Automatically run configure when opening a Pico project"
},
"raspberry-pi-pico.useCmakeTools": {
"type": "boolean",
"default": false,
"markdownDescription": "Use the CMake Tools extension for CMake configuration, instead of this extension"
},
"raspberry-pi-pico.githubToken": {
"type": "string",
"default": "",
Expand Down
8 changes: 3 additions & 5 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
],
"openOCDLaunchCommands": [
"adapter speed 5000"
],
"preLaunchTask": "Compile Project"
]
}},
{{
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
Expand All @@ -800,8 +799,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"postRestartCommands": [
"break main",
"continue"
],
"preLaunchTask": "Compile Project"
]
}},
{{
"name": "Pico Debug (C++ Debugger)",
Expand Down Expand Up @@ -907,6 +905,7 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
"PATH": "{propertiesToolchainPath(toolchainVersion, force_non_windows=True)}/bin:{os.path.dirname(cmakePath.replace(user_home, "${env:HOME}") if use_home_var else cmakePath)}:{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:${{env:PATH}}"
}},
"raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakePath": "{cmakePath.replace(user_home, "${HOME}") if use_home_var else cmakePath}",
"raspberry-pi-pico.ninjaPath": "{ninjaPath.replace(user_home, "${HOME}") if use_home_var else ninjaPath}"'''

Expand Down Expand Up @@ -949,7 +948,6 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
{{
"label": "Flash",
"type": "process",
"dependsOn": "Compile Project",
"command": "{openocd_path if openocd_path else "openocd"}",
"args": [
"-f",
Expand Down
15 changes: 14 additions & 1 deletion src/commands/compileProject.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { tasks, window } from "vscode";
import { commands, tasks, window } from "vscode";
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import Settings, { SettingsKey } from "../settings.mjs";

export default class CompileProjectCommand extends Command {
private _logger: Logger = new Logger("CompileProjectCommand");
Expand All @@ -19,6 +20,18 @@ export default class CompileProjectCommand extends Command {
return task.name === "Compile Project";
});

const settings = Settings.getInstance();
if (
settings !== undefined && settings.getBoolean(SettingsKey.useCmakeTools)
) {
// Compile with CMake Tools
await commands.executeCommand(
"cmake.launchTargetPath"
);

return;
}

if (task) {
// Execute the task
await tasks.executeTask(task);
Expand Down
19 changes: 18 additions & 1 deletion src/commands/launchTargetPath.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { readFileSync } from "fs";
import { CommandWithResult } from "./command.mjs";
import { window, workspace } from "vscode";
import { commands, window, workspace } from "vscode";
import { join } from "path";
import Settings, { SettingsKey } from "../settings.mjs";

export default class LaunchTargetPathCommand extends CommandWithResult<string> {
constructor() {
Expand Down Expand Up @@ -60,6 +61,19 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
return "";
}

const settings = Settings.getInstance();
if (
settings !== undefined && settings.getBoolean(SettingsKey.useCmakeTools)
) {
// Compile with CMake Tools
const path: string = await commands.executeCommand(
"cmake.launchTargetPath"
);
if (path) {
return path;
}
}

const fsPathFolder = workspace.workspaceFolders[0].uri.fsPath;

const projectName = await this.readProjectNameFromCMakeLists(
Expand All @@ -70,6 +84,9 @@ export default class LaunchTargetPathCommand extends CommandWithResult<string> {
return "";
}

// Compile before returning
await commands.executeCommand("raspberry-pi-pico.compileProject");

return join(fsPathFolder, "build", projectName + ".elf").replaceAll(
"\\",
"/"
Expand Down
1 change: 1 addition & 0 deletions src/settings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum SettingsKey {
gitPath = "gitPath",
cmakeAutoConfigure = "cmakeAutoConfigure",
githubToken = "githubToken",
useCmakeTools = "useCmakeTools",
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/utils/cmakeUtil.mts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ export async function configureCmakeNinja(folder: Uri): Promise<boolean> {
return false;
}

if (settings.getBoolean(SettingsKey.useCmakeTools)) {
await window.showErrorMessage(
"You must use the CMake Tools extension to configure your build. " +
"To use this extension instead, change the useCmakeTools setting."
);

return false;
}

try {
// check if CMakeLists.txt exists in the root folder
await workspace.fs.stat(
Expand Down

0 comments on commit ccb76a5

Please sign in to comment.