Add objective-c language support in CMake (#80432)

Fixes #80018

Local build on my machine looks fine.

cc @albanD @peterbell10

Pull Request resolved: https://github.com/pytorch/pytorch/pull/80432
Approved by: https://github.com/albanD
diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
index a1f8018..8d8d489 100644
--- a/caffe2/CMakeLists.txt
+++ b/caffe2/CMakeLists.txt
@@ -779,6 +779,12 @@
   list(APPEND Caffe2_CPU_SRCS ${Caffe2_MPS_SRCS})
 endif()
 
+if(USE_MPS OR USE_METAL)
+  if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.16")
+    enable_language(OBJCXX)
+  endif()
+endif()
+
 # NOTE [ Linking AVX and non-AVX files ]
 #
 # Regardless of the CPU capabilities, we build some files with AVX2, and AVX512