Fixed bug 5366 - cmake build doesn't detect Metal on macOS

Tom Seddon

This is as of commit 50d804ea729accf9e3a9ce83238d0a2976a17545 from https://github.com/SDL-mirror/SDL, which is HEAD as I write (apologies, not confident with Mercurial)

# Config

macOS: 10.14.6 (18G6042)
cmake --version: cmake version 3.16.20200101-g23e782c
clang --version: Apple clang version 11.0.0 (clang-1100.0.33.17)
Xcode version: Version 11.3.1 (11C504)

# Repro steps

Run the following commands in the shell.

 cd /tmp/
 git clone https://github.com/SDL-mirror/SDL
 mkdir build.SDL
 cd build.SDL
 cmake -G ../SDL/

Examine cmake output.

# Expected result

Metal is detected.

# Actual result

It appears that Metal is not detected! Note this line in the summary:

 --   RENDER_METAL           (Wanted: 0): OFF

# Fix

Change check_c_source_compiles to check_objc_source_compiles. The cmake script tries to add -ObjC to the clang command line, but, for whatever reason, this doesn't seem to work.

Change the test source to have an empty main. The "return 0;" line seems to confuse cmake somehow, causing it to crap out with an error about HAVE_FRAMEWORK_METAL being an unknown argument. (Maybe I'm just dense, but it's not obvious to me what the problem is here.)

With these two changes:

 --   RENDER_METAL           (Wanted: ON): ON

Patch attached.
1 file changed