circuitpython/ports/esp32/CMakeLists.txt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
2.0 KiB
CMake
Raw Normal View History

# Top-level cmake file for building MicroPython on ESP32.
cmake_minimum_required(VERSION 3.12)
# Set the board if it's not already set.
if(NOT MICROPY_BOARD)
set(MICROPY_BOARD ESP32_GENERIC)
endif()
# Set the board directory and check that it exists.
if(NOT MICROPY_BOARD_DIR)
esp32/CMake: Change PROJECT_DIR to CMAKE_CURRENT_LIST_DIR. This migrates the CMake variable `MICROPY_PORT_DIR` from the ESP-IDF defined project to the component. Previously used instances of the variable within the project definition have been migrated to `CMAKE_CURRENT_LIST_DIR`. Within the component (the `main` subdirectory in the ESP32 port) we define `MICROPY_PORT_DIR` using `CMAKE_CURRENT_LIST_DIR` and subsequently use the `MICROPY_PORT_DIR` value in all locations where `PROJECT` had previously been used. Context: In commit 9b90882146, initial support was added for building with the newly introduced CMake support provided by the ESP-IDF. Specifically, the commit message states: > This commit adds support for building the esp32 port with CMake, and in particular, it builds MicroPython as a component within the ESP-IDF. Using CMake and the ESP-IDF build infrastructure makes it much easier to maintain the port, especially with the various new ESP32 MCUs and their required toolchains. `PROJECT_DIR` is a variable populated by the ESP-IDF specifically and is not stable when used with "[Pure CMake components][1]" as documented in the ESP-IDF. It is intended to be used in the scope of the parent of the current file (the "project") as opposed to the current file ("the component"). Crossing into the parent scope like this works solely when the "project" is MicroPython, but not when used as a component by other ESP-IDF projects. Analyzing this file, the intention is to reference the "Project" which in the example is the parent directory. Within the [CMake variables][2] documentation, there is one specifically defined for referencing the directory for the CMake listfile currently being processed: [`CMAKE_CURRENT_LIST_DIR`][3]. After making the change from `PROJECT_DIR` to `CMAKE_CURRENT_LIST_DIR`, the reach into the parent scope defined by the ESP-IDF and the resulting CMake interface violation is removed. Similar to the component definition, the project `CMakeLists.txt` uses the variable `CMAKE_SOURCE_DIR` which CMake defines as "The path to the top level of the source tree." This commit changes the variable to `CMAKE_CURRENT_LIST_DIR` for the reasons cited above. [1]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/build-system.html#writing-pure-cmake-components [2]: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html [3]: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html Signed-off-by: Brian 'redbeard' Harrington <redbeard@dead-city.org>
2023-06-12 16:02:10 -04:00
set(MICROPY_BOARD_DIR ${CMAKE_CURRENT_LIST_DIR}/boards/${MICROPY_BOARD})
endif()
if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
endif()
# Define the output sdkconfig so it goes in the build directory.
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
# Save the manifest file set from the cmake command line.
set(MICROPY_USER_FROZEN_MANIFEST ${MICROPY_FROZEN_MANIFEST})
# Include board config; this is expected to set (among other options):
# - SDKCONFIG_DEFAULTS
# - IDF_TARGET
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
# Set the frozen manifest file. Note if MICROPY_FROZEN_MANIFEST is set from the cmake
# command line, then it will override the default and any manifest set by the board.
if (MICROPY_USER_FROZEN_MANIFEST)
set(MICROPY_FROZEN_MANIFEST ${MICROPY_USER_FROZEN_MANIFEST})
elseif (NOT MICROPY_FROZEN_MANIFEST)
esp32/CMake: Change PROJECT_DIR to CMAKE_CURRENT_LIST_DIR. This migrates the CMake variable `MICROPY_PORT_DIR` from the ESP-IDF defined project to the component. Previously used instances of the variable within the project definition have been migrated to `CMAKE_CURRENT_LIST_DIR`. Within the component (the `main` subdirectory in the ESP32 port) we define `MICROPY_PORT_DIR` using `CMAKE_CURRENT_LIST_DIR` and subsequently use the `MICROPY_PORT_DIR` value in all locations where `PROJECT` had previously been used. Context: In commit 9b90882146, initial support was added for building with the newly introduced CMake support provided by the ESP-IDF. Specifically, the commit message states: > This commit adds support for building the esp32 port with CMake, and in particular, it builds MicroPython as a component within the ESP-IDF. Using CMake and the ESP-IDF build infrastructure makes it much easier to maintain the port, especially with the various new ESP32 MCUs and their required toolchains. `PROJECT_DIR` is a variable populated by the ESP-IDF specifically and is not stable when used with "[Pure CMake components][1]" as documented in the ESP-IDF. It is intended to be used in the scope of the parent of the current file (the "project") as opposed to the current file ("the component"). Crossing into the parent scope like this works solely when the "project" is MicroPython, but not when used as a component by other ESP-IDF projects. Analyzing this file, the intention is to reference the "Project" which in the example is the parent directory. Within the [CMake variables][2] documentation, there is one specifically defined for referencing the directory for the CMake listfile currently being processed: [`CMAKE_CURRENT_LIST_DIR`][3]. After making the change from `PROJECT_DIR` to `CMAKE_CURRENT_LIST_DIR`, the reach into the parent scope defined by the ESP-IDF and the resulting CMake interface violation is removed. Similar to the component definition, the project `CMakeLists.txt` uses the variable `CMAKE_SOURCE_DIR` which CMake defines as "The path to the top level of the source tree." This commit changes the variable to `CMAKE_CURRENT_LIST_DIR` for the reasons cited above. [1]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/build-system.html#writing-pure-cmake-components [2]: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html [3]: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html Signed-off-by: Brian 'redbeard' Harrington <redbeard@dead-city.org>
2023-06-12 16:02:10 -04:00
set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/boards/manifest.py)
endif()
# Concatenate all sdkconfig files into a combined one for the IDF to use.
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
file(READ ${SDKCONFIG_DEFAULT} CONTENTS)
file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}")
endforeach()
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)
# Include main IDF cmake file.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# Set the location of the main component for the project (one per target).
list(APPEND EXTRA_COMPONENT_DIRS main_${IDF_TARGET})
# Define the project.
project(micropython)