title: How to instruct CMake to use the build architecture compiler
body: <p>When using CMake for cross compiling, one generally specifies a toolchain file via the <code>CMAKE_TOOLCHAIN_FILE</code> option. In <a href="https://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html" rel="noreferrer">GNU terminology</a>, 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.</p>
  
  <p>Consider the following setup. I have two source files <code>genfoo.c</code> and <code>bar.c</code>. During build, <code>genfoo.c</code> needs to be compiled and run. Its output needs to be written to <code>foo.h</code>. Then I can compile <code>bar.c</code>, which <code>#include "foo.h"</code>. Since CMake defaults to using the host architecture toolchain, the instructions for <code>bar.c</code> are easy. But how do I tell it to use the build architecture toolchain for compiling <code>genfoo.c</code>? Simply saying <code>add_executable(genfoo genfoo.c)</code> will result in using the wrong compiler.</p>