Skip to content

Commit 9407004

Browse files
committed
Update cmake file for IDB <= 5.3
1 parent a97ab12 commit 9407004

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

src/micropython.cmake

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,73 @@
1-
# Include the py.cmake for additional macro micropy_gather_target_properties usage
21
include(${MICROPY_DIR}/py/py.cmake)
32

4-
# Create an INTERFACE library for the camera module and sdd source files to the library
3+
# IDF version >= 5.4 not supported yet
4+
message(STATUS "IDF_VERSION: ${IDF_VER}")
5+
if (NOT IDF_VERSION_MINOR VERSION_LESS 4)
6+
message(FATAL_ERROR "ESP-IDF version >= 5.4 or later is not supported by micropython with the esp32-camera yet. Please use IDF 5.2 or 5.3")
7+
endif()
8+
59
add_library(usermod_mp_camera INTERFACE)
10+
611
target_sources(usermod_mp_camera INTERFACE
712
${CMAKE_CURRENT_LIST_DIR}/modcamera.c
813
${CMAKE_CURRENT_LIST_DIR}/modcamera_api.c
914
)
1015

11-
if(NOT ESP32_CAMERA_DIR)
12-
set(ESP32_CAMERA_DIR "${IDF_PATH}/components/esp32-camera")
13-
endif()
14-
15-
message("Camera Dir: ${ESP32_CAMERA_DIR}")
16+
# Prefer user-defined ESP32_CAMERA_DIR if provided
17+
if(DEFINED ESP32_CAMERA_DIR AND EXISTS "${ESP32_CAMERA_DIR}")
18+
message(STATUS "Using user-defined ESP32 Camera directory: ${ESP32_CAMERA_DIR}")
1619

17-
if(EXISTS "${ESP32_CAMERA_DIR}")
1820
target_include_directories(usermod_mp_camera INTERFACE
1921
${CMAKE_CURRENT_LIST_DIR}
2022
${ESP32_CAMERA_DIR}/driver/include
21-
${ESP32_CAMERA_DIR}/driver/private_include
2223
${ESP32_CAMERA_DIR}/conversions/include
24+
${ESP32_CAMERA_DIR}/driver/private_include
2325
${ESP32_CAMERA_DIR}/conversions/private_include
2426
${ESP32_CAMERA_DIR}/sensors/private_include
2527
)
28+
29+
# If no manual directory is provided, try to fetch it from ESP-IDF
2630
else()
27-
target_include_directories(usermod_mp_camera INTERFACE
28-
${CMAKE_CURRENT_LIST_DIR})
29-
endif()
31+
idf_component_get_property(CAMERA_INCLUDES esp32-camera INCLUDE_DIRS)
32+
idf_component_get_property(CAMERA_PRIV_INCLUDES esp32-camera PRIV_INCLUDE_DIRS)
33+
idf_component_get_property(CAMERA_DIR esp32-camera COMPONENT_DIR)
3034

31-
# Add the include directories to the target
32-
target_include_directories(usermod_mp_camera INTERFACE ${MOD_INCLUDES})
35+
if(CAMERA_DIR)
36+
message(STATUS "Using ESP32 Camera component from ESP-IDF: ${CAMERA_DIR}")
3337

34-
# Add compile definitions if MICROPY_CAMERA_MODEL is defined
38+
# Add public include directories from ESP-IDF
39+
if(CAMERA_INCLUDES)
40+
list(TRANSFORM CAMERA_INCLUDES PREPEND ${CAMERA_DIR}/)
41+
target_include_directories(usermod_mp_camera INTERFACE ${CAMERA_INCLUDES})
42+
endif()
43+
44+
# Add private include directories from ESP-IDF
45+
if(CAMERA_PRIV_INCLUDES)
46+
list(TRANSFORM CAMERA_PRIV_INCLUDES PREPEND ${CAMERA_DIR}/)
47+
target_include_directories(usermod_mp_camera INTERFACE ${CAMERA_PRIV_INCLUDES})
48+
endif()
49+
else()
50+
message(WARNING "ESP32 Camera component not found in ESP-IDF!")
51+
target_include_directories(usermod_mp_camera PUBLIC ${CMAKE_CURRENT_LIST_DIR})
52+
endif()
53+
endif()
54+
55+
# Define MICROPY_CAMERA_MODEL if specified
3556
if (MICROPY_CAMERA_MODEL)
36-
target_compile_definitions(usermod_mp_camera INTERFACE MICROPY_CAMERA_MODEL_${MICROPY_CAMERA_MODEL}=1)
57+
target_compile_definitions(usermod_mp_camera INTERFACE
58+
MICROPY_CAMERA_MODEL_${MICROPY_CAMERA_MODEL}=1
59+
)
3760
endif()
3861

39-
# Add compile definitions if MP_CAMERA_DRIVER_VERSION is defined
62+
# Define MP_CAMERA_DRIVER_VERSION if specified
4063
if (MP_CAMERA_DRIVER_VERSION)
41-
target_compile_definitions(usermod_mp_camera INTERFACE MP_CAMERA_DRIVER_VERSION=\"${MP_CAMERA_DRIVER_VERSION}\")
64+
target_compile_definitions(usermod_mp_camera INTERFACE
65+
MP_CAMERA_DRIVER_VERSION=\"${MP_CAMERA_DRIVER_VERSION}\"
66+
)
4267
endif()
4368

44-
# Link the usermod_mp_camera library to the main usermod target
69+
# Link the camera module with the main usermod target
4570
target_link_libraries(usermod INTERFACE usermod_mp_camera)
4671

72+
# Gather target properties for MicroPython build system
4773
micropy_gather_target_properties(usermod_mp_camera)

0 commit comments

Comments
 (0)