find_compiler.cmake 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. # Toolchain file is processed multiple times, however, it cannot access CMake cache on some runs.
  2. # We store the search path in an environment variable so that we can always access it.
  3. if (NOT "${PICO_TOOLCHAIN_PATH}" STREQUAL "")
  4. set(ENV{PICO_TOOLCHAIN_PATH} "${PICO_TOOLCHAIN_PATH}")
  5. endif ()
  6. # Find the compiler executable and store its path in a cache entry ${compiler_path}.
  7. # If not found, issue a fatal message and stop processing. PICO_TOOLCHAIN_PATH can be provided from
  8. # commandline as additional search path.
  9. function(pico_find_compiler compiler_path compiler_exe)
  10. # Search user provided path first.
  11. find_program(
  12. ${compiler_path} ${compiler_exe}
  13. PATHS ENV PICO_TOOLCHAIN_PATH
  14. PATH_SUFFIXES bin
  15. NO_DEFAULT_PATH
  16. )
  17. # If not then search system paths.
  18. if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
  19. if (DEFINED ENV{PICO_TOOLCHAIN_PATH})
  20. message(WARNING "PICO_TOOLCHAIN_PATH specified ($ENV{PICO_TOOLCHAIN_PATH}), but ${compiler_exe} not found there")
  21. endif()
  22. find_program(${compiler_path} ${compiler_exe})
  23. endif ()
  24. if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
  25. set(PICO_TOOLCHAIN_PATH "" CACHE PATH "Path to search for compiler.")
  26. message(FATAL_ERROR "Compiler '${compiler_exe}' not found, you can specify search path with\
  27. \"PICO_TOOLCHAIN_PATH\".")
  28. endif ()
  29. endfunction()