espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.28k stars 7.2k forks source link

CMake: Possibility to specify location of mconf-idf when using IDF as library (IDFGH-1399) #3677

Open PerMalmberg opened 5 years ago

PerMalmberg commented 5 years ago

@renzbagaporo Some futher feedback on the CMake build system when using it together with an interface library between the main app and IDF.

ESP-IDF: v4.0-dev-1136-g28f1cdf5e gcc 8, rc1

Project structure:

As the top-level projects needs to set its own settings, I need to pass the correct sdkconfig file down to the build system of IDF via the interface library, which I do like this;

Top CMakeLists.txt:

set(project_specific_sdkconfig ${CMAKE_CURRENT_LIST_DIR}/sdkconfig)
add_subdirectory(externals/smooth/lib/smooth)
add_subdirectory(main)

Excerpt from interface library CMakeLists.txt, via idf_utils.cmake

# When a project specifies a specific sdkconfig, use it
if("${project_specific_sdkconfig}" EQUAL "")
    set(smooth_sdkconfig ${CMAKE_CURRENT_LIST_DIR}/sdkconfig)
else()
    set(smooth_sdkconfig ${project_specific_sdkconfig})
endif()

idf_build_process(esp32
    COMPONENTS ${smooth_req_comps} smooth_idf_component
    SDKCONFIG ${smooth_sdkconfig}
    BUILD_DIR ${CMAKE_BINARY_DIR})

This gets me so far that running cmake .. -G Ninja -DESP_PLATFORM=1 -DCMAKE_TOOLCHAIN_FILE=$IDF_PATH/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32 && ninja builds IDF, interfrace library and the main app using the correct sdkconfig. So far so good.

The problem is that when running ninja menuconfig, it emits the following error (full output here):

No such file or directory

Dissecting the output of the command being run shows that the missing file it is /home/permal/electronics/IO-Card-G3/software/build/kconfig_bin/mconf-idf.

Not entirely unexpected, mconf-idf is placed here: /home/permal/electronics/IO-Card-G3/software/build/externals/smooth/lib/smooth/kconfig_bin/mconf-idf, i.e. within ${CMAKE_BINARY_DIR}/kconfig_bin of IDF, as specified in kconfig.cmake.

I thought that by specifying BUILD_DIR ${CMAKE_BINARY_DIR} in the call to idf_build_process, all IDF build artifacts would use that, but alas that is not the case.

Apart from the issue generating project_desctiption.json, this seems to be the last item that is preventing a pleasant user experience when using IDF as a library. Yes, the file can be modified by had, but its structure is rather unsuited for that and you loose all the help you get from the tool itself in terms of range limits etc.

As such, would it be possible to change the idf build system so that it uses the BUILD_DIR specified in the call to idf_build_process also when building mconf-idf? I think this would make even idf.py function properly.

PerMalmberg commented 5 years ago

@renzbagaporo If you get a moment to spare, I'd really appreciate some feedback on the above idea as not being able to run menuconfig without manually editing the command line each time is a real pain.

PerMalmberg commented 5 years ago

@renzbagaporo Are you still working on changes to the CMake build system? This is still relevant.

renzbagaporo commented 5 years ago

I thought that by specifying BUILD_DIR ${CMAKE_BINARY_DIR} in the call to idf_build_process, all IDF build artifacts would use that, but alas that is not the case.

Yes, ESP-IDF has some artifacts placed in the build directory. In the case of mconf-idf, its because the targets for those are created before BUILD_DIR gets set via argument to idf_build_process.

This is certainly a bug however, and can be solved by changing https://github.com/espressif/esp-idf/blob/master/tools/cmake/kconfig.cmake#L50 to

            BINARY_DIR "${CMAKE_BINARY_DIR}/kconfig_bin"

Is this how you workaround this problem?

PerMalmberg commented 5 years ago

Is this how you workaround this problem?

No, I edited the command line.

Good see that it's another bug found, I assume it'll be in master sometime soon.