mirror of
https://github.com/dpogue/CMake-MetalShaderSupport.git
synced 2025-04-03 20:45:05 +00:00
Add MetalShaderSupport CMake helper
This commit is contained in:
parent
c5eb0fdf01
commit
6594c420e2
4 changed files with 49 additions and 18 deletions
|
@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 3.12)
|
|||
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
|
||||
include(CheckLanguage)
|
||||
include(MetalShaderSupport)
|
||||
|
||||
project(MetalTest)
|
||||
|
||||
|
|
41
cmake/MetalShaderSupport.cmake
Normal file
41
cmake/MetalShaderSupport.cmake
Normal file
|
@ -0,0 +1,41 @@
|
|||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENCE.txt or https://cmake.org/licensing for details.
|
||||
|
||||
function(add_metal_shader_library TARGET)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 _amsl
|
||||
""
|
||||
"" #TODO: support "STANDARD"
|
||||
""
|
||||
)
|
||||
|
||||
add_library(${TARGET} MODULE ${_amsl_UNPARSED_ARGUMENTS})
|
||||
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
XCODE_PRODUCT_TYPE com.apple.product-type.metal-library
|
||||
XCODE_ATTRIBUTE_MTL_FAST_MATH "YES"
|
||||
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE"
|
||||
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(target_embed_metal_shader_libraries TARGET)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 _temsl
|
||||
""
|
||||
""
|
||||
""
|
||||
)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.28 AND ${CMAKE_GENERATOR} STREQUAL "Xcode")
|
||||
set_target_properties(${TARGET} PROPERTIES
|
||||
XCODE_EMBED_RESOURCES ${_temsl_UNPARSED_ARGUMENTS}
|
||||
)
|
||||
else()
|
||||
foreach(SHADERLIB IN LISTS _temsl_UNPARSED_ARGUMENTS)
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
DEPENDS ${SHADERLIB}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${SHADERLIB}>" "$<TARGET_BUNDLE_CONTENT_DIR:${TARGET}>/Resources/$<TARGET_FILE_NAME:${SHADERLIB}>"
|
||||
VERBATIM
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
|
@ -23,7 +23,6 @@ set(ExampleApp_RESOURCES
|
|||
add_executable(ExampleApp MACOSX_BUNDLE
|
||||
${ExampleApp_SOURCES} ${ExampleApp_HEADERS} ${ExampleApp_RESOURCES}
|
||||
)
|
||||
add_dependencies(ExampleApp ShaderBase)
|
||||
|
||||
set_target_properties(ExampleApp PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist"
|
||||
|
@ -31,17 +30,15 @@ set_target_properties(ExampleApp PROPERTIES
|
|||
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ca.dpogue.metaltest.example
|
||||
)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.28 AND ${CMAKE_GENERATOR} STREQUAL "Xcode")
|
||||
target_embed_metal_shader_libraries(ExampleApp
|
||||
ShaderBase
|
||||
)
|
||||
|
||||
if(${CMAKE_GENERATOR} STREQUAL "Xcode")
|
||||
set_target_properties(ExampleApp PROPERTIES
|
||||
RESOURCE "${ExampleApp_RESOURCES}"
|
||||
XCODE_EMBED_RESOURCES ShaderBase
|
||||
RESOURCE ${ExampleApp_RESOURCES}
|
||||
)
|
||||
else()
|
||||
add_custom_command(TARGET ExampleApp POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:ShaderBase>" "$<TARGET_BUNDLE_CONTENT_DIR:ExampleApp>/Resources/$<TARGET_FILE_NAME:ShaderBase>"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
|
||||
add_custom_command(TARGET ExampleApp POST_BUILD
|
||||
COMMAND ${IBTOOL} --output-format human-readable-text --compile "$<TARGET_BUNDLE_CONTENT_DIR:ExampleApp>/Resources/Main.storyboardc" "${CMAKE_CURRENT_SOURCE_DIR}/Main.storyboard"
|
||||
|
|
|
@ -9,15 +9,7 @@ set(ShaderBase_SOURCES
|
|||
AAPLShaders.metal
|
||||
)
|
||||
|
||||
add_library(ShaderBase MODULE
|
||||
add_metal_shader_library(ShaderBase
|
||||
${ShaderBase_SOURCES}
|
||||
${ShaderBase_HEADERS}
|
||||
)
|
||||
|
||||
set_target_properties(ShaderBase PROPERTIES
|
||||
XCODE_PRODUCT_TYPE com.apple.product-type.metal-library
|
||||
#XCODE_ATTRIBUTE_MTL_LANGUAGE_REVISION Metal21
|
||||
XCODE_ATTRIBUTE_MTL_FAST_MATH "YES"
|
||||
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE"
|
||||
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue