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