diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh b/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh deleted file mode 100644 index 9a18dc76db..0000000000 --- a/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -PARAM="" - -# Retrive the target from the current filename, if no target specified, -# the variable will be empty -TARGET=$(echo $0 | cut -s -f2 -d- | cut -s -f1 -d.) -if [[ -n $TARGET ]] -then - # Target is not null, specify the build parameters - PARAM="-DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-${TARGET}.cmake -DTARGET=${TARGET} -GNinja" -fi - -rm -rf build && mkdir build && cd build -cmake .. $PARAM -cmake --build . diff --git a/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh b/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh new file mode 120000 index 0000000000..c07a74de4f --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/build-esp32p4.sh @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh b/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh deleted file mode 100644 index 3d9e0bfba5..0000000000 --- a/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -cd build -python $IDF_PATH/components/esptool_py/esptool/esptool.py -p $1 write_flash @flash_project_args -python -m esp_idf_monitor -p $1 idf_as_lib.elf diff --git a/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh b/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh new file mode 120000 index 0000000000..cde8585ed4 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/run-esp32p4.sh @@ -0,0 +1 @@ +run-esp32.sh \ No newline at end of file diff --git a/examples/build_system/cmake/idf_as_lib/stubs/esp32/CMakeLists.txt b/examples/build_system/cmake/idf_as_lib/stubs/esp32/CMakeLists.txt index df694d2662..ca45436572 100644 --- a/examples/build_system/cmake/idf_as_lib/stubs/esp32/CMakeLists.txt +++ b/examples/build_system/cmake/idf_as_lib/stubs/esp32/CMakeLists.txt @@ -1,5 +1,3 @@ -add_library(stub_esp32 STATIC system_api.c flash_ops.c cpu_start.c) +add_library(stub_esp32 STATIC system_api.c cpu_start.c) target_include_directories(stub_esp32 PUBLIC .) add_library(stub::esp32 ALIAS stub_esp32) - -target_link_libraries(stub_esp32 stub::spi_flash) diff --git a/examples/build_system/cmake/idf_as_lib/stubs/esp32/esp_system.h b/examples/build_system/cmake/idf_as_lib/stubs/esp32/esp_system.h index a3d2143c55..4a8e3af859 100644 --- a/examples/build_system/cmake/idf_as_lib/stubs/esp32/esp_system.h +++ b/examples/build_system/cmake/idf_as_lib/stubs/esp32/esp_system.h @@ -9,6 +9,10 @@ extern "C" { #endif +#define ESP_OK 0 /*!< esp_err_t value indicating success (no error) */ + +typedef int esp_err_t; + void esp_restart(void); #ifdef __cplusplus diff --git a/examples/build_system/cmake/idf_as_lib/stubs/esp32/flash_ops.c b/examples/build_system/cmake/idf_as_lib/stubs/esp32/flash_ops.c deleted file mode 100644 index e44eb03361..0000000000 --- a/examples/build_system/cmake/idf_as_lib/stubs/esp32/flash_ops.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - -int spi_flash_get_chip_size(void) -{ - return (1024 * 1024 * 1024); -} diff --git a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/CMakeLists.txt b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/CMakeLists.txt index c44bb82f1a..60550ed7c1 100644 --- a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/CMakeLists.txt +++ b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/CMakeLists.txt @@ -1,3 +1,4 @@ -add_library(stub_spi_flash INTERFACE) -target_include_directories(stub_spi_flash INTERFACE .) +add_library(stub_spi_flash STATIC flash_ops.c) +target_include_directories(stub_spi_flash PUBLIC .) add_library(stub::spi_flash ALIAS stub_spi_flash) +target_link_libraries(stub_spi_flash PUBLIC stub_esp32) diff --git a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_flash.h b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_flash.h new file mode 100644 index 0000000000..aa8584c4b3 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_flash.h @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#pragma once + +#include +#include "esp_system.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void * esp_flash_t; + +esp_err_t esp_flash_get_size(esp_flash_t *chip, uint32_t *out_size); + +#ifdef __cplusplus +} +#endif diff --git a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_spi_flash.h b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_spi_flash.h deleted file mode 100644 index ede1cb373e..0000000000 --- a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/esp_spi_flash.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int spi_flash_get_chip_size(void); - -#ifdef __cplusplus -} -#endif diff --git a/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/flash_ops.c b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/flash_ops.c new file mode 100644 index 0000000000..faf0aec0c2 --- /dev/null +++ b/examples/build_system/cmake/idf_as_lib/stubs/spi_flash/flash_ops.c @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include "esp_flash.h" + +esp_err_t esp_flash_get_size(esp_flash_t *chip, uint32_t *out_size) +{ + *out_size = 1024 * 1024 * 1024; + return ESP_OK; +} diff --git a/tools/test_build_system/test_cmake.py b/tools/test_build_system/test_cmake.py index 51be08ecb2..e43f090a77 100644 --- a/tools/test_build_system/test_cmake.py +++ b/tools/test_build_system/test_cmake.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import logging import os @@ -16,14 +16,17 @@ from test_build_system_helpers import run_cmake_and_build def test_build_custom_cmake_project(test_app_copy: Path) -> None: # Test is compatible with any target. Random targets in the list are selected for performance reasons - for target in ['esp32', 'esp32s3', 'esp32c6', 'esp32h2']: + idf_path = Path(os.environ['IDF_PATH']) + for target in ['esp32','esp32c2','esp32c3','esp32c6','esp32h2','esp32p4','esp32s2','esp32s3']: logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for {target}') - idf_path = Path(os.environ['IDF_PATH']) run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), '-G', 'Ninja', '-DCMAKE_TOOLCHAIN_FILE={}'.format(idf_path / 'tools' / 'cmake' / f'toolchain-{target}.cmake'), f'-DTARGET={target}') assert file_contains((test_app_copy / 'build' / 'compile_commands.json'), '"command"') shutil.rmtree(test_app_copy / 'build') + logging.info(f'Test build ESP-IDF as a library to a custom CMake projects for host') + run_cmake_and_build(str(idf_path / 'examples' / 'build_system' / 'cmake' / 'idf_as_lib'), '-G', 'Ninja') + def test_build_cmake_library_psram_workaround(test_app_copy: Path) -> None: logging.info('Building a project with CMake library imported and PSRAM workaround, all files compile with workaround')