Explorar o código

Merge branch 'bugfix/cmake_example_sdkconfig_path_v4.2' into 'release/v4.2'

cmake/example: Move idf_as_lib sdkconfig path to project, document configuring project (v4.2)

See merge request espressif/esp-idf!10859
Angus Gratton %!s(int64=5) %!d(string=hai) anos
pai
achega
ceb11fd543

+ 1 - 1
examples/build_system/cmake/idf_as_lib/CMakeLists.txt

@@ -14,7 +14,7 @@ if("${TARGET}" STREQUAL "esp32")
                     # processing the component is needed for flashing related
                     # targets and file generation
                     COMPONENTS esp32 freertos esptool_py
-                    SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig
+                    SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
                     BUILD_DIR ${CMAKE_BINARY_DIR})
 else()
     # Create stubs for esp32 and freertos, stub::esp32 and stub::freertos

+ 20 - 0
examples/build_system/cmake/idf_as_lib/README.md

@@ -44,6 +44,8 @@ or run [build.sh](./build.sh) to build for the host:
 ./build-esp32.sh
 ```
 
+Note: To build for a different target SoC, copy the `build-esp32.sh` file and change the `-DTARGET=esp32` clause on the second line.
+
 or
 
 ```bash
@@ -68,6 +70,24 @@ or
 ./run.sh
 ```
 
+## Configuring this Example
+
+To modify the example ESP-IDF project configuration, first create the CMake build directory. This can be done by running `build-esp32.sh` or by running only the first two lines in `build-esp32.sh` (which won't build the actual project yet).
+
+Then execute the menuconfig build target in the build directory:
+
+```bash
+cmake --build build -- menuconfig
+```
+
+If using ninja directly:
+
+```bash
+ninja -C build menuconfig
+```
+
+Note: ESP-IDF project configuration isn't used by the host CMake builds, the config is only read when the project is built using the ESP-IDF build system.
+
 ---
 
 There is a discussion on using ESP-IDF in custom CMake projects in the programming guide under `API Guides` -> `Build System` -> `Using ESP-IDF in Custom CMake Projects`

+ 13 - 12
tools/ci/test_build_system_cmake.sh

@@ -455,35 +455,36 @@ function run_tests()
 
     print_status "Building a project with CMake library imported and PSRAM workaround, all files compile with workaround"
     # Test for libraries compiled within ESP-IDF
-    rm -rf build
+    rm -r build sdkconfig
     echo "CONFIG_ESP32_SPIRAM_SUPPORT=y" >> sdkconfig.defaults
     echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> sdkconfig.defaults
     # note: we do 'reconfigure' here, as we just need to run cmake
     idf.py -C $IDF_PATH/examples/build_system/cmake/import_lib -B `pwd`/build -D SDKCONFIG_DEFAULTS="`pwd`/sdkconfig.defaults" reconfigure
     grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it"
     (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround"
-    rm -r sdkconfig.defaults build
-    # Test for external libraries in custom CMake projects with ESP-IDF components linked
-    mkdir build && touch build/sdkconfig
-    echo "CONFIG_ESP32_SPIRAM_SUPPORT=y" >> build/sdkconfig
-    echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> build/sdkconfig
+    rm -r build sdkconfig sdkconfig.defaults
+
+    print_status "Test for external libraries in custom CMake projects with ESP-IDF components linked"
+    mkdir build
+    IDF_AS_LIB=$IDF_PATH/examples/build_system/cmake/idf_as_lib
+    echo "CONFIG_ESP32_SPIRAM_SUPPORT=y" > $IDF_AS_LIB/sdkconfig
+    echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> $IDF_AS_LIB/sdkconfig
     # note: we just need to run cmake
-    (cd build && cmake $IDF_PATH/examples/build_system/cmake/idf_as_lib -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32)
+    (cd build && cmake $IDF_AS_LIB -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32)
     grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it"
     (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround"
-    rm -r build
-    #Test for various strategies
+
     for strat in MEMW NOPS DUPLDST; do
-        rm -r build sdkconfig.defaults sdkconfig sdkconfig.defaults.esp32
+        print_status "Test for external libraries in custom CMake projects with PSRAM strategy $strat"
+        rm -r build sdkconfig sdkconfig.defaults sdkconfig.defaults.esp32
         stratlc=`echo $strat | tr A-Z a-z`
-        mkdir build && touch build/sdkconfig
         echo "CONFIG_ESP32_SPIRAM_SUPPORT=y" > sdkconfig.defaults
         echo "CONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_$strat=y"  >> sdkconfig.defaults
         echo "CONFIG_SPIRAM_CACHE_WORKAROUND=y" >> sdkconfig.defaults
         # note: we do 'reconfigure' here, as we just need to run cmake
         idf.py reconfigure
         grep -q '"command"' build/compile_commands.json || failure "compile_commands.json missing or has no no 'commands' in it"
-        (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-strategy=$stratlc) && failure "All commands in compile_commands.json should use PSRAM cache workaround strategy $strat when selected"
+        (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-strategy=$stratlc) && failure "All commands in compile_commands.json should use PSRAM cache workaround strategy"
         echo ${PWD}
         rm -r sdkconfig.defaults build
     done

+ 2 - 0
tools/cmake/kconfig.cmake

@@ -191,6 +191,8 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
     set(config_dir ${build_dir}/config)
     file(MAKE_DIRECTORY "${config_dir}")
 
+    message(STATUS "Project sdkconfig file ${sdkconfig}")
+
     # Generate the config outputs
     set(sdkconfig_cmake ${config_dir}/sdkconfig.cmake)
     set(sdkconfig_header ${config_dir}/sdkconfig.h)