Skip to content

Commit f19207e

Browse files
committed
Refactor CMakeLists.txt to improve path handling for MicroPython ESP32
1 parent 9322c19 commit f19207e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
# Include MicroPython ESP32 component.
22

3-
get_filename_component(CURRENT_DIR "." ABSOLUTE)
3+
get_filename_component(CURRENT_DIR "${CMAKE_CURRENT_LIST_DIR}" ABSOLUTE)
44
message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}")
55

6-
get_filename_component(MICROPY_DIR "../../../third_party/micropython" ABSOLUTE)
6+
# Compute MICROPY_DIR relative to this file to avoid brittle relative paths.
7+
get_filename_component(MICROPY_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../third_party/micropython" ABSOLUTE)
8+
get_filename_component(MICROPY_PORT_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../third_party/micropython/ports/esp32" REALPATH)
79

8-
message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}")
910

10-
set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32)
11-
include(${PROJECT_DIR}/main_esp32s3/CMakeLists.txt)
11+
message(STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}")
12+
13+
message(STATUS "Including ${MICROPY_PORT_DIR}/main/CMakeLists.txt")
14+
include("${MICROPY_PORT_DIR}/main/CMakeLists.txt")
15+
16+
## Prefer the S3-specific entry if present, otherwise fall back to the generic one.
17+
#if(EXISTS "${MICROPY_PORT_DIR}/main_esp32s3/CMakeLists.txt")
18+
# message(STATUS "Including ${MICROPY_PORT_DIR}/main_esp32s3/CMakeLists.txt")
19+
# include("${MICROPY_PORT_DIR}/main_esp32s3/CMakeLists.txt")
20+
#elseif(EXISTS "${MICROPY_PORT_DIR}/main/CMakeLists.txt")
21+
#
22+
#else()
23+
# message(FATAL_ERROR "Could not find MicroPython ESP32 entry CMakeLists in ${MICROPY_PORT_DIR}. Expected one of:\n ${MICROPY_PORT_DIR}/main_esp32s3/CMakeLists.txt\n ${MICROPY_PORT_DIR}/main/CMakeLists.txt\nCheck that third_party/micropython/ports/esp32 exists and contains the correct CMake entry.")
24+
#endif()

0 commit comments

Comments
 (0)