diff --git a/README.md b/README.md index 8ba91b1..153f41f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,16 @@ add_metal_shader_library(MyShaders ) ``` +You can specify a Metal language version with the `STANDARD` attribute: + +```cmake +add_metal_shader_library(MyShaders + STANDARD macos-metal2.3 + shader1.metal + shader2.metal +) +``` +

Implementation Details

@@ -74,6 +84,15 @@ set_target_properties(MyShaders PROPERTIES XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE" XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE" ) + +# If a target language version is provided: +target_compile_options(MyShaders + PRIVATE "-std=macos-metal2.3" +) + +set_target_properties(MyShaders PROPERTIES + XCODE_ATTRIBUTE_MTL_LANGUAGE_REVISION "Metal23" +) ```
@@ -121,7 +140,7 @@ add_custom_command(TARGET MyApp POST_BUILD Remaining Work -------------- -* Handling the target and SDK parameters +* Handling the SDK and min-version parameters * Testing that this works with the Windows version of the Metal tools diff --git a/cmake/MetalShaderSupport.cmake b/cmake/MetalShaderSupport.cmake index 7d7bb1a..9cace56 100644 --- a/cmake/MetalShaderSupport.cmake +++ b/cmake/MetalShaderSupport.cmake @@ -4,7 +4,7 @@ function(add_metal_shader_library TARGET) cmake_parse_arguments(PARSE_ARGV 1 _amsl "" - "" #TODO: support "STANDARD" + "STANDARD" "" ) @@ -16,6 +16,16 @@ function(add_metal_shader_library TARGET) XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE" XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE" ) + + if(_amsl_STANDARD AND _amsl_STANDARD MATCHES "metal([0-9]+)\.([0-9]+)") + target_compile_options(${TARGET} + PRIVATE "-std=${_amsl_STANDARD}" + ) + + set_target_properties(${TARGET} PROPERTIES + XCODE_ATTRIBUTE_MTL_LANGUAGE_REVISION "Metal${CMAKE_MATCH_1}${CMAKE_MATCH_2}" + ) + endif() endfunction() function(target_embed_metal_shader_libraries TARGET) diff --git a/example/ShaderBase/CMakeLists.txt b/example/ShaderBase/CMakeLists.txt index 4337f43..363d346 100644 --- a/example/ShaderBase/CMakeLists.txt +++ b/example/ShaderBase/CMakeLists.txt @@ -10,6 +10,7 @@ set(ShaderBase_SOURCES ) add_metal_shader_library(ShaderBase + STANDARD macos-metal2.1 ${ShaderBase_SOURCES} ${ShaderBase_HEADERS} )