https://github.com/zmactep/cmake-metal-example
Minimal example of C++ Metal project built with CMake
https://github.com/zmactep/cmake-metal-example
Last synced: about 1 year ago
JSON representation
Minimal example of C++ Metal project built with CMake
- Host: GitHub
- URL: https://github.com/zmactep/cmake-metal-example
- Owner: zmactep
- Created: 2022-01-28T17:56:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-28T18:53:43.000Z (over 4 years ago)
- Last Synced: 2025-02-09T19:53:49.296Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
CMake Metal Minimal Example
===========================
What is it?
-----------
Recently, Apple announced [C++ interface](https://developer.apple.com/metal/cpp/) for its Metal Framework to use it without Swift or Objective-C. That is great, as many different bindings for high-level programming languages can be created now.
Of course, Apple has a manual on working with these headers in XCode. But if you hate this IDE as I do, you would like to use CMake to build your project without it. So here we have a minimal example of how to build a Metal-based project using CLI.
Build
-----
All the magic is stored in `compile.sh` file. But let us understand it.
```bash
curl -o metal-cpp.zip https://developer.apple.com/metal/cpp/files/metal-cpp_macOS12_iOS15.zip
unzip metal-cpp.zip
```
Download and unzip headers from Apple Developer. All the staff will be in `metal-cpp` directory.
```bash
mkdir build
cd build
cmake ..
```
Standard CMake operations to create a Makefile. CMake will use `metal-cpp` as additional headers path, so `Metal/Metal.hpp` will be available.
```bash
xcrun -sdk macosx metal -c ../src/kernel.metal -o kernel.air
xcrun -sdk macosx metallib kernel.air -o kernel.metallib
```
CMake cannot build Metal shaders by itself, so we have to do this work by ourselfs. The explanation of this lines can be found [here](https://developer.apple.com/documentation/metal/libraries/building_a_library_with_metal_s_command-line_tools).
```bash
make
```
Nothing to comment. Just build the executable.