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 CMakefind_*
commands need to look into this sysroot.CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
: This variable controls whether theCMAKE_FIND_ROOT_PATH
andCMAKE_SYSROOT
are used byfind_library()
. We set toONLY
, so CMake willfind_library
under this path only.CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
: This variable controls whether theCMAKE_FIND_ROOT_PATH
andCMAKE_SYSROOT
are used byfind_file()
andfind_path()
. We set toONLY
, so CMake will look into this path only.