From 0691517ced61dc1789b8efbee301f46756f7cecb Mon Sep 17 00:00:00 2001
From: "Kirill A. Korinsky" <kirill@korins.ky>
Date: Wed, 17 Aug 2022 14:13:11 +0200
Subject: [PATCH] compiler-rt: added CMAKE_OSX_DEPLOYMENT_TARGET fallback

---
 .../cmake/Modules/CompilerRTDarwinUtils.cmake      | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
index be8d7e733c7a..ab0b0a43f2b6 100644
--- a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -69,15 +69,6 @@ function(find_darwin_sdk_version var sdk_name)
       ERROR_FILE /dev/null
     )
   endif()
-  if(NOT result_process EQUAL 0)
-    message(FATAL_ERROR
-      "Failed to determine SDK version for \"${sdk_name}\" SDK")
-  endif()
-  # Check reported version looks sane.
-  if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$")
-    message(FATAL_ERROR
-      "Reported SDK version \"${var_internal}\" does not look like a version")
-  endif()
   set(${var} ${var_internal} PARENT_SCOPE)
 endfunction()
 
@@ -128,6 +119,11 @@ function(darwin_test_archs os valid_archs)
     # binaries.
     if ("${os}" STREQUAL "osx")
       find_darwin_sdk_version(macosx_sdk_version "macosx")
+      # if there is no sdk that responds to "macosx" use the CMAKE passed in deployment target
+      if(NOT macosx_sdk_version)
+        message(WARNING "Could not determine MacOSX SDK Version, trying CMAKE_OSX_DEPLOYMENT_TARGET")
+        set(macosx_sdk_version CMAKE_OSX_DEPLOYMENT_TARGET)
+      endif()
       if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15)
         message(STATUS "Disabling i386 slice for ${valid_archs}")
         list(REMOVE_ITEM archs "i386")
-- 
2.37.2

