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.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b65f438..2fa8d56 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,7 @@ include(CheckIncludeFiles)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckCSourceCompiles)
+include(CheckOBJCSourceCompiles)
include(CheckCSourceRuns)
include(CheckCCompilerFlag)
include(CheckTypeSize)
@@ -1759,9 +1760,7 @@ elseif(APPLE)
endif()
if(VIDEO_VULKAN OR VIDEO_METAL OR RENDER_METAL)
- set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
- set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -ObjC")
- check_c_source_compiles("
+ check_objc_source_compiles("
#include <AvailabilityMacros.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
@@ -1771,10 +1770,8 @@ elseif(APPLE)
#endif
int main()
{
- return 0;
}
" HAVE_FRAMEWORK_METAL)
- set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
if(HAVE_FRAMEWORK_METAL)
set(SDL_FRAMEWORK_METAL 1)
set(SDL_FRAMEWORK_QUARTZCORE 1)