CMakeLists.txt
changeset 12998 b87ba0fad17e
parent 12974 0fef4b21fa1d
child 13001 1353fb9be62b
     1.1 --- a/CMakeLists.txt	Sun Aug 04 23:30:55 2019 -0300
     1.2 +++ b/CMakeLists.txt	Mon Aug 05 12:35:32 2019 -0300
     1.3 @@ -373,8 +373,10 @@
     1.4  set_option(DIRECTX             "Use DirectX for Windows audio/video" ${WINDOWS})
     1.5  set_option(WASAPI              "Use the Windows WASAPI audio driver" ${WINDOWS})
     1.6  set_option(RENDER_D3D          "Enable the Direct3D render driver" ${WINDOWS})
     1.7 +set_option(RENDER_METAL        "Enable the Metal render driver" ${APPLE})
     1.8  set_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ${UNIX_SYS})
     1.9  dep_option(VIDEO_VULKAN        "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF)
    1.10 +set_option(VIDEO_METAL         "Enable Metal support" ${APPLE})
    1.11  set_option(VIDEO_KMSDRM        "Use KMS DRM video driver" ${UNIX_SYS})
    1.12  dep_option(KMSDRM_SHARED       "Dynamically load KMS DRM support" ON "VIDEO_KMSDRM" OFF)
    1.13  option_string(BACKGROUNDING_SIGNAL "number to use for magic backgrounding signal or 'OFF'" "OFF")
    1.14 @@ -1533,6 +1535,69 @@
    1.15      set(HAVE_SDL_FILESYSTEM TRUE)
    1.16    endif()
    1.17  
    1.18 +  # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
    1.19 +  if(SDL_VIDEO)
    1.20 +    if (IOS)
    1.21 +      set(SDL_VIDEO_DRIVER_UIKIT 1)
    1.22 +      file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
    1.23 +      set(SOURCE_FILES ${SOURCE_FILES} ${UIKITVIDEO_SOURCES})
    1.24 +    else()
    1.25 +      CheckCOCOA()
    1.26 +      if(VIDEO_OPENGL)
    1.27 +        set(SDL_VIDEO_OPENGL 1)
    1.28 +        set(SDL_VIDEO_OPENGL_CGL 1)
    1.29 +        set(SDL_VIDEO_RENDER_OGL 1)
    1.30 +        set(HAVE_VIDEO_OPENGL TRUE)
    1.31 +      endif()
    1.32 +
    1.33 +      if(VIDEO_OPENGLES)
    1.34 +        set(SDL_VIDEO_OPENGL_EGL 1)
    1.35 +        set(SDL_VIDEO_OPENGL_ES2 1)
    1.36 +        set(SDL_VIDEO_RENDER_OGL_ES2 1)
    1.37 +        set(HAVE_VIDEO_OPENGLES TRUE)
    1.38 +      endif()
    1.39 +    endif()
    1.40 +    
    1.41 +    if(VIDEO_VULKAN OR VIDEO_METAL OR RENDER_METAL)
    1.42 +      set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
    1.43 +      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x objective-c")
    1.44 +      check_c_source_compiles("
    1.45 +        #include <AvailabilityMacros.h>
    1.46 +        #import <Metal/Metal.h>
    1.47 +        #import <QuartzCore/CAMetalLayer.h>
    1.48 +
    1.49 +        #if TARGET_OS_SIMULATOR || (!TARGET_CPU_X86_64 && !TARGET_CPU_ARM64)
    1.50 +        #error Metal doesn't work on this configuration
    1.51 +        #endif
    1.52 +        int main()
    1.53 +        {
    1.54 +            return 0;
    1.55 +        }
    1.56 +        " HAVE_FRAMEWORK_METAL)
    1.57 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
    1.58 +      if(HAVE_FRAMEWORK_METAL)
    1.59 +        set(SDL_FRAMEWORK_METAL 1)
    1.60 +        set(SDL_FRAMEWORK_QUARTZCORE 1)
    1.61 +      else()
    1.62 +        set(VIDEO_VULKAN 0)
    1.63 +        set(VIDEO_METAL 0)
    1.64 +        set(RENDER_METAL 0)
    1.65 +      endif()
    1.66 +    endif()
    1.67 +
    1.68 +    if(VIDEO_METAL)
    1.69 +      set(SDL_VIDEO_METAL 1)
    1.70 +      set(HAVE_VIDEO_METAL TRUE)
    1.71 +    endif()
    1.72 +
    1.73 +    if(RENDER_METAL)
    1.74 +      file(GLOB RENDER_METAL_SOURCES ${SDL2_SOURCE_DIR}/src/render/metal/*.m)
    1.75 +      set(SOURCE_FILES ${SOURCE_FILES} ${RENDER_METAL_SOURCES})
    1.76 +      set(SDL_VIDEO_RENDER_METAL 1)
    1.77 +      set(HAVE_RENDER_METAL TRUE)
    1.78 +    endif()
    1.79 +  endif()
    1.80 +
    1.81    # Actually load the frameworks at the end so we don't duplicate include.
    1.82    if(SDL_FRAMEWORK_COREVIDEO)
    1.83      find_library(COREVIDEO CoreVideo)
    1.84 @@ -1562,28 +1627,20 @@
    1.85      find_library(AUDIOTOOLBOX AudioToolbox)
    1.86      list(APPEND EXTRA_LIBS ${AUDIOTOOLBOX})
    1.87    endif()
    1.88 -
    1.89 -  # iOS hack needed - http://code.google.com/p/ios-cmake/ ?
    1.90 -  if(SDL_VIDEO)
    1.91 -    if (IOS)
    1.92 -      set(SDL_VIDEO_DRIVER_UIKIT 1)
    1.93 -      file(GLOB UIKITVIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/uikit/*.m)
    1.94 -      set(SOURCE_FILES ${SOURCE_FILES} ${UIKITVIDEO_SOURCES})
    1.95 +  if(SDL_FRAMEWORK_METAL)
    1.96 +    if(IOS)
    1.97 +      find_library(METAL Metal)
    1.98 +      list(APPEND EXTRA_LIBS ${METAL})
    1.99      else()
   1.100 -      CheckCOCOA()
   1.101 -      if(VIDEO_OPENGL)
   1.102 -        set(SDL_VIDEO_OPENGL 1)
   1.103 -        set(SDL_VIDEO_OPENGL_CGL 1)
   1.104 -        set(SDL_VIDEO_RENDER_OGL 1)
   1.105 -        set(HAVE_VIDEO_OPENGL TRUE)
   1.106 -      endif()
   1.107 -
   1.108 -      if(VIDEO_OPENGLES)
   1.109 -        set(SDL_VIDEO_OPENGL_EGL 1)
   1.110 -        set(SDL_VIDEO_OPENGL_ES2 1)
   1.111 -        set(SDL_VIDEO_RENDER_OGL_ES2 1)
   1.112 -        set(HAVE_VIDEO_OPENGLES TRUE)
   1.113 -      endif()
   1.114 +      list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,Metal")
   1.115 +    endif()
   1.116 +  endif()
   1.117 +  if(SDL_FRAMEWORK_QUARTZCORE)
   1.118 +    if(IOS)
   1.119 +      find_library(QUARTZCORE QuartzCore)
   1.120 +      list(APPEND EXTRA_LIBS ${QUARTZCORE})
   1.121 +    else()
   1.122 +      list(APPEND EXTRA_LDFLAGS "-Wl,-weak_framework,QuartzCore")
   1.123      endif()
   1.124    endif()
   1.125