crosstool_version_check.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Function to check the toolchain used the expected version
  2. # of crosstool, and warn otherwise
  3. set(ctng_version_warning "Check Getting Started documentation or proceed at own risk.")
  4. function(gcc_version_check expected_gcc_version)
  5. if(NOT "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${expected_gcc_version}")
  6. message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} version ${CMAKE_C_COMPILER_VERSION} "
  7. "is not the supported version ${expected_gcc_version}. ${ctng_version_warning}")
  8. endif()
  9. endfunction()
  10. function(crosstool_version_check expected_ctng_version)
  11. execute_process(
  12. COMMAND ${CMAKE_C_COMPILER} -v
  13. ERROR_VARIABLE toolchain_stderr
  14. OUTPUT_QUIET)
  15. string(REGEX MATCH "crosstool-ng-[0-9a-g\\.-]+" ctng_version "${toolchain_stderr}")
  16. # We use FIND to match version instead of STREQUAL because some toolchains are built
  17. # with longer git hash strings than others. This will match any version which starts with
  18. # the expected version string.
  19. string(FIND "${ctng_version}" "${expected_ctng_version}" found_expected_version)
  20. if(NOT ctng_version)
  21. message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} does not appear to be built with crosstool-ng. "
  22. "${ctng_version_warning}")
  23. elseif(found_expected_version EQUAL -1)
  24. message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} crosstool-ng version ${ctng_version} "
  25. "doesn't match supported version ${expected_ctng_version}. ${ctng_version_warning}")
  26. endif()
  27. endfunction()
  28. function(get_expected_ctng_version _toolchain_ver _gcc_ver)
  29. file(STRINGS ${IDF_PATH}/tools/toolchain_versions.mk config_contents)
  30. foreach(name_and_value ${config_contents})
  31. # Strip spaces
  32. string(REPLACE " " "" name_and_value ${name_and_value})
  33. # Find variable name
  34. string(REGEX MATCH "^[^=]+" name ${name_and_value})
  35. # Find the value
  36. string(REPLACE "${name}=" "" value ${name_and_value})
  37. # Getting values
  38. if("${name}" STREQUAL "SUPPORTED_TOOLCHAIN_COMMIT_DESC")
  39. set("${_toolchain_ver}" "${value}" PARENT_SCOPE)
  40. elseif("${name}" STREQUAL "SUPPORTED_TOOLCHAIN_GCC_VERSIONS")
  41. set(${_gcc_ver} "${value}" PARENT_SCOPE)
  42. endif()
  43. endforeach()
  44. endfunction()