# Example code for Metal shaders?

**URL:** https://discourse.cmake.org/t/example-code-for-metal-shaders/6404
**Category:** Usage
**Created:** [September 4, 2022, 2:43pm UTC](https://discourse.cmake.org/t/example-code-for-metal-shaders/6404 "2022-09-04T14:43:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![RobN](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/e9bcb4/32.png) [@RobN](https://discourse.cmake.org/u/RobN)
#### Post date: [September 4, 2022, 2:43pm UTC](https://discourse.cmake.org/t/example-code-for-metal-shaders/6404/1 "2022-09-04T14:43:11Z")

</div>

I’m trying to move an Xcode project to CLion and CMake. I’ve got the C/C++ part working, but my build is doing nothing with the Metal shader files.

I found this: [metal - Building metallib with CMake - Stack Overflow](https://stackoverflow.com/questions/52008408/building-metallib-with-cmake)

I will try to follow that and do something with `add_custom_command` and `add_custom_target`.

I’m a beginner with CMake so it may take me a while. If anyone has experience with this or knows where to find some example code, I’d appreciate the pointers.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [September 4, 2022, 3:28pm UTC](https://discourse.cmake.org/t/example-code-for-metal-shaders/6404/2 "2022-09-04T15:28:41Z")

</div>

Here are some repos using CMake to compile Vulkan shaders. Hopefully they are useful as a reference to you.

- [GitHub - Ravbug/RavEngine: A fast, easy to use C++20 3D game library for modern computers](https://github.com/Ravbug/RavEngine)
- [GitHub - liliolett/cmake-spirv: Small CMake module for glslc integration](https://github.com/liliolett/cmake-spirv)
- [GitHub - ZOulhadj/vulkan\_starter: A basic triangle example program using Vulkan.](https://github.com/ZOulhadj/vulkan_starter)

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [November 29, 2023, 11:57pm UTC](https://discourse.cmake.org/t/example-code-for-metal-shaders/6404/3 "2023-11-29T23:57:17Z")

</div>

Ended up finding a CMake project that uses C++ and Metal:

> **[GitHub - LeeTeng2001/metal-cpp-cmake: Metal graphic api ported to C++ with...](https://github.com/LeeTeng2001/metal-cpp-cmake)**
>
> Metal graphic api ported to C++ with CMake build system - GitHub - LeeTeng2001/metal-cpp-cmake: Metal graphic api ported to C++ with CMake build system

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [June 11, 2024, 3:27pm UTC](https://discourse.cmake.org/t/example-code-for-metal-shaders/6404/4 "2024-06-11T15:27:21Z")

</div>

# [CMake modules to support Apple Metal shaders](https://discourse.cmake.org/t/cmake-modules-to-support-apple-metal-shaders/10991)
