Skip to content

Commit

Permalink
Added CMake tools extension integration to the project generator
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 11, 2024
1 parent aced124 commit 8f458a6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,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

Expand Down
21 changes: 12 additions & 9 deletions scripts/pico_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def GDB_NAME():
"// UART defines",
"// By default the stdout UART is `uart0`, so we will use the second one",
"#define UART_ID uart1",
"#define BAUD_RATE 9600", "",
"#define BAUD_RATE 115200", "",
"// Use pins 4 and 5 for UART1",
"// Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments",
"#define UART_TX_PIN 4",
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -931,9 +932,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,
Expand Down Expand Up @@ -967,8 +968,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}"'''

Expand Down Expand Up @@ -1238,7 +1239,8 @@ def DoEverything(parent, params):
params["ninjaPath"],
params["cmakePath"],
params["customPython"],
params["openOCDVersion"])
params["openOCDVersion"],
params['useCmakeTools'])

if params['wantBuild']:
os.system(makeCmd)
Expand Down Expand Up @@ -1362,7 +1364,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)
Expand Down
38 changes: 28 additions & 10 deletions src/webview/newProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface ImportProjectMessageValue {

// debugger
debugger: number;
useCmakeTools: boolean;
}

interface SubmitExampleMessageValue extends ImportProjectMessageValue {
Expand Down Expand Up @@ -268,6 +269,7 @@ interface ImportProjectOptions {
ninjaExecutable: string;
cmakeExecutable: string;
debugger: Debugger;
useCmakeTools: boolean;
}

interface NewExampleBasedProjectOptions extends ImportProjectOptions {
Expand Down Expand Up @@ -1119,6 +1121,7 @@ export class NewProjectPanel {
},
ninjaExecutable,
cmakeExecutable,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand All @@ -1143,6 +1146,7 @@ export class NewProjectPanel {
},
ninjaExecutable,
cmakeExecutable,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand All @@ -1164,6 +1168,7 @@ export class NewProjectPanel {
ninjaExecutable,
cmakeExecutable,
debugger: data.debugger === 1 ? Debugger.swd : Debugger.debugProbe,
useCmakeTools: data.useCmakeTools,
};

await this._executePicoProjectGenerator(
Expand Down Expand Up @@ -1983,18 +1988,30 @@ export class NewProjectPanel {
</div>`
: ""
}
<div id="section-debugger" class="snap-start mt-10">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<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">
<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>
</div>
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<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">
<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>
<div class="grid gap-6 grid-cols-3 mt-10">
<div id="section-debugger" class="snap-start col-span-2">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">Debugger</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<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">
<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>
</div>
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<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">
<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>
</div>
</div>
</div>
<div id="section-extension-integration" class="snap-end advanced-option" hidden>
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">CMake Tools</h3>
<div class="flex items-stretch space-x-4">
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
<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">
<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>
</div>
</div>
</div>
</div>
<div class="bottom-3 mt-8 mb-12 w-full flex justify-end">
<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>
Expand Down Expand Up @@ -2188,6 +2205,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" : "",
Expand Down
4 changes: 3 additions & 1 deletion web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -410,7 +411,8 @@ var exampleSupportedBoards = [];
cppExceptions: cppExceptionsCodeGen,

// debugger selection
debugger: debuggerSelection
debugger: debuggerSelection,
useCmakeTools
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions web/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class State {
cppExceptionsCodeGen;
selRiscv;
debuggerSelection;
useCMakeTools;

// special ui only state
uiShowAdvancedOptions;
Expand Down Expand Up @@ -163,6 +164,10 @@ function restoreState(state) {
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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8f458a6

Please sign in to comment.