find_program does not work as expected in toolchain files
I tried writing a toolchain-file which can use the system compiler with a CMAKE_SYSROOT
.
It works on Linux as clang is in PATH
, but does not work on Windows where clang is typically installed in $ENV{ProgramFiles}/LLVM/bin
.
It seems that required variables like CMAKE_SYSTEM_PREFIX_PATH
are set later.
- Is there a way to force initialization of those variables?
- Are the
find_*
commands not allowed to be used in toolchain files? - Some explanation in the docs about what / what not to do in toolchain-files would be welcome.
I already found out that the behavior changes before / after the project
command, which makes
sense since the toolchain can affect search paths.
But i dont see why CMAKE_SYSTEM_PREFIX_PATH
should not be initialized early.
Relevant fragment of the toolchain file:
set(_clang_path)
if(CMAKE_HOST_WIN32)
set(_clang_path PATH_SUFFIXES LLVM/bin)
endif()
find_program(_clang_exe clang NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CACHE ${_clang_path})
find_program(_clangp_exe clang++ NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CACHE ${_clang_path})
set(CMAKE_C_COMPILER "${_clang_exe}")
set(CMAKE_CXX_COMPILER "${_clangp_exe}")
Edited by nolange