I’m a contributor to an open-source game engine with a CMake build system, that recently merged some code to use Apple’s metal-cpp library as an alternative rendering engine. As such, the project now contains Metal shaders that need to be compiled and linked on Apple platforms.
It was possible to use CMake to add the Metal shaders to the Xcode projects and build them that way, it bothered me that despite Metal command-line tools being available there was no way for CMake to support Metal shaders with Makefile, Ninja, or any generators besides Xcode.
Hence, I set out to teach CMake how to compile and link Metal shaders as a new language option, and it turns out that it only requires a few CMake module files that can easily be copied into any project! The full details of how this was accomplished and tested are written up in a post on my website.
Announcing CMake Metal Shader Support!
GitHub - dpogue/CMake-MetalShaderSupport has the module files, some boilerplate helpers, an example project, and instructions for using it in your own projects.
It has mostly been tested on macOS with Xcode, Ninja, and Makefile generators; but the Ninja generator also worked on Windows with Apple’s Metal Developer Tools installed and added to the path. Please report any bugs, issues, or feature requests on the GitHub repo.