Skip to content

arauzca/cmake-metal-cpp

Repository files navigation

cmake-metal-cpp

About

metal-cpp is a low-overhead, header-only C++ interface for Metal that helps developers add Metal functionality to graphics applications written in C++ (such as game engines). metal-cpp eliminates the need to create a shim, allowing developers to call Metal functions directly from their existing C++ code.

cmake-metal-cpp integrates metal-cpp with projects using CMake. The project can be configured to provide the Metal-cpp headers or automatically create a single header file using the script provided by Apple.

How to Build

  1. Clone this project into your source directory or add it as a submodule.

  2. In your CMakeLists.txt file, add:

    add_subdirectory(cmake-metal-cpp)
  3. Add the compile definitions and link the library provided by cmake-metal-cpp. For instance, if you have an executable my-target:

    target_link_libraries(my-target metal-cpp)

Options

This project provides two options for header creation: individual headers or a single header file. The AppKit and MetalKit extensions are enabled by default but can be excluded.

  • MAKE_METAL_SINGLE_HEADER: Use metal-cpp as a single-header include in your project. Default: OFF.
  • INCLUDE_APPKIT_EXTENSION: Include the AppKit extension from metal-cpp-extensions. Default: ON.
  • INCLUDE_METALKIT_EXTENSION: Include the MetalKit extension from metal-cpp-extensions. Default: ON.
  • ENABLE_BETA: For beta developers targeting macOS 13. Default: OFF.

How to Use the Headers

In your source code, add the headers (or header, if using the single header option) and start coding.

  • Individual headers:

    #include <Metal/Metal.hpp>
    #include <AppKit/AppKit.hpp>
    #include <MetalKit/MetalKit.hpp>
  • Single header file:

    #include <Metal.hpp>

Credits

  • CMake Logo: Created by the CMake team. Original uploader was Francesco Betti Sorbelli on Italian Wikipedia. Vectorized by Magasjukur2 CC BY 2.0.

  • metal-cpp: Copyright 2020-2023 Apple Inc.

  • metal-cpp-beta: Copyright 2020-2024 Apple Inc.

  • metal-cpp-extensions: Copyright 2020-2021 Apple Inc.

Disclaimer

I do not own any of the metal-cpp works. However, the single header file generated by the script provided by Apple may be slightly different because I use a script to remove unnecessary imports from the AppKit and MetalKit header extensions.

About

Metal-cpp with CMake

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages