crosstool_version_check.cmake 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.\n")
  4. function(gcc_version_check expected_gcc_version)
  5. if(NOT "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${expected_gcc_version}")
  6. message(WARNING "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} --version
  13. OUTPUT_VARIABLE toolchain_version
  14. ERROR_QUIET)
  15. string(REGEX REPLACE ".*(crosstool-NG ([^\)]+)).*\n" "\\2" ctng_version "${toolchain_version}")
  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 "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. set(wrong_compiler_msg "\nToolchain: ${CMAKE_C_COMPILER}, "
  25. "crosstool-ng version ${ctng_version} doesn't match supported version ${expected_ctng_version}"
  26. "\nPlease try to run 'idf.py fullclean' to solve it quickly.\n")
  27. set(IDF_MAINTAINER $ENV{IDF_MAINTAINER})
  28. if(IDF_MAINTAINER)
  29. message(WARNING ${wrong_compiler_msg} ${ctng_version_warning})
  30. else()
  31. set(ctng_version_error "Check Getting Started documentation if the error continues."
  32. "\nYou can override this error and proceed with build by defining the IDF_MAINTAINER environment variable.\n")
  33. message(FATAL_ERROR ${wrong_compiler_msg} ${ctng_version_error})
  34. endif()
  35. endif()
  36. endfunction()
  37. function(get_expected_ctng_version _toolchain_ver _gcc_ver)
  38. idf_build_get_property(idf_path IDF_PATH)
  39. file(STRINGS ${idf_path}/tools/toolchain_versions.mk config_contents)
  40. foreach(name_and_value ${config_contents})
  41. # Strip spaces
  42. string(REPLACE " " "" name_and_value ${name_and_value})
  43. # Find variable name
  44. string(REGEX MATCH "^[^=]+" name ${name_and_value})
  45. # Find the value
  46. string(REPLACE "${name}=" "" value ${name_and_value})
  47. # Getting values
  48. if("${name}" STREQUAL "SUPPORTED_TOOLCHAIN_COMMIT_DESC")
  49. set("${_toolchain_ver}" "${value}" PARENT_SCOPE)
  50. elseif("${name}" STREQUAL "SUPPORTED_TOOLCHAIN_GCC_VERSIONS")
  51. set(${_gcc_ver} "${value}" PARENT_SCOPE)
  52. endif()
  53. endforeach()
  54. endfunction()