duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

AddMetalSources.cmake (2183B)


      1 # Borrowed from PCSX2.
      2 
      3 if(APPLE)
      4   function(add_metal_sources target sources)
      5     if(CMAKE_GENERATOR MATCHES "Xcode")
      6       # If we're generating an xcode project, you can just add the shaders to the main pcsx2 target and xcode will deal with them properly
      7       # This will make sure xcode supplies code completion, etc (if you use a custom command, it won't)
      8       set_target_properties(${target} PROPERTIES
      9         XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO INCLUDE_SOURCE
     10       )
     11       foreach(shader IN LISTS sources)
     12         target_sources(${target} PRIVATE ${shader})
     13         set_source_files_properties(${shader} PROPERTIES LANGUAGE METAL)
     14       endforeach()
     15     else()
     16       function(generateMetallib std triple outputName)
     17         set(MetalShaderOut)
     18         set(flags
     19           -ffast-math
     20           $<$<NOT:$<CONFIG:Release,MinSizeRel>>:-gline-tables-only>
     21           $<$<NOT:$<CONFIG:Release,MinSizeRel>>:-MO>
     22         )
     23         foreach(shader IN LISTS sources)
     24           file(RELATIVE_PATH relativeShader "${CMAKE_SOURCE_DIR}" "${shader}")
     25           set(shaderOut ${CMAKE_CURRENT_BINARY_DIR}/${outputName}/${relativeShader}.air)
     26           list(APPEND MetalShaderOut ${shaderOut})
     27           get_filename_component(shaderDir ${shaderOut} DIRECTORY)
     28           add_custom_command(OUTPUT ${shaderOut}
     29             COMMAND ${CMAKE_COMMAND} -E make_directory ${shaderDir}
     30             COMMAND xcrun metal ${flags} -std=${std} -target ${triple} -o ${shaderOut} -c ${shader}
     31             DEPENDS ${shader}
     32           )
     33           set(metallib ${CMAKE_CURRENT_BINARY_DIR}/${outputName}.metallib)
     34         endforeach()
     35         add_custom_command(OUTPUT ${metallib}
     36           COMMAND xcrun metallib -o ${metallib} ${MetalShaderOut}
     37           DEPENDS ${MetalShaderOut}
     38         )
     39         target_sources(${target} PRIVATE ${metallib})
     40         set_source_files_properties(${metallib} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
     41       endfunction()
     42       generateMetallib(macos-metal2.0 air64-apple-macos10.13 default)
     43       generateMetallib(macos-metal2.2 air64-apple-macos10.15 Metal22)
     44       generateMetallib(macos-metal2.3 air64-apple-macos11.0  Metal23)
     45     endif()  
     46   endfunction()
     47 endif()