diff --git a/tools/cmakev2/project.cmake b/tools/cmakev2/project.cmake index 4e0a6352310..5e12167da53 100644 --- a/tools/cmakev2/project.cmake +++ b/tools/cmakev2/project.cmake @@ -592,3 +592,22 @@ function(__generate_project_info) configure_file("${IDF_PATH}/tools/cmake/project_description.json.in" "${BUILD_DIR}/project_description.json") endfunction() + +#[[api +.. cmakev2:macro:: idf_project_default + + .. code-block:: cmake + + idf_project_default() + + Create a default project executable based on the main component and its + transitive dependencies. The executable name is derived from the + PROJECT_NAME variable, which by default uses the CMAKE_PROJECT_NAME value + specified in the CMake's project() call. +#]] +macro(idf_project_default) + idf_project_init() + idf_build_get_property(project_name PROJECT_NAME) + idf_build_executable("${project_name}" COMPONENTS main SUFFIX ".elf") + unset(project_name) +endmacro() diff --git a/tools/cmakev2/test/CMakeLists.txt b/tools/cmakev2/test/CMakeLists.txt index 3cbd4db04da..3c3fda97235 100644 --- a/tools/cmakev2/test/CMakeLists.txt +++ b/tools/cmakev2/test/CMakeLists.txt @@ -222,6 +222,9 @@ test_project_properties() test_include_component() test_executable() +# Create default project +idf_project_default() + # Call this test last because it replaces the ESP system component. test_component_priority() diff --git a/tools/cmakev2/test/components/main/CMakeLists.txt b/tools/cmakev2/test/components/main/CMakeLists.txt new file mode 100644 index 00000000000..28ab405bd66 --- /dev/null +++ b/tools/cmakev2/test/components/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "hello_world_main.c" + PRIV_REQUIRES spi_flash + INCLUDE_DIRS "") diff --git a/tools/cmakev2/test/components/main/hello_world_main.c b/tools/cmakev2/test/components/main/hello_world_main.c new file mode 100644 index 00000000000..95cab254a1a --- /dev/null +++ b/tools/cmakev2/test/components/main/hello_world_main.c @@ -0,0 +1,51 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_chip_info.h" +#include "esp_flash.h" +#include "esp_system.h" + +void app_main(void) +{ + printf("Hello world!\n"); + + /* Print chip information */ + esp_chip_info_t chip_info; + uint32_t flash_size; + esp_chip_info(&chip_info); + printf("This is %s chip with %d CPU core(s), %s%s%s%s, ", + CONFIG_IDF_TARGET, + chip_info.cores, + (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "", + (chip_info.features & CHIP_FEATURE_BT) ? "BT" : "", + (chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "", + (chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : ""); + + unsigned major_rev = chip_info.revision / 100; + unsigned minor_rev = chip_info.revision % 100; + printf("silicon revision v%d.%d, ", major_rev, minor_rev); + if (esp_flash_get_size(NULL, &flash_size) != ESP_OK) { + printf("Get flash size failed"); + return; + } + + printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024), + (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); + + printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size()); + + for (int i = 10; i >= 0; i--) { + printf("Restarting in %d seconds...\n", i); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } + printf("Restarting now.\n"); + fflush(stdout); + esp_restart(); +}