From 8d6e3ea367cfa94d5fd0570b7b72c72e5d6c2ed4 Mon Sep 17 00:00:00 2001 From: will-v-pi <108662275+will-v-pi@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:35:39 +0100 Subject: [PATCH 1/3] Add CMake Tools settings to readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 60868c3c..e3d63d1d 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,22 @@ This extension provides the following settings: * `raspberry-pi-pico.gitPath`: Specify a custom path for Git. * `raspberry-pi-pico.cmakeAutoConfigure`: Provide a GitHub personal access token (classic) with the `public_repo` scope. This token is used to check for available versions of the Pico SDK and other tools. Without it, the extension uses the unauthenticated GitHub API, which has a lower rate limit and may lead to restricted functionality if the limit is exceeded. The unauthenticated rate limit is per public IP address, so a token is more necessary if your IP is shared with many users. +## Using the CMake Tools extension +By default, this extension only supports projects with a single executable who's name matches the project name, and the project name cannot be a variable. For more complex projects that require better CMake parsing (for example with multiple executables, or if the project name is set by a variable), this extension can integrate with the CMake Tools extension to perform that parsing. You can enable the CMake Tools extension by changing the following settings in your `settings.json` file: + +* `raspberry-pi-pico.cmakeAutoConfigure`: From `true` to `false` +* `raspberry-pi-pico.useCmakeTools`: From `false` to `true` + +You may also wish to enable the following settings as well, as the default `settings.json` file disables a lot of the CMake Tools functionality: + +* `cmake.configureOnEdit`: true +* `cmake.automaticReconfigure`: true +* `cmake.configureOnOpen`: true + +When prompted to select a kit by the CMake Tools extension, you should pick the `Pico` kit. You can then use the CMake Tools extension to set your Build and Launch targets appropriately. + +Once the Launch target has been set correctly, this extension should continue to work seamlessly with debugging etc, it will just use CMake Tools for compilation rather than it's own backend. Do not use the CMake Tools debugging functionality, as that will not work with the Pico. + ## VS Code Profiles If you work with multiple microcontroller toolchains, consider installing this extension into a [VS Code Profile](https://code.visualstudio.com/docs/editor/profiles) to avoid conflicts with other toolchains. Follow these steps: From 2c12de23f96c83b97ffd227499435f394099cfcd Mon Sep 17 00:00:00 2001 From: paulober <44974737+paulober@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:51:52 +0100 Subject: [PATCH 2/3] Added CMake tools extension integration to the project generator Signed-off-by: paulober <44974737+paulober@users.noreply.github.com> --- README.md | 19 ++++++++--------- scripts/pico_project.py | 19 ++++++++++------- src/webview/newProjectPanel.mts | 38 ++++++++++++++++++++++++--------- web/main.js | 4 +++- web/state.js | 10 ++++++++- 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index e3d63d1d..ef529aec 100644 --- a/README.md +++ b/README.md @@ -62,21 +62,20 @@ This extension provides the following settings: * `raspberry-pi-pico.gitPath`: Specify a custom path for Git. * `raspberry-pi-pico.cmakeAutoConfigure`: Provide a GitHub personal access token (classic) with the `public_repo` scope. This token is used to check for available versions of the Pico SDK and other tools. Without it, the extension uses the unauthenticated GitHub API, which has a lower rate limit and may lead to restricted functionality if the limit is exceeded. The unauthenticated rate limit is per public IP address, so a token is more necessary if your IP is shared with many users. -## Using the CMake Tools extension -By default, this extension only supports projects with a single executable who's name matches the project name, and the project name cannot be a variable. For more complex projects that require better CMake parsing (for example with multiple executables, or if the project name is set by a variable), this extension can integrate with the CMake Tools extension to perform that parsing. You can enable the CMake Tools extension by changing the following settings in your `settings.json` file: +## CMake Tools Extension Integration -* `raspberry-pi-pico.cmakeAutoConfigure`: From `true` to `false` -* `raspberry-pi-pico.useCmakeTools`: From `false` to `true` +For more complex projects, such as those with multiple executables or when the project name is defined as a variable, this extension can integrate with the CMake Tools extension to enhance CMake parsing. You can enable CMake Tools integration during project generation under the **Advanced Options**. Additionally, to manually enable it, adjust the following settings in your `settings.json`: -You may also wish to enable the following settings as well, as the default `settings.json` file disables a lot of the CMake Tools functionality: +- `raspberry-pi-pico.cmakeAutoConfigure`: Set from `true` to `false`. +- `raspberry-pi-pico.useCmakeTools`: Set from `false` to `true`. -* `cmake.configureOnEdit`: true -* `cmake.automaticReconfigure`: true -* `cmake.configureOnOpen`: true +For optimal functionality, consider enabling: -When prompted to select a kit by the CMake Tools extension, you should pick the `Pico` kit. You can then use the CMake Tools extension to set your Build and Launch targets appropriately. +- `cmake.configureOnEdit`: true +- `cmake.automaticReconfigure`: true +- `cmake.configureOnOpen`: true -Once the Launch target has been set correctly, this extension should continue to work seamlessly with debugging etc, it will just use CMake Tools for compilation rather than it's own backend. Do not use the CMake Tools debugging functionality, as that will not work with the Pico. +When prompted, select the `Pico` kit in CMake Tools, and set your build and launch targets accordingly. Use CMake Tools for compilation, but continue using this extension for debugging, as CMake Tools debugging is not compatible with Pico. ## VS Code Profiles diff --git a/scripts/pico_project.py b/scripts/pico_project.py index 0f426b1c..8bd0cb94 100644 --- a/scripts/pico_project.py +++ b/scripts/pico_project.py @@ -483,6 +483,7 @@ def ParseCommandLine(): parser.add_argument("-cupy", "--customPython", action='store_true', help="Custom python path used to execute the script.") parser.add_argument("-openOCDVersion", "--openOCDVersion", help="OpenOCD version to use - defaults to 0", default=0) parser.add_argument("-examLibs", "--exampleLibs", action='append', help="Include an examples library in the folder") + parser.add_argument("-ucmt", "--useCmakeTools", action='store_true', help="Enable CMake Tools extension integration") return parser.parse_args() @@ -765,7 +766,7 @@ def GenerateCMake(folder, params): # Generates the requested project files, if any -def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion): +def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion, useCmakeTools): oldCWD = os.getcwd() @@ -929,9 +930,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, "statusBarVisibility": "hidden" }} }}, - "cmake.configureOnEdit": false, - "cmake.automaticReconfigure": false, - "cmake.configureOnOpen": false, + "cmake.configureOnEdit": {"true" if useCmakeTools else "false"}, + "cmake.automaticReconfigure": {"true" if useCmakeTools else "false"}, + "cmake.configureOnOpen": {"true" if useCmakeTools else "false"}, "cmake.generator": "Ninja", "cmake.cmakePath": "{cmakePath.replace(user_home, "${userHome}") if use_home_var else cmakePath}", "C_Cpp.debugShortcut": false, @@ -965,8 +966,8 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, {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.cmakeAutoConfigure": {"false" if useCmakeTools else "true"}, + "raspberry-pi-pico.useCmakeTools": {"true" if useCmakeTools else "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}"''' @@ -1236,7 +1237,8 @@ def DoEverything(parent, params): params["ninjaPath"], params["cmakePath"], params["customPython"], - params["openOCDVersion"]) + params["openOCDVersion"], + params['useCmakeTools']) if params['wantBuild']: os.system(makeCmd) @@ -1360,7 +1362,8 @@ def DoEverything(parent, params): 'cmakePath' : args.cmakePath, 'customPython' : args.customPython, 'openOCDVersion': args.openOCDVersion, - 'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else [] + 'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else [], + 'useCmakeTools' : args.useCmakeTools } DoEverything(None, params) diff --git a/src/webview/newProjectPanel.mts b/src/webview/newProjectPanel.mts index 85d9bb82..4eed11c2 100644 --- a/src/webview/newProjectPanel.mts +++ b/src/webview/newProjectPanel.mts @@ -82,6 +82,7 @@ interface ImportProjectMessageValue { // debugger debugger: number; + useCmakeTools: boolean; } interface SubmitExampleMessageValue extends ImportProjectMessageValue { @@ -268,6 +269,7 @@ interface ImportProjectOptions { ninjaExecutable: string; cmakeExecutable: string; debugger: Debugger; + useCmakeTools: boolean; } interface NewExampleBasedProjectOptions extends ImportProjectOptions { @@ -1123,6 +1125,7 @@ export class NewProjectPanel { }, ninjaExecutable, cmakeExecutable, + useCmakeTools: data.useCmakeTools, }; await this._executePicoProjectGenerator( @@ -1147,6 +1150,7 @@ export class NewProjectPanel { }, ninjaExecutable, cmakeExecutable, + useCmakeTools: data.useCmakeTools, }; await this._executePicoProjectGenerator( @@ -1168,6 +1172,7 @@ export class NewProjectPanel { ninjaExecutable, cmakeExecutable, debugger: data.debugger === 1 ? Debugger.swd : Debugger.debugProbe, + useCmakeTools: data.useCmakeTools, }; await this._executePicoProjectGenerator( @@ -1987,18 +1992,30 @@ export class NewProjectPanel { ` : "" } -
-

