Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to compile *.metal files to generate *.metalib and improve xcode.application rule #1597

Closed
waruqi opened this issue Aug 22, 2021 · 0 comments

Comments

@waruqi
Copy link
Member

waruqi commented Aug 22, 2021

Add xcode.metal rule

We can use add_rules("code.metal") rule to compile *.metal files and generate xxx.metallib in target directory

target("test")
    add_rules("xcode.metal")
    add_files("src/*.metal")
    add_files("src/*.m")
    add_frameworks("MetalKit")

Improve xcode.application rule

this rule also contain xcode.metal rule automatically.

We can also build *.metal files to add it as default.metallib when we build macOS/iOS application.

so we can use default metal library in application.

example project: https://github.com/xmake-io/xmake/blob/dev/tests/projects/objc/metal_app/xmake.lua

add_rules("mode.debug", "mode.release")

target("HelloTriangle")
    add_rules("xcode.application")
    add_includedirs("Renderer")
    add_frameworks("MetalKit")
    add_mflags("-fmodules")
    add_files("Renderer/*.m", "Renderer/*.metal")
    if is_plat("macosx") then
        add_files("Application/main.m")
        add_files("Application/AAPLViewController.m")
        add_files("Application/macOS/Info.plist")
        add_files("Application/macOS/Base.lproj/*.storyboard")
        add_defines("TARGET_MACOS")
        add_frameworks("AppKit")
    elseif is_plat("iphoneos") then
        add_files("Application/*.m")
        add_files("Application/iOS/Info.plist")
        add_files("Application/iOS/Base.lproj/*.storyboard")
        add_frameworks("UIKit")
        add_defines("TARGET_IOS")
    end
$ xmake
[  9%]: compiling.xcode.release Application/iOS/Base.lproj/LaunchScreen.storyboard
[  9%]: compiling.xcode.release Application/iOS/Base.lproj/Main.storyboard
[  9%]: processing.xcode.release Application/iOS/Info.plist
[ 18%]: ccache compiling.release Renderer/AAPLRenderer.m
[ 18%]: ccache compiling.release Application/AAPLViewController.m
[ 18%]: ccache compiling.release Application/AAPLAppDelegate.m
[ 18%]: ccache compiling.release Application/main.m
[ 18%]: compiling.metal Renderer/AAPLShaders.metal
[ 81%]: linking.metal default.metallib
[ 81%]: linking.release HelloTriangle
[ 90%]: generating.xcode.release HelloTriangle.app
[100%]: build ok!
$ xmake run

Snip20210822_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant