]> granicus.if.org Git - esp-idf/commitdiff
cmake: Add toolchain version check
authorAngus Gratton <angus@espressif.com>
Sun, 14 Jan 2018 23:25:35 +0000 (10:25 +1100)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
idf.cmake
tools/cmake/crosstool_version_check.cmake [new file with mode: 0644]

index 8586d687a17d008448df89737e8008b7fa331d1e..d1623f2757460ed2cffe0a4aed94b83c3b18711a 100644 (file)
--- a/idf.cmake
+++ b/idf.cmake
@@ -32,6 +32,13 @@ include(GetGitRevisionDescription)
 include(utilities)
 include(components)
 include(kconfig)
+include(crosstool_version_check)
+
+#
+# Warn if the toolchain version doesn't match
+#
+gcc_version_check("5.2.0")
+crosstool_version_check("1.22.0-80-g6c4433a")
 
 #
 # Configure optional variables
@@ -76,3 +83,4 @@ finish_component_registration()
 if(NOT BOOTLOADER_BUILD)
   include(bootloader_subproject)
 endif()
+
diff --git a/tools/cmake/crosstool_version_check.cmake b/tools/cmake/crosstool_version_check.cmake
new file mode 100644 (file)
index 0000000..ed51890
--- /dev/null
@@ -0,0 +1,31 @@
+# Function to check the toolchain used the expected version
+# of crosstool, and warn otherwise
+
+set(ctng_version_warning "Check Getting Started documentation or proceed at own risk.")
+
+function(gcc_version_check expected_gcc_version)
+  if(NOT "${CMAKE_C_COMPILER_VERSION}" STREQUAL "${expected_gcc_version}")
+    message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} version ${CMAKE_C_COMPILER_VERSION} is not the supported version ${expected_gcc_version}. ${ctng_version_warning}")
+  endif()
+endfunction()
+
+function(crosstool_version_check expected_ctng_version)
+  execute_process(
+    COMMAND ${CMAKE_C_COMPILER} -v
+    ERROR_VARIABLE toolchain_stderr
+    OUTPUT_QUIET)
+
+    string(REGEX MATCH "crosstool-ng-[0-9a-g\\.-]+" ctng_version "${toolchain_stderr}")
+    string(REPLACE "crosstool-ng-" "" ctng_version "${ctng_version}")
+       # We use FIND to match version instead of STREQUAL because some toolchains are built
+       # with longer git hash strings than others. This will match any version which starts with
+       # the expected version string.
+       string(FIND "${ctng_version}" "${expected_ctng_version}" found_expected_version)
+    if(NOT ctng_version)
+        message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} does not appear to be built with crosstool-ng. "
+            "${ctng_version_warning}")
+    elseif(found_expected_version EQUAL -1)
+        message(WARNING "Xtensa toolchain ${CMAKE_C_COMPILER} crosstool-ng version ${ctng_version} "
+            "doesn't match supported version ${expected_ctng_version}. ${ctng_version_warning}")
+    endif()
+endfunction()