host-tools.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # SPDX-License-Identifier: Apache-2.0
  2. # This is the minimum required version for Zephyr to work (Old style)
  3. set(REQUIRED_SDK_VER 0.11.1)
  4. cmake_host_system_information(RESULT TOOLCHAIN_ARCH QUERY OS_PLATFORM)
  5. if(NOT DEFINED ZEPHYR_SDK_INSTALL_DIR)
  6. # Until https://github.com/zephyrproject-rtos/zephyr/issues/4912 is
  7. # resolved we use ZEPHYR_SDK_INSTALL_DIR to determine whether the user
  8. # wants to use the Zephyr SDK or not.
  9. return()
  10. endif()
  11. # Cache the Zephyr SDK install dir.
  12. set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR} CACHE PATH "Zephyr SDK install directory")
  13. if(NOT DEFINED SDK_VERSION)
  14. if(ZEPHYR_TOOLCHAIN_VARIANT AND ZEPHYR_SDK_INSTALL_DIR)
  15. # Manual detection for Zephyr SDK 0.11.1 and 0.11.2 for backward compatibility.
  16. set(sdk_version_path ${ZEPHYR_SDK_INSTALL_DIR}/sdk_version)
  17. if(NOT (EXISTS ${sdk_version_path}))
  18. message(FATAL_ERROR
  19. "The file '${ZEPHYR_SDK_INSTALL_DIR}/sdk_version' was not found. \
  20. Is ZEPHYR_SDK_INSTALL_DIR=${ZEPHYR_SDK_INSTALL_DIR} misconfigured?")
  21. endif()
  22. # Read version as published by the SDK
  23. file(READ ${sdk_version_path} SDK_VERSION_PRE1)
  24. # Remove any pre-release data, for example 0.10.0-beta4 -> 0.10.0
  25. string(REGEX REPLACE "-.*" "" SDK_VERSION_PRE2 ${SDK_VERSION_PRE1})
  26. # Strip any trailing spaces/newlines from the version string
  27. string(STRIP ${SDK_VERSION_PRE2} SDK_VERSION)
  28. string(REGEX MATCH "([0-9]*).([0-9]*)" SDK_MAJOR_MINOR ${SDK_VERSION})
  29. string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" SDK_MAJOR_MINOR_MICRO ${SDK_VERSION})
  30. #at least 0.0.0
  31. if(NOT SDK_MAJOR_MINOR_MICRO)
  32. message(FATAL_ERROR "sdk version: ${SDK_MAJOR_MINOR_MICRO} improper format.
  33. Expected format: x.y.z
  34. Check whether the Zephyr SDK was installed correctly.
  35. ")
  36. endif()
  37. endif()
  38. endif()
  39. message(STATUS "Using toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
  40. if(${SDK_VERSION} VERSION_LESS_EQUAL 0.11.2)
  41. # For backward compatibility with 0.11.1 and 0.11.2
  42. # we need to source files from Zephyr repo
  43. include(${CMAKE_CURRENT_LIST_DIR}/${SDK_MAJOR_MINOR}/host-tools.cmake)
  44. else()
  45. include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/host-tools.cmake)
  46. endif()