[cmake] Handle iOS, watchOS and tvOS when finding compiler-rt on Apple
authorLouis Dionne <ldionne.2@gmail.com>
Mon, 21 Mar 2022 17:43:02 +0000 (13:43 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Tue, 22 Mar 2022 01:55:09 +0000 (21:55 -0400)
This patch uses CMAKE_OSX_SYSROOT, which should contain the SDK path
that we're building against on Apple platforms, to determine which
platform we are compiling for and set the compiler-rt suffix accordingly.

Differential Revision: https://reviews.llvm.org/D122161

cmake/Modules/HandleCompilerRT.cmake

index 51409d6..a55984c 100644 (file)
@@ -20,8 +20,26 @@ function(get_component_name name variable)
     if(NOT name MATCHES "builtins.*")
       set(component_name "${name}_")
     endif()
-    # TODO: Support ios, tvos and watchos as well.
-    set(component_name "${component_name}osx")
+    if (CMAKE_OSX_SYSROOT MATCHES ".+MacOSX.+")
+      set(component_name "${component_name}osx")
+
+    elseif (CMAKE_OSX_SYSROOT MATCHES ".+iPhoneOS.+")
+      set(component_name "${component_name}ios")
+    elseif (CMAKE_OSX_SYSROOT MATCHES ".+iPhoneSimulator.+")
+      set(component_name "${component_name}iossim")
+
+      elseif (CMAKE_OSX_SYSROOT MATCHES ".+AppleTVOS.+")
+      set(component_name "${component_name}tvos")
+    elseif (CMAKE_OSX_SYSROOT MATCHES ".+AppleTVSimulator.+")
+      set(component_name "${component_name}tvossim")
+
+    elseif (CMAKE_OSX_SYSROOT MATCHES ".+WatchOS.+")
+      set(component_name "${component_name}watchos")
+    elseif (CMAKE_OSX_SYSROOT MATCHES ".+WatchSimulator.+")
+      set(component_name "${component_name}watchossim")
+    else()
+      message(FATAL_ERROR "Unknown Apple SDK ${CMAKE_OSX_SYSROOT}, we don't know which compiler-rt library suffix to use.")
+    endif()
   else()
     set(component_name "${name}")
   endif()