in

CMake: pass variables to custom toolchain file


I am creating a toolchain file for a gcc-based C compiler for a non-popular platform. I would like users to pass a path to compiler root directory, while a toolchain file will set up all the paths to c/c++/ar/whatever, set proper compile flags.

My toolchain file starts with this check:

IF(NOT TOOLCHAIN_PREFIX)
     MESSAGE(FATAL_ERROR "No TOOLCHAIN_PREFIX specified")
ENDIF()

All other paths are calculated based on TOOLCHAIN_PREFIX variable, which I want users to be passed as a parameter to cmake (e.g. cmake -DTOOLCHAIN_PREFIX=/path/to/compiler/root ..)

Problem: during configuration process, cmake gets to ‘Detecting C compiler ABI info’ step, and runs compilation of a test program, and passes there a toolchain file. The issue is that my variable TOOLCHAIN_PREFIX is not passed there. As result I get error and configuration process stops.

What is the proper way of passing my TOOLCHAIN_PREFIX parameter to the nested try_compile() operations?

Alternative question: what is the proper way of building toolchain files so that it can search for a compiler at a specific path?



Source: https://stackoverflow.com/questions/70558484/cmake-pass-variables-to-custom-toolchain-file

Getting Started with Kotlin Coroutines

KD – A fantastic game created in python with pygame