Debugger

-
-
- - -
-
- - + +
+
+

Debugger

+
+
+ + +
+
+ + +
+
@@ -2192,6 +2209,7 @@ export class NewProjectPanel { `"${options.ninjaExecutable}"`, "--cmakePath", `"${options.cmakeExecutable}"`, + options.useCmakeTools ? "-ucmt" : "", // set custom python executable path used flag if python executable is not in PATH pythonExe.includes("/") ? "-cupy" : "", diff --git a/web/main.js b/web/main.js index 3d0d4699..d3520755 100644 --- a/web/main.js +++ b/web/main.js @@ -366,6 +366,7 @@ var exampleSupportedBoards = []; const cppCodeGen = document.getElementById('cpp-code-gen-cblist').checked; const cppRttiCodeGen = document.getElementById('cpp-rtti-code-gen-cblist').checked; const cppExceptionsCodeGen = document.getElementById('cpp-exceptions-code-gen-cblist').checked; + const useCmakeTools = document.getElementById('use-cmake-tools-cb').checked; //post all data values to the extension vscode.postMessage({ @@ -410,7 +411,8 @@ var exampleSupportedBoards = []; cppExceptions: cppExceptionsCodeGen, // debugger selection - debugger: debuggerSelection + debugger: debuggerSelection, + useCmakeTools } }); } diff --git a/web/state.js b/web/state.js index e6461465..8b42a6c2 100644 --- a/web/state.js +++ b/web/state.js @@ -31,6 +31,7 @@ class State { cppExceptionsCodeGen; selRiscv; debuggerSelection; + useCMakeTools; // special ui only state uiShowAdvancedOptions; @@ -157,12 +158,16 @@ function restoreState(state) { document.getElementById('pico-wireless-radio-background').checked = state.picoWirelessSelection == 3; } // instead of setting debug-probe if selection is undefined or 0, - // first check so the default can be controlled in the html + // first check so the default can be controlled in the html if (state.debuggerSelection !== undefined) { document.getElementById('debugger-radio-debug-probe').checked = state.debuggerSelection == 0; document.getElementById('debugger-radio-swd').checked = state.debuggerSelection == 1; } + if (state.useCMakeTools !== undefined) { + document.getElementById('use-cmake-tools-cb').checked = state.useCMakeTools; + } + // instead of setting ninja-radio-default-version if selection is undefined or 0, // first check so the default can be controlled in the html if (state.ninjaMode !== undefined) { @@ -444,6 +449,9 @@ function setupStateSystem(vscode) { case "sel-riscv": state.selRiscv = checkbox.checked; break; + case "use-cmake-tools-cb": + state.useCMakeTools = checkbox.checked; + break; } vscode.setState(state); From d07eb73b0cfd3ac4e905e8f7628d82091036bc32 Mon Sep 17 00:00:00 2001 From: paulober <44974737+paulober@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:51:17 +0100 Subject: [PATCH 3/3] Fix cmake tools selection for import and examples Signed-off-by: paulober <44974737+paulober@users.noreply.github.com> --- web/main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/main.js b/web/main.js index d3520755..7b3ef1cf 100644 --- a/web/main.js +++ b/web/main.js @@ -275,6 +275,7 @@ var exampleSupportedBoards = []; submitted = false; return; } + const useCmakeTools = document.getElementById('use-cmake-tools-cb').checked; if (doProjectImport) { vscode.postMessage({ @@ -293,7 +294,8 @@ var exampleSupportedBoards = []; pythonPath: pythonPath, // debugger selection - debugger: 0 + debugger: 0, + useCmakeTools } }); return; @@ -319,7 +321,8 @@ var exampleSupportedBoards = []; pythonPath: pythonPath, // debugger selection - debugger: debuggerSelection + debugger: debuggerSelection, + useCmakeTools } }); return; @@ -366,7 +369,6 @@ var exampleSupportedBoards = []; const cppCodeGen = document.getElementById('cpp-code-gen-cblist').checked; const cppRttiCodeGen = document.getElementById('cpp-rtti-code-gen-cblist').checked; const cppExceptionsCodeGen = document.getElementById('cpp-exceptions-code-gen-cblist').checked; - const useCmakeTools = document.getElementById('use-cmake-tools-cb').checked; //post all data values to the extension vscode.postMessage({