CMake: Toolchain File
When we have a build system like Yocto or Buildroot, cross compiling a CMake project is a simple task - We just need to create a simple CMake inherited recipe. If the SoC vendor only provides toolchain for you to cross compile a single CMake project, CMake toolchain file is a good approach.
What is CMake Toolchain File
CMake has a variable CMAKE_TOOLCHAIN_FILE:
This variable is specified on the command line when cross-compiling with CMake. It is the path to a file which is read early in the CMake run and which specifies locations for compilers and toolchain utilities, and other target platform and compiler related information.
Toolchain File Example
| 1 | SET(CMAKE_SYSTEM_NAME Linux) | 
- CMAKE_FIND_ROOT_PATH: This variable tells CMake- find_*commands need to look into this sysroot.
- CMAKE_FIND_ROOT_PATH_MODE_LIBRARY: This variable controls whether the- CMAKE_FIND_ROOT_PATHand- CMAKE_SYSROOTare used by- find_library(). We set to- ONLY, so CMake will- find_libraryunder this path only.
- CMAKE_FIND_ROOT_PATH_MODE_INCLUDE: This variable controls whether the- CMAKE_FIND_ROOT_PATHand- CMAKE_SYSROOTare used by- find_file()and- find_path(). We set to- ONLY, so CMake will look into this path only.