[ASan] CMake support for building ASan runtime as a universal binary on Mac

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@161665 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8985c2..a7d9a89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,18 @@
             COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}"
             CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}")
 
+function(filter_available_targets out_var)
+  set(archs)
+  foreach(arch ${ARGN})
+    if(${arch} STREQUAL "x86_64" AND CAN_TARGET_X86_64)
+      list(APPEND archs ${arch})
+    elseif (${arch} STREQUAL "i386" AND CAN_TARGET_I386)
+      list(APPEND archs ${arch})
+    endif()
+  endforeach()
+  set(${out_var} ${archs} PARENT_SCOPE)
+endfunction()
+
 # Because compiler-rt spends a lot of time setting up custom compile flags,
 # define a handy helper function for it. The compile flags setting in CMake
 # has serious issues that make its syntax challenging at best.