Skip to content

Commit 2c12de2

Browse files
committed
Added CMake tools extension integration to the project generator
Signed-off-by: paulober <[email protected]>
1 parent 8d6e3ea commit 2c12de2

File tree

5 files changed

+60
-30
lines changed

5 files changed

+60
-30
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,20 @@ This extension provides the following settings:
6262
* `raspberry-pi-pico.gitPath`: Specify a custom path for Git.
6363
* `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.
6464

65-
## Using the CMake Tools extension
66-
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:
65+
## CMake Tools Extension Integration
6766

68-
* `raspberry-pi-pico.cmakeAutoConfigure`: From `true` to `false`
69-
* `raspberry-pi-pico.useCmakeTools`: From `false` to `true`
67+
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`:
7068

71-
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:
69+
- `raspberry-pi-pico.cmakeAutoConfigure`: Set from `true` to `false`.
70+
- `raspberry-pi-pico.useCmakeTools`: Set from `false` to `true`.
7271

73-
* `cmake.configureOnEdit`: true
74-
* `cmake.automaticReconfigure`: true
75-
* `cmake.configureOnOpen`: true
72+
For optimal functionality, consider enabling:
7673

77-
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.
74+
- `cmake.configureOnEdit`: true
75+
- `cmake.automaticReconfigure`: true
76+
- `cmake.configureOnOpen`: true
7877

79-
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.
78+
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.
8079

8180
## VS Code Profiles
8281

scripts/pico_project.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ def ParseCommandLine():
483483
parser.add_argument("-cupy", "--customPython", action='store_true', help="Custom python path used to execute the script.")
484484
parser.add_argument("-openOCDVersion", "--openOCDVersion", help="OpenOCD version to use - defaults to 0", default=0)
485485
parser.add_argument("-examLibs", "--exampleLibs", action='append', help="Include an examples library in the folder")
486+
parser.add_argument("-ucmt", "--useCmakeTools", action='store_true', help="Enable CMake Tools extension integration")
486487

487488
return parser.parse_args()
488489

@@ -765,7 +766,7 @@ def GenerateCMake(folder, params):
765766

766767

767768
# Generates the requested project files, if any
768-
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion):
769+
def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger, sdkVersion, toolchainVersion, picotoolVersion, ninjaPath, cmakePath, customPython, openOCDVersion, useCmakeTools):
769770

770771
oldCWD = os.getcwd()
771772

