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}.ato
${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.