Skip to main content
Graduate II
November 18, 2025
Solved

changing toolchain by running project setup again fails

  • November 18, 2025
  • 3 replies
  • 263 views

I want to change the selected toolchain for a project by clicking on "Setup STM32Cube project(s)" and selecting the desired toolchain and clicking save.
I want to change from clang to gcc to test a few things.
It keeps using the old toolchain (clang). Even if I delete the build folder.
If I delete CMakePresets.json I get an error that the project requires a preset.
If I modify CMakePresets.json I get the following warning message when building:

[cmake] Manually-specified variables were not used by the project:
[cmake]
[cmake] CMAKE_TOOLCHAIN_FILE
[cmake]

In STM32CubeMX the toolchain option is greyed out.

What's the proper way to change the tool chain?

    This topic has been closed for replies.
    Best answer by unsigned_char_array

    In CMakePresets.json I changed:

     

    "toolchainFile": "${sourceDir}/cmake/starm-clang.cmake",

    to

    "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",

     I deleted the build folder. Then I restarted VS Code.

    This fixed most of the configuration. Build started with GCC, but touchgfx still was pointing to 
    Middlewares/ST/touchgfx/lib/core/cortex_m7/stclang/libtouchgfx-float-abi-hard.a

    In *.ioc I changed:

    ProjectManager.CompilerLinker=Starm-Clang

    to

    ProjectManager.CompilerLinker=GCC

    With a text editor since the option is greyed out in STM32CubeMX.

    Then I clicked "Generate Code" TouchGFX and it changed cmake/touchgfx/CMakeLists.txt:

    -${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/stclang/libtouchgfx${HARD_FLOAT}.a

    to

    ${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc/libtouchgfx${HARD_FLOAT}.a


    I don't like compiler dependent hardcoded lines. I prefer CMAKE variables for that. So my suggestion is that ST uses a variable for that so the CMakeLists.txt doesn't change when you change the compiler. For example: 

    if("${TOOLCHAIN_PREFIX}" STREQUAL "starm-")
    set(LIB_TOOLCHAIN_DIR "stclang")
    else()
    set(LIB_TOOLCHAIN_DIR "gcc")
    endif()


    # Link touchgfx (and nemagfx) static libs
    target_link_libraries(TouchGFX PRIVATE
    ${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/${LIB_TOOLCHAIN_DIR}/libtouchgfx${HARD_FLOAT}.a
    )

    I've added it now, but I know it will be overwritten next time I use TouchGFX.

    Touchgfx cmake runs "target_link_libraries" when included using "add_subdirectory(cmake/touchgfx)". There is no clean way to unlink libraries in cmake without modifying the source code.

    I can also create multiple presets:

    {
    "version": 3,
    "configurePresets": [
    {
    "name": "default_gcc",
    "hidden": true,
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/build/${presetName}",
    "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
    "cacheVariables": {}
    },
    {
    "name": "default_clang",
    "hidden": true,
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/build/${presetName}",
    "toolchainFile": "${sourceDir}/cmake/starm-clang.cmake",
    "cacheVariables": {}
    },
    {
    "name": "Debug_clang",
    "inherits": "default_clang",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug"
    }
    },
    {
    "name": "Debug_gcc",
    "inherits": "default_gcc",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug"
    }
    },
    {
    "name": "Configure preset using toolchain file",
    "displayName": "Configure preset using toolchain file",
    "description": "Sets Ninja generator, build and install directory",
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/out/build/${presetName}",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug",
    "CMAKE_TOOLCHAIN_FILE": "",
    "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
    }
    }
    ],
    "buildPresets": [
    {
    "name": "Debug_clang",
    "configurePreset": "Debug_clang"
    },
    {
    "name": "Debug_gcc",
    "configurePreset": "Debug_gcc"
    }
    ]
    }

    But this means different build folders so it requires updating launch file too:

     "imageFileName": "${command:cmake.launchTargetPath}" 

    This seems to work.

     

    3 replies

    ST Employee
    November 22, 2025

    @unsigned_char_array 

    Currently, the toolchain swap automation is not complete. Using "Setup STM32Cube project(s)" is the correct approach, as it allows you to update pointers to the required tools outside of VSCode, including the toolchain compiler itself.

    However, updating the tools involved in the process is not enough. You must also update your project files manually. At this time, we do not provide automated assistance for this. You need to update your CMake-related files yourself, specifically CMakePresets.json and the toolchain configuration file with the .cmake extension.

    Is your project generated by STM32CubeMX? If so, the toolchain config files are provided, and you only need to update the first pointer in CMakePresets.json.

    Visitor II
    November 22, 2025

    I’ve run into a similar issue before. STM32CubeIDE sometimes keeps the old toolchain settings even after changing them in the project setup. Usually the safest way is to regenerate the project from CubeMX with the new toolchain selected, or manually clean the CMake cache and let it rebuild the presets. Also make sure there are no leftover toolchain paths in your project’s CMake files. It’s a bit annoying, but doing a full clean + regeneration has worked for me. Hope this helps!

    Graduate II
    November 25, 2025

    In CMakePresets.json I changed:

     

    "toolchainFile": "${sourceDir}/cmake/starm-clang.cmake",

    to

    "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",

     I deleted the build folder. Then I restarted VS Code.

    This fixed most of the configuration. Build started with GCC, but touchgfx still was pointing to 
    Middlewares/ST/touchgfx/lib/core/cortex_m7/stclang/libtouchgfx-float-abi-hard.a

    In *.ioc I changed:

    ProjectManager.CompilerLinker=Starm-Clang

    to

    ProjectManager.CompilerLinker=GCC

    With a text editor since the option is greyed out in STM32CubeMX.

    Then I clicked "Generate Code" TouchGFX and it changed cmake/touchgfx/CMakeLists.txt:

    -${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/stclang/libtouchgfx${HARD_FLOAT}.a

    to

    ${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/gcc/libtouchgfx${HARD_FLOAT}.a


    I don't like compiler dependent hardcoded lines. I prefer CMAKE variables for that. So my suggestion is that ST uses a variable for that so the CMakeLists.txt doesn't change when you change the compiler. For example: 

    if("${TOOLCHAIN_PREFIX}" STREQUAL "starm-")
    set(LIB_TOOLCHAIN_DIR "stclang")
    else()
    set(LIB_TOOLCHAIN_DIR "gcc")
    endif()


    # Link touchgfx (and nemagfx) static libs
    target_link_libraries(TouchGFX PRIVATE
    ${CMAKE_SOURCE_DIR}/Middlewares/ST/touchgfx/lib/core/cortex_m7/${LIB_TOOLCHAIN_DIR}/libtouchgfx${HARD_FLOAT}.a
    )

    I've added it now, but I know it will be overwritten next time I use TouchGFX.

    Touchgfx cmake runs "target_link_libraries" when included using "add_subdirectory(cmake/touchgfx)". There is no clean way to unlink libraries in cmake without modifying the source code.

    I can also create multiple presets:

    {
    "version": 3,
    "configurePresets": [
    {
    "name": "default_gcc",
    "hidden": true,
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/build/${presetName}",
    "toolchainFile": "${sourceDir}/cmake/gcc-arm-none-eabi.cmake",
    "cacheVariables": {}
    },
    {
    "name": "default_clang",
    "hidden": true,
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/build/${presetName}",
    "toolchainFile": "${sourceDir}/cmake/starm-clang.cmake",
    "cacheVariables": {}
    },
    {
    "name": "Debug_clang",
    "inherits": "default_clang",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug"
    }
    },
    {
    "name": "Debug_gcc",
    "inherits": "default_gcc",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug"
    }
    },
    {
    "name": "Configure preset using toolchain file",
    "displayName": "Configure preset using toolchain file",
    "description": "Sets Ninja generator, build and install directory",
    "generator": "Ninja",
    "binaryDir": "${sourceDir}/out/build/${presetName}",
    "cacheVariables": {
    "CMAKE_BUILD_TYPE": "Debug",
    "CMAKE_TOOLCHAIN_FILE": "",
    "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
    }
    }
    ],
    "buildPresets": [
    {
    "name": "Debug_clang",
    "configurePreset": "Debug_clang"
    },
    {
    "name": "Debug_gcc",
    "configurePreset": "Debug_gcc"
    }
    ]
    }

    But this means different build folders so it requires updating launch file too:

     "imageFileName": "${command:cmake.launchTargetPath}" 

    This seems to work.