Parse included board files for pico_cmake_set declarations #2113

Closed
will-v-pi wants to merge 1 commit from cmake-set-includes into develop
will-v-pi commented 2024-11-28 08:19:51 -06:00 (Migrated from github.com)

Currently if you have a #include within a board header file (eg in vgaboard.h) any pico_cmake_set and pico_cmake_set_default declarations in the included file aren't parsed (#2112)

This fixes #2112 by parsing those files for these comments. It only parses includes which start with boards/, as it needs to extract the .h file directly for use with pico_find_in_paths.

The inclusion order matches what would be expected (I think) - ie:

// pico_cmake_set PICO_PLATFORM = rp2350

#include "boards/pico.h"

gives PICO_PLATFORM = rp2040 from pico.h,

#include "boards/pico.h"

// pico_cmake_set PICO_PLATFORM = rp2350

gives PICO_PLATFORM = rp2350,

// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024)
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024)
#endif

#include "boards/pico.h"

gives PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) (matching the pre-processor defines), and

#include "boards/pico.h"

// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024)
#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024)
#endif

gives PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024) from pico.h (again matching the pre-processor defines)

Currently if you have a `#include` within a board header file (eg in [vgaboard.h](https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/vgaboard.h)) any `pico_cmake_set` and `pico_cmake_set_default` declarations in the included file aren't parsed (#2112) This fixes #2112 by parsing those files for these comments. It only parses includes which start with `boards/`, as it needs to extract the `.h` file directly for use with `pico_find_in_paths`. The inclusion order matches what would be expected (I think) - ie: ```c // pico_cmake_set PICO_PLATFORM = rp2350 #include "boards/pico.h" ``` gives `PICO_PLATFORM = rp2040` from `pico.h`, ```c #include "boards/pico.h" // pico_cmake_set PICO_PLATFORM = rp2350 ``` gives `PICO_PLATFORM = rp2350`, ```c // pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif #include "boards/pico.h" ``` gives `PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024)` (matching the pre-processor defines), and ```c #include "boards/pico.h" // pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (8 * 1024 * 1024) #ifndef PICO_FLASH_SIZE_BYTES #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) #endif ``` gives `PICO_FLASH_SIZE_BYTES = (2 * 1024 * 1024)` from `pico.h` (again matching the pre-processor defines)
lurch commented 2024-11-28 09:25:11 -06:00 (Migrated from github.com)

If the behaviour matches what the pre-processor does, then I think this sounds great! Well done @will-v-pi 😃

If the behaviour matches what the pre-processor does, then I think this sounds great! Well done @will-v-pi :smiley:

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!2113
No description provided.