Merge branch 'bugfix/fix_idf_as_lib_build' into 'master'

Build: fix idf_as_lib example not building

Closes IDFGH-6453

See merge request espressif/esp-idf!16514
This commit is contained in:
Zim Kalinowski
2022-01-06 03:17:30 +00:00
24 changed files with 144 additions and 34 deletions

View File

@@ -2,21 +2,24 @@ cmake_minimum_required(VERSION 3.5)
project(idf_as_lib C)
if("${TARGET}" STREQUAL "esp32")
set(targets "esp32" "esp32s2" "esp32s3" "esp32c3" "esp32h2" "esp8684")
if("${TARGET}" IN_LIST targets)
# Include for ESP-IDF build system functions
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
# Create idf::esp32 and idf::freertos static libraries
idf_build_process(esp32
# Create idf::{target} and idf::freertos static libraries
idf_build_process("${TARGET}"
# try and trim the build; additional components
# will be included as needed based on dependency tree
#
# although esptool_py does not generate static library,
# processing the component is needed for flashing related
# targets and file generation
COMPONENTS esp32 freertos esptool_py
COMPONENTS "${TARGET}" freertos esptool_py
SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
BUILD_DIR ${CMAKE_BINARY_DIR})
else()
message(WARNING "Unknown target ${TARGET}, creating stubs for esp32 instead")
# Create stubs for esp32 and freertos, stub::esp32 and stub::freertos
add_subdirectory(stubs/esp32)
add_subdirectory(stubs/freertos)
@@ -29,8 +32,8 @@ set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} main.c)
# Link the static libraries to the executable
if("${TARGET}" STREQUAL "esp32")
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash)
if("${TARGET}" IN_LIST targets)
target_link_libraries(${elf_file} "idf::${TARGET}" idf::freertos idf::spi_flash)
# Attach additional targets to the executable file for flashing,
# linker script generation, partition_table generation, etc.
idf_build_executable(${elf_file})

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env bash
rm -rf build && mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32 -GNinja
cmake --build .

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -0,0 +1 @@
build.sh

View File

@@ -1,4 +1,14 @@
#!/usr/bin/env bash
# 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 ..
cmake .. $PARAM
cmake --build .

View File

@@ -0,0 +1 @@
run-esp32.sh

View File

@@ -0,0 +1 @@
run-esp32.sh

View File

@@ -0,0 +1 @@
run-esp32.sh

View File

@@ -0,0 +1 @@
run-esp32.sh

View File

@@ -0,0 +1 @@
run-esp32.sh

View File

@@ -0,0 +1 @@
run-esp32.sh