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

Allow building macOS client with Makefiles/Ninja #1611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpogue
Copy link
Member

@dpogue dpogue commented Aug 6, 2024

This removes the strict requirement to use the Xcode project generator, but still requires the Xcode build tools (and specifically the Metal compiler) to be installed. With these changes, I was able to build and launch plClient.app locally with a Makefile build, and it rendered as expected (so I'm assuming the Metal shaders are working).

I expect that our official stance will always be that the Xcode project generator is the recommended and supported way to do macOS builds, but any day I don't have to launch Xcode is a good day.

Note: the new CMake files came from https://github.com/dpogue/CMake-MetalShaderSupport

@dpogue dpogue force-pushed the cmake-metal branch 3 times, most recently from ec7390f to 72e3295 Compare August 6, 2024 08:44
Copy link
Member

@Hoikas Hoikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense and looks good to me, just some formatting nitpicks.

CMakeLists.txt Show resolved Hide resolved

execute_process(COMMAND xcrun --find metal
OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE _xcrun_err RESULT_VARIABLE _xcrun_result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for the closing ) to be on a newline.

if(CMAKE_Metal_FLAGS_ENV_INIT)
set(CMAKE_Metal_COMPILER_ARG1 "${CMAKE_Metal_FLAGS_ENV_INIT}" CACHE STRING "Arguments to the Metal compiler")
endif()
if(NOT EXISTS ${CMAKE_Metal_COMPILER_INIT})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if ${CMAKE_Metal_COMPILER_INIT} should be quoted?

# CMAKE_(LANG)_COMPILE_OBJECT
# CMAKE_(LANG)_LINK_EXECUTABLE

include (CMakeCommonLanguageInclude)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include (CMakeCommonLanguageInclude)
include(CMakeCommonLanguageInclude)


if(NOT CMAKE_Metal_COMPILE_OBJECT)
set(CMAKE_Metal_COMPILE_OBJECT
"<CMAKE_Metal_COMPILER> -c <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for the closing ) to be on a newline.

return()
endif()

include (CMakeTestCompilerCommon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include (CMakeTestCompilerCommon)
include(CMakeTestCompilerCommon)

"# error \"The CMAKE_Metal_COMPILER is not a Metal compiler\"\n"
"#endif\n"
"#import <metal_stdlib>\n"
"using namespace metal;\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for the closing ) to be on a newline.

# Puts test result in cache variable.
try_compile(CMAKE_Metal_COMPILER_WORKS
SOURCE_FROM_VAR testMetalCompiler.metal __TestCompiler_testMetalCompilerSource
OUTPUT_VARIABLE __CMAKE_Metal_COMPILER_OUTPUT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for the closing ) to be on a newline.

message(FATAL_ERROR "The Metal compiler\n \"${CMAKE_Metal_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
"with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for the closing ) to be on a newline.

@dpogue
Copy link
Member Author

dpogue commented Aug 7, 2024

@Hoikas The 5 new CMake files are from my https://github.com/dpogue/CMake-MetalShaderSupport project, and are based on files used internally by CMake for language detection/support (and the inconsistent formatting that CMake uses internally).

If we feel strongly about the code style here, I can update them, but I'd like to also make those changes in my "upstream" repo to keep things consistent for updating/diffing.

I didn't see a good way to bring these over without just copying them, and I don't think it's worth the hassle of another git submodule for them.

This removes the strict requirement to use the Xcode project generator,
but still requires the Xcode build tools (and specifically the Metal
compiler) to be installed.

I expect that our official stance will always be that the Xcode project
generator is the recommended and supported way to do macOS builds, but
any day I don't have to launch Xcode is a good day.
@colincornaby
Copy link
Contributor

I pulled this down, checked the Xcode output, and built. Looks good to me.

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

Successfully merging this pull request may close these issues.

3 participants