Cmake cross compiling: finding tools
<p>I am using a standalone toolchain made from the android ndk13b. It works fine, but to find all the tools (linker, archiver etc.) I have a quite verbose section in my toolchain file. <strong>Is there a way to make it more condensed?</strong></p>

<pre><code>SET(COMPILER_PATH   "&lt;path_to_my_llvm_directory&gt;")

SET(CMAKE_TOOLCHAIN_PREFIX aarch64-linux-android-) #In theory should allow to find minor tools like ar and objdump, see http://stackoverflow.com/a/7032021/2436175
find_program(CMAKE_C_COMPILER   clang.cmd PATH ${COMPILER_PATH})
find_program(CMAKE_CXX_COMPILER clang++.cmd PATH ${COMPILER_PATH})
find_program(CMAKE_AR ${CMAKE_TOOLCHAIN_PREFIX}ar.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_RANLIB ${CMAKE_TOOLCHAIN_PREFIX}ranlib.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_LINKER ${CMAKE_TOOLCHAIN_PREFIX}ld.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_NM ${CMAKE_TOOLCHAIN_PREFIX}nm.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_OBJCOPY ${CMAKE_TOOLCHAIN_PREFIX}objcopy.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_OBJDUMP ${CMAKE_TOOLCHAIN_PREFIX}objdump.exe PATHS ${COMPILER_PATH})
find_program(CMAKE_STRIP ${CMAKE_TOOLCHAIN_PREFIX}strip.exe PATHS ${COMPILER_PATH})
</code></pre>

<p>What didn't work:</p>

<ul>
<li>Not explicitly using <code>find_program</code> -> It finds some other tools from some other mingw toolchain I have in my path</li>
<li>Setting <a href="https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH.html" rel="nofollow noreferrer"><code>CMAKE_FIND_ROOT_PATH</code></a> to <code>${COMPILER_PATH}</code>. It won't even find the compiler at that point. I can workaround that by setting the compiler instead with <code>SET(CMAKE_C_COMPILER   ${COMPILER_PATH}/clang.cmd)</code> (same for clang++), but it still doesn't find the other tools</li>
<li>Trying various flags with <a href="https://cmake.org/cmake/help/latest/command/find_program.html" rel="nofollow noreferrer"><code>find_program</code></a>, especially <code>ONLY_CMAKE_FIND_ROOT_PATH</code></li>
</ul>

<p>Note that I found <code>find_program</code> to be the only workaround to find the tools, because for example the following won't work: </p>

<pre><code>SET(CMAKE_AR ${COMPILER_PATH}/${CMAKE_TOOLCHAIN_PREFIX}ar.exe
</code></pre>

<p>(The archive operation will fail and I can see from cmake-gui that the variable is not set).</p>