Add support for specifying Metal language version

This commit is contained in:
Darryl Pogue 2024-06-02 14:10:16 -07:00
parent 56e8d08ddc
commit 96b889da02
No known key found for this signature in database
GPG key ID: CB824715C3E6FD41
3 changed files with 32 additions and 2 deletions

View file

@ -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
)
```
<details>
<summary><h3>Implementation Details</h3></summary>
@ -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"
)
```
</details>
@ -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

View file

@ -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)

View file

@ -10,6 +10,7 @@ set(ShaderBase_SOURCES
)
add_metal_shader_library(ShaderBase
STANDARD macos-metal2.1
${ShaderBase_SOURCES}
${ShaderBase_HEADERS}
)