I’ve got a simple program in one file (main.cc) that uses a Metal shader. I tried this CMakeLists.txt
below, but when I edit the source file (Shaders.metal), it doesn’t rebuild.
I’m trying to tell it to rebuild the Shaders.metallib
from Shaders.metal
, when the latter changes. And I want to tell it that Shaders.metallib
should be built when building the executable.
How do I do this?
The are two commands. One to build the .air file from .metal, the second to build .metallib from .air.
set(TARG myui_samples_bare_metal_tri)
add_executable(${TARG} MACOSX_BUNDLE main.cc Shaders.metallib)
set_target_properties(${TARG} PROPERTIES OUTPUT_NAME bare_metal_tri)
target_link_libraries(${TARG}
PRIVATE MyUI ${APPKIT_LIB} ${METAL_LIB})
add_custom_command(OUTPUT Shaders.air
MAIN_DEPENDENCY Shaders.metal
COMMAND xcrun -sdk macosx metal -c Shaders.metal -o Shaders.air)
add_custom_command(OUTPUT Shaders.metallib
MAIN_DEPENDENCY Shaders.air
COMMAND xcrun -sdk macosx metallib Shaders.air -o Shaders.metallib)