Using sysroots to isolate build environments
In a nutshell, a system root, or just sysroot, is a directory that a build system considers to be the root directory from which to locate headers and libraries. In brief, they contain a stripped-down version of the root filesystem for the platform for which software is being compiled. They are often used when cross-compiling software for other platforms, as described in Chapter 12, Cross-Platform Compiling and Custom Toolchains. If containers for shipping whole build environments are not an option, sysroots can be an alternative to provide a defined build environment.
To use a sysroot with CMake, a toolchain file is needed. As the name suggests, these files define the tools to use to compile and link the software as well as where to find any libraries. In a normal build, CMake automatically detects the toolchain by introspecting the system. Toolchain files are passed to CMake with the CMAKE_TOOLCHAIN_FILE
variable like this:
cmake...