Use platform/generator agnostic CMake commands (#2539)

* Use platform/generator agnostic CMake commands

Change the README to use platform/generator agnostic commands to create and build the CMake project

* review fixup

* Apply suggestions from code review

Co-authored-by: Andrew Scheller <andrew.scheller@raspberrypi.com>

* Whitespace fix

---------

Co-authored-by: Andrew Scheller <andrew.scheller@raspberrypi.com>
This commit is contained in:
will-v-pi 2025-07-14 17:20:55 +01:00 committed by GitHub
parent 214c24386a
commit 4ee09729cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -177,12 +177,11 @@ instructions for other platforms, and just in general, we recommend you see [Ras
1. Setup a CMake build directory. 1. Setup a CMake build directory.
For example, if not using an IDE: For example, if not using an IDE:
``` ```
$ mkdir build $ cmake -S . -B build
$ cd build
$ cmake ..
``` ```
> The cmake -S flag indicates the source directory, and the -B flag tells cmake the name of the output-directory to create. This doesn't have to be named "build", you can call it whatever you want.
When building for a board other than the Raspberry Pi Pico, you should pass `-DPICO_BOARD=board_name` to the `cmake` command above, e.g. `cmake -DPICO_BOARD=pico2 ..` or `cmake -DPICO_BOARD=pico_w ..` to configure the SDK and build options accordingly for that particular board. When building for a board other than the Raspberry Pi Pico, you should pass `-DPICO_BOARD=board_name` to the `cmake` command above, e.g. `cmake -S . -B build -DPICO_BOARD=pico2` or `cmake -S . -B build -DPICO_BOARD=pico_w` to configure the SDK and build options accordingly for that particular board.
Specifying `PICO_BOARD=<boardname>` sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain Specifying `PICO_BOARD=<boardname>` sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain
cases also enables the use of additional libraries (e.g. wireless support when building for `PICO_BOARD=pico_w`) which cannot cases also enables the use of additional libraries (e.g. wireless support when building for `PICO_BOARD=pico_w`) which cannot
@ -193,8 +192,9 @@ instructions for other platforms, and just in general, we recommend you see [Ras
1. Make your target from the build directory you created. 1. Make your target from the build directory you created.
```sh ```sh
$ make hello_world $ cmake --build build --target hello_world
``` ```
> The directory-name supplied to the `--build` flag needs to match the directory-name that was passed to the `-B` flag in the earlier cmake command.
1. You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and run on your Raspberry Pi Pico-series device via drag and drop. 1. You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and run on your Raspberry Pi Pico-series device via drag and drop.