Skip to content

Commit 0cc869f

Browse files
committed
CMakeLists: add support for external overlays
I am currently working on a project where I use ArduinoCore as a module in order to use arduino libraries. I am using an AtomS3 board and I don't want to add it explicitly to the ArduinoCore/variants. These changes will allow the user to provide their own overlay in their project without having to modify the library pulled in by west. If they don't provide an overlay their build will fail anyways due to missing zephyr,user section. If this is not the right approach would adding the AtomS3 board to the variants be a good PR? Signed-off-by: Michal Gagos <lizard123137@gmail.com>
1 parent b16b96f commit 0cc869f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ if (CONFIG_ARDUINO_API)
88
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${NORMALIZED_BOARD_TARGET})
99
set(variant_dir variants/${NORMALIZED_BOARD_TARGET})
1010
else()
11-
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${NORMALIZED_BOARD_TARGET}")
11+
message(WARNING
12+
"Variant dir not found: variants/${BOARD}, variants/${NORMALIZED_BOARD_TARGET}\n"
13+
"Your board is currently not supported. To use it you must create a DTS overlay."
14+
)
15+
set(variant_dir variants/default)
1216
endif()
1317

1418
add_subdirectory(cores)

documentation/variants.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ variants/
4545
- The `Cmakelists` help the compiler locate the proper directory to help find the proper header files that are board specific. You need to add the name using `zephyr_include_directories(BOARD_NAME)` to this file. Do note that this `BOARD_NAME` is the same as the name of your board's directory.
4646
- `variant.h` contains the necessary `#includes` inorder to tell the source code about your board's pinmap.
4747
- The `<BOARD_NAME>` folder is where the overlay and pinmap file resides. Inorder to understand how to write DT overlays, lookup `Documentation/overlays.md`. To understand the `<boardname_pinmap.h>` file, go through the existing `variants/ARDUINO_NANO33BLE/arduino_nano_ble_sense_pinmap.h` which shows how to use the overlay nodes inside our C programs using zephyr macros like `GPIO_DT_SPEC_GET`. The zephyr-project documentation on this is pretty extensive as well and worth reading.
48+
- It is also possible to apply the overlay outside of the `variants` folder. In that case `cmake` will show a warning and a default empty `variant.h` file will be used. The `zephyr,user` section will still need to be defined somewhere in your project, as described in the [Guide to Writing Overlays section](#guide-to-writing-overlays).
4849

4950
## Guide to Writing Overlays
5051

variants/default/variant.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2026 Michal Gagos
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once

0 commit comments

Comments
 (0)