ARMmbed/mbed-tools

Drive mbed config processing from CMake

rwalton-arm opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
We have a number of issues due to our coupling between mbed-tools configuration processing and the CMake build system. Driving the config processing from CMake would mean mbed-tools wouldn't have to concern itself with such implementation details as "build directory" or "mbed-os-path", which are already known by our CMake build system. This approach also makes it easier for users to only run CMake commands to build mbed-os, as it removes the need for the user to run an mbed-tools configure before running CMake.

Describe the solution you'd like
Split the config processing module into a separate Python package. Run the config tool from mbed-os CMake where source & build tree locations are available and always correct.

Describe alternatives you've considered
Move all config processing to raw CMake without using any python tools, or use an off the shelf config system such as KConfig.

I have a trick that may help - Early in the top-level CMakeLists file, I execute mbed-tools configure, if there is no config in the default path (i.e. if you don't call mbed-tools yourself)
For example:

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")

# ...

if (NOT EXISTS ${MBED_CONFIG_PATH}/mbed_config.cmake)
    # Set default target here:
    set(DEFAULT_MBED_TARGET "NUCLEO_H743ZI2" CACHE INTERNAL "")

    message("Target: ${DEFAULT_MBED_TARGET}")

    # Custom config path for each target so it
    # doesn't conflict with the default path or with other targets.
    set (MBED_CONFIG_PATH "${CMAKE_CURRENT_BINARY_DIR}/mbed-config-${DEFAULT_MBED_TARGET}" CACHE INTERNAL "")

    execute_process(
        COMMAND mbed-tools configure -m ${DEFAULT_MBED_TARGET} -t GCC_ARM -o ${MBED_CONFIG_PATH}
    )
endif()

# ...

include(${MBED_PATH}/tools/cmake/app.cmake)

It's not perfect, but this will allow you to invoke cmake directly, and it will handle the invocation of mbed-tools before loading the rest of the project.

This works with the auto-configuration in the VSCode CMake plugin, and I think my coworker has it working with CLion too.