|
| 1 | +include(${MICROPY_DIR}/py/py.cmake) |
| 2 | + |
| 3 | +set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/manifest.py) |
| 4 | + |
| 5 | +add_library(usermod_mp_camera INTERFACE) |
| 6 | + |
| 7 | +target_sources(usermod_mp_camera INTERFACE |
| 8 | + ${CMAKE_CURRENT_LIST_DIR}/src/modcamera.c |
| 9 | + ${CMAKE_CURRENT_LIST_DIR}/src/modcamera_api.c |
| 10 | +) |
| 11 | + |
| 12 | +# Register dependency on esp32-camera component |
| 13 | +# The component is managed by IDF component manager via idf_component.yml |
| 14 | +# Add include directories directly from managed_components (they exist after Component Manager ran) |
| 15 | +# Allow manual override via ESP32_CAMERA_DIR |
| 16 | +if(DEFINED ESP32_CAMERA_DIR AND EXISTS "${ESP32_CAMERA_DIR}") |
| 17 | + message(STATUS "Using user-defined ESP32_CAMERA_DIR: ${ESP32_CAMERA_DIR}") |
| 18 | + set(ESP32_CAMERA_MANAGED_DIR "${ESP32_CAMERA_DIR}") |
| 19 | +else() |
| 20 | + set(ESP32_CAMERA_MANAGED_DIR "${MICROPY_PORT_DIR}/managed_components/espressif__esp32-camera") |
| 21 | +endif() |
| 22 | + |
| 23 | +if(EXISTS "${ESP32_CAMERA_MANAGED_DIR}") |
| 24 | + # Add standard include directories for esp32-camera |
| 25 | + list(APPEND MICROPY_INC_USERMOD |
| 26 | + ${ESP32_CAMERA_MANAGED_DIR}/driver/include |
| 27 | + ${ESP32_CAMERA_MANAGED_DIR}/driver/private_include |
| 28 | + ${ESP32_CAMERA_MANAGED_DIR}/conversions/include |
| 29 | + ${ESP32_CAMERA_MANAGED_DIR}/conversions/private_include |
| 30 | + ${ESP32_CAMERA_MANAGED_DIR}/sensors/private_include |
| 31 | + ) |
| 32 | + |
| 33 | + message(STATUS "Found esp32-camera at: ${ESP32_CAMERA_MANAGED_DIR}") |
| 34 | + |
| 35 | + # Link against the component library when target exists (during actual build) |
| 36 | + # The target doesn't exist yet during include(), but will exist during build |
| 37 | + if(TARGET espressif__esp32-camera) |
| 38 | + idf_component_get_property(esp32_camera_lib espressif__esp32-camera COMPONENT_LIB) |
| 39 | + target_link_libraries(usermod_mp_camera INTERFACE ${esp32_camera_lib}) |
| 40 | + endif() |
| 41 | + |
| 42 | + # Set MP_CAMERA_DRIVER_VERSION if available |
| 43 | + if(EXISTS "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml") |
| 44 | + file(READ "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml" _camera_component_yml) |
| 45 | + string(REGEX MATCH "version: ([0-9]+\\.[0-9]+(\\.[0-9]+)?)" _ ${_camera_component_yml}) |
| 46 | + if(CMAKE_MATCH_1) |
| 47 | + set(MP_CAMERA_DRIVER_VERSION "${CMAKE_MATCH_1}") |
| 48 | + message(STATUS "Found esp32-camera version: ${MP_CAMERA_DRIVER_VERSION}") |
| 49 | + endif() |
| 50 | + endif() |
| 51 | +else() |
| 52 | + message(WARNING "esp32-camera component not found - component manager should have downloaded it based on idf_component.yml") |
| 53 | +endif() |
| 54 | + |
| 55 | +# Check if MP_JPEG_DIR is set or if mp_jpeg directory exists two levels up |
| 56 | +if(DEFINED MP_JPEG_DIR AND EXISTS "${MP_JPEG_DIR}") |
| 57 | + message(STATUS "Using user-defined MP_JPEG_DIR: ${MP_JPEG_DIR}") |
| 58 | + set(MP_JPEG_SRC "${MP_JPEG_DIR}/micropython.cmake") |
| 59 | +elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../mp_jpeg") |
| 60 | + message(STATUS "Found mp_jpeg directory at same level as the camera module") |
| 61 | + set(MP_JPEG_SRC "${CMAKE_CURRENT_LIST_DIR}/../mp_jpeg/micropython.cmake") |
| 62 | +endif() |
| 63 | + |
| 64 | +# Include mp_jpeg module if found |
| 65 | +if(DEFINED MP_JPEG_SRC AND EXISTS "${MP_JPEG_SRC}") |
| 66 | + include(${MP_JPEG_SRC}) |
| 67 | + message(STATUS "Included mp_jpeg module from: ${MP_JPEG_SRC}") |
| 68 | +else() |
| 69 | + message(STATUS "mp_jpeg module not found - camera module will build without JPEG support") |
| 70 | +endif() |
| 71 | + |
| 72 | +# Define MICROPY_CAMERA_MODEL if specified |
| 73 | +if (MICROPY_CAMERA_MODEL) |
| 74 | + message(STATUS "Using user-defined camera model: ${MICROPY_CAMERA_MODEL}") |
| 75 | + target_compile_definitions(usermod_mp_camera INTERFACE |
| 76 | + MICROPY_CAMERA_MODEL_${MICROPY_CAMERA_MODEL}=1 |
| 77 | + ) |
| 78 | +endif() |
| 79 | + |
| 80 | +# Define MP_CAMERA_DRIVER_VERSION if specified |
| 81 | +if (MP_CAMERA_DRIVER_VERSION) |
| 82 | + target_compile_definitions(usermod_mp_camera INTERFACE |
| 83 | + MP_CAMERA_DRIVER_VERSION=\"${MP_CAMERA_DRIVER_VERSION}\" |
| 84 | + ) |
| 85 | +endif() |
| 86 | + |
| 87 | +# Camera module strings are not suitable for compression and cause size increase |
| 88 | +target_compile_definitions(usermod_mp_camera INTERFACE |
| 89 | + MICROPY_ROM_TEXT_COMPRESSION=0 |
| 90 | +) |
| 91 | + |
| 92 | +# Link the camera module with the main usermod target |
| 93 | +target_link_libraries(usermod INTERFACE usermod_mp_camera) |
| 94 | + |
| 95 | +# Gather target properties for MicroPython build system |
| 96 | +micropy_gather_target_properties(usermod_mp_camera) |
0 commit comments