Docs should mention that CMAKE_TOOLCHAIN_FILE does not have access to the cache
I am unsure if this is intended behavior.
When setting the CMAKE_SYSROOT variable in a Toolchain file, cache variables defined inside the Toolchain file are expanded in the --sysroots option passed to the compiler, but cache variables defined on the command line do not expand
Example:
In the Toolchain file: set(internal-dir xyz)
(set CMAKE_SYSROOT {internal-dir}/
{external-dir}/example)
On the command line:
cmake -Dexternal-dir=abc -DCMAKE_TOOLCHAIN_FILE=Toolchain.cmake
When trying to compile, --sysroot will be 'xyz//example', but the value of ${external-dir} is indeed set as abc confirmed by printing the value of ${external-dir}.