When using CMake for cross compiling, one generally specifies a toolchain file via the CMAKE_TOOLCHAIN_FILE
option. In GNU terminology, one can specify the host architecture toolset using this file. However, one can generally not expect to be able to execute anything built with this toolchain. So often enough, some build tools need to be compiled for the build architecture.
Consider the following setup. I have two source files genfoo.c
and bar.c
. During build, genfoo.c
needs to be compiled and run. Its output needs to be written to foo.h
. Then I can compile bar.c
, which #include "foo.h"
. Since CMake defaults to using the host architecture toolchain, the instructions for bar.c
are easy. But how do I tell it to use the build architecture toolchain for compiling genfoo.c
? Simply saying add_executable(genfoo genfoo.c)
will result in using the wrong compiler.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…