@@ -929,9 +930,9 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
929930
"statusBarVisibility": "hidden"
930931
}}
931932
}},
932-
"cmake.configureOnEdit": false,
933-
"cmake.automaticReconfigure": false,
934-
"cmake.configureOnOpen": false,
933+
"cmake.configureOnEdit": {"true" if useCmakeTools else "false"},
934+
"cmake.automaticReconfigure": {"true" if useCmakeTools else "false"},
935+
"cmake.configureOnOpen": {"true" if useCmakeTools else "false"},
935936
"cmake.generator": "Ninja",
936937
"cmake.cmakePath": "{cmakePath.replace(user_home, "${userHome}") if use_home_var else cmakePath}",
937938
"C_Cpp.debugShortcut": false,
@@ -965,8 +966,8 @@ def generateProjectFiles(projectPath, projectName, sdkPath, projects, debugger,
965966
{os.path.dirname(ninjaPath.replace(user_home, "${env:HOME}") if use_home_var else ninjaPath)}:\
966967
${{env:PATH}}"
967968
}},
968-
"raspberry-pi-pico.cmakeAutoConfigure": true,
969-
"raspberry-pi-pico.useCmakeTools": false,
969+
"raspberry-pi-pico.cmakeAutoConfigure": {"false" if useCmakeTools else "true"},
970+
"raspberry-pi-pico.useCmakeTools": {"true" if useCmakeTools else "false"},
970971
"raspberry-pi-pico.cmakePath": "{cmakePath.replace(user_home, "${HOME}") if use_home_var else cmakePath}",
971972
"raspberry-pi-pico.ninjaPath": "{ninjaPath.replace(user_home, "${HOME}") if use_home_var else ninjaPath}"'''
972973

@@ -1236,7 +1237,8 @@ def DoEverything(parent, params):
12361237
params["ninjaPath"],
12371238
params["cmakePath"],
12381239
params["customPython"],
1239-
params["openOCDVersion"])
1240+
params["openOCDVersion"],
1241+
params['useCmakeTools'])
12401242

12411243
if params['wantBuild']:
12421244
os.system(makeCmd)
@@ -1360,7 +1362,8 @@ def DoEverything(parent, params):
13601362
'cmakePath' : args.cmakePath,
13611363
'customPython' : args.customPython,
13621364
'openOCDVersion': args.openOCDVersion,
1363-
'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else []
1365+
'exampleLibs' : args.exampleLibs if args.exampleLibs is not None else [],
1366+
'useCmakeTools' : args.useCmakeTools
13641367
}
13651368

13661369
DoEverything(None, params)

src/webview/newProjectPanel.mts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface ImportProjectMessageValue {
8282

8383
// debugger
8484
debugger: number;
85+
useCmakeTools: boolean;
8586
}
8687

8788
interface SubmitExampleMessageValue extends ImportProjectMessageValue {
@@ -268,6 +269,7 @@ interface ImportProjectOptions {
268269
ninjaExecutable: string;
269270
cmakeExecutable: string;
270271
debugger: Debugger;
272+
useCmakeTools: boolean;
271273
}
272274

273275
interface NewExampleBasedProjectOptions extends ImportProjectOptions {
@@ -1123,6 +1125,7 @@ export class NewProjectPanel {
11231125
},
11241126
ninjaExecutable,
11251127
cmakeExecutable,
1128+
useCmakeTools: data.useCmakeTools,
11261129
};
11271130

11281131
await this._executePicoProjectGenerator(
@@ -1147,6 +1150,7 @@ export class NewProjectPanel {
11471150
},
11481151
ninjaExecutable,
11491152
cmakeExecutable,
1153+
useCmakeTools: data.useCmakeTools,
11501154
};
11511155

11521156
await this._executePicoProjectGenerator(
@@ -1168,6 +1172,7 @@ export class NewProjectPanel {
11681172
ninjaExecutable,
11691173
cmakeExecutable,
11701174
debugger: data.debugger === 1 ? Debugger.swd : Debugger.debugProbe,
1175+
useCmakeTools: data.useCmakeTools,
11711176
};
11721177

11731178
await this._executePicoProjectGenerator(
@@ -1987,18 +1992,30 @@ export class NewProjectPanel {
19871992
</div>`
19881993
: ""
19891994
}
1990-
<div id="section-debugger" class="snap-start mt-10">
1991-
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
1992-
<div class="flex items-stretch space-x-4">
1993-
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
1994-
<input checked id="debugger-radio-debug-probe" type="radio" value="0" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
1995-
<label for="debugger-radio-debug-probe" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">DebugProbe (CMSIS-DAP) [Default]</label>
1996-
</div>
1997-
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
1998-
<input id="debugger-radio-swd" type="radio" value="1" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
1999-
<label for="debugger-radio-swd" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">SWD (Pi host, on Pi 5 it requires Linux Kernel >= 6.6.47)</label>
1995+
1996+
<div class="grid gap-6 grid-cols-3 mt-10">
1997+
<div id="section-debugger" class="snap-start col-span-2">
1998+
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
1999+
<div class="flex items-stretch space-x-4">
2000+
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
2001+
<input checked id="debugger-radio-debug-probe" type="radio" value="0" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
2002+
<label for="debugger-radio-debug-probe" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">DebugProbe (CMSIS-DAP) [Default]</label>
2003+
</div>
2004+
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
2005+
<input id="debugger-radio-swd" type="radio" value="1" name="debugger-radio" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
2006+
<label for="debugger-radio-swd" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">SWD (Pi host, on Pi 5 it requires Linux Kernel >= 6.6.47)</label>
2007+
</div>
20002008
</div>
20012009
</div>
2010+
<div id="section-extension-integration" class="snap-end advanced-option" hidden>
2011+
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">CMake Tools</h3>
2012+
<div class="flex items-stretch space-x-4">
2013+
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
2014+
<input id="use-cmake-tools-cb" type="checkbox" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
2015+
<label for="use-cmake-tools-cb" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">Enable CMake-Tools extension integration</label>
2016+
</div>
2017+
</div>
2018+
</div>
20022019
</div>
20032020
<div class="bottom-3 mt-8 mb-12 w-full flex justify-end">
20042021
<button id="btn-advanced-options" class="focus:outline-none bg-transparent ring-2 focus:ring-4 ring-yellow-400 dark:ring-yellow-700 font-medium rounded-lg text-lg px-4 py-2 mr-4 hover:bg-yellow-500 dark:hover:bg-yellow-700 focus:ring-yellow-600 dark:focus:ring-yellow-800">Show Advanced Options</button>
@@ -2192,6 +2209,7 @@ export class NewProjectPanel {
21922209
`"${options.ninjaExecutable}"`,
21932210
"--cmakePath",
21942211
`"${options.cmakeExecutable}"`,
2212+
options.useCmakeTools ? "-ucmt" : "",
21952213

21962214
// set custom python executable path used flag if python executable is not in PATH
21972215
pythonExe.includes("/") ? "-cupy" : "",

web/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ var exampleSupportedBoards = [];
366366
const cppCodeGen = document.getElementById('cpp-code-gen-cblist').checked;
367367
const cppRttiCodeGen = document.getElementById('cpp-rtti-code-gen-cblist').checked;
368368
const cppExceptionsCodeGen = document.getElementById('cpp-exceptions-code-gen-cblist').checked;
369+
const useCmakeTools = document.getElementById('use-cmake-tools-cb').checked;
369370

370371
//post all data values to the extension
371372
vscode.postMessage({
@@ -410,7 +411,8 @@ var exampleSupportedBoards = [];
410411
cppExceptions: cppExceptionsCodeGen,
411412

412413
// debugger selection
413-
debugger: debuggerSelection
414+
debugger: debuggerSelection,
415+
useCmakeTools
414416
}
415417
});
416418
}

web/state.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class State {
3131
cppExceptionsCodeGen;
3232
selRiscv;
3333
debuggerSelection;
34+
useCMakeTools;
3435

3536
// special ui only state
3637
uiShowAdvancedOptions;
@@ -157,12 +158,16 @@ function restoreState(state) {
157158
document.getElementById('pico-wireless-radio-background').checked = state.picoWirelessSelection == 3;
158159
}
159160
// instead of setting debug-probe if selection is undefined or 0,
160-
// first check so the default can be controlled in the html
161+
// first check so the default can be controlled in the html
161162
if (state.debuggerSelection !== undefined) {
162163
document.getElementById('debugger-radio-debug-probe').checked = state.debuggerSelection == 0;
163164
document.getElementById('debugger-radio-swd').checked = state.debuggerSelection == 1;
164165
}
165166

167+
if (state.useCMakeTools !== undefined) {
168+
document.getElementById('use-cmake-tools-cb').checked = state.useCMakeTools;
169+
}
170+
166171
// instead of setting ninja-radio-default-version if selection is undefined or 0,
167172
// first check so the default can be controlled in the html
168173
if (state.ninjaMode !== undefined) {
@@ -444,6 +449,9 @@ function setupStateSystem(vscode) {
444449
case "sel-riscv":
445450
state.selRiscv = checkbox.checked;
446451
break;
452+
case "use-cmake-tools-cb":
453+
state.useCMakeTools = checkbox.checked;
454+
break;
447455
}
448456

449457
vscode.setState(state);

0 commit comments

Comments
 (0)