How to specify toolchain path in mbed CLI2?

The mbed-tools configure command allows to select the toolchain to be used by CMake for compilation:

mbed-tools configure --help
Usage: mbed-tools configure [OPTIONS]

  Generate an Mbed OS config CMake file and write it to a .mbedbuild folder in
  the program directory.

Options:
  --custom-targets-json PATH     Path to custom_targets.json.
  -t, --toolchain [ARM|GCC_ARM]  The toolchain you are using to build your
                                 app.  [required]
  -m, --mbed-target TEXT         A build target for an Mbed-enabled device,
                                 eg. K64F  [required]
  -b, --profile TEXT             The build type (release, develop or debug).
  -o, --output-dir PATH          Path to output directory.
  -p, --program-path PATH        Path to local Mbed program. By default is the
                                 current working directory.
  --mbed-os-path PATH            Path to local Mbed OS directory.
  --app-config PATH              Path to application configuration file.
  -h, --help                     Show this message and exit.

But how can I specify the path to the selected toolchain?

For example, on Linux the GCC ARM toolchain can be placed (unzipped) to any directory (there is no installation script provided).

In mbed CLI1 this can be done by setting the GCC_ARM_PATH system variable:

mbed config -G GCC_ARM_PATH <path to the GCC ARM toolchain>

CMake has its own mechanism to find a suitable compiler and there are env vars or vars to specify the path,

set(CMAKE_C_COMPILER   /usr/opt/my_c_compiler/bin/gcc  )
set(CMAKE_CXX_COMPILER /usr/opt/my_c_compiler/bin/g++ )

I haven’t checked what is possible in CLI2, maybe it is only the compiler that is found by CMake in the search path.

In VSCode it is very conveniant with the cmake-tools extension. The avaiible compilers can be added in a json config and then selected by a drown down box in the IDE.

Thank you for the tip. Unfortunately it does not work. After adding full paths in CMakeLists.txt I have got:

$ mbed-tools compile -m LPC1768 -t GCC_ARM
Configuring project and generating build system...
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- The ASM compiler identification is unknown
-- Found assembler: arm-none-eabi-gcc
CMake Error at mbed-os/tools/cmake/app.cmake:27 (enable_language):
  The CMAKE_C_COMPILER:

    arm-none-eabi-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  CMakeLists.txt:14 (include)


CMake Error at mbed-os/tools/cmake/app.cmake:27 (enable_language):
  The CMAKE_CXX_COMPILER:

    arm-none-eabi-g++

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  CMakeLists.txt:14 (include)


CMake Error at mbed-os/tools/cmake/app.cmake:27 (enable_language):
  The CMAKE_ASM_COMPILER:

    arm-none-eabi-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
Call Stack (most recent call first):
  CMakeLists.txt:14 (include)


-- Warning: Did not find file Compiler/-ASM
-- Configuring incomplete, errors occurred!
See also "/home/zoli/src/mbed/app/os-6/CMake/test01/cmake_build/LPC1768/develop/GCC_ARM/CMakeFiles/CMakeOutput.log".
See also "/home/zoli/src/mbed/app/os-6/CMake/test01/cmake_build/LPC1768/develop/GCC_ARM/CMakeFiles/CMakeError.log".
ERROR: CMake invocation failed!

More information may be available by using the command line option '-v'.

Setting the environment variables (CC, CXX, ASM) did not help either.

do you have the arm-none-eabi-gcc in the search path? For linux/wsl I had that in the path in .profile:
PATH=$PATH:/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin

but it should work with setting the compiler path in CMakelists.txt.

The error msg sounds like gcc is called for asm, shouldn’t it be arm-none-eabi-as ?

There is also a tool cmake-gui, this shows also the cached settings.

edit:
I could not find the setting for the path.
in mbed-os/tools/cmake/toolchainss/GCC_ARM.cmake you’ll find:

# specify the cross compiler.  Use cache variables so that VS Code can detect the compiler from the cache.
set(CMAKE_C_COMPILER arm-none-eabi-gcc CACHE FILEPATH "C Compiler")
set(CMAKE_CXX_COMPILER arm-none-eabi-g++ CACHE FILEPATH "CXX Compiler")
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc CACHE FILEPATH "ASM Compiler")

this is for mbed-ce, in mbed-os it is the same except the part witch CACHE is missing. But that is for VSC.

I’ve checked it again, cmake tries to find the compiler in the search path. The set(CMAKE_COMPILER is overriden by the mbed cmake, so the error message is ‘arm-none-eabi-gcc not found on path’.
The settings from the python build system are ignored.

The compiler path is cached in CMakeCache.txt, so after a change the cache must be cleared that changes have an effect.

Adding the GCC ARM toolchain path to the PATH environment variable works. Thank you!