-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow building macOS client with Makefiles
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.
- Loading branch information
Showing
9 changed files
with
358 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
# file LICENCE.txt or https://cmake.org/licensing for details. | ||
|
||
# CMakeDetermine(LANG)Compiler.cmake -> this should find the compiler for LANG and configure CMake(LANG)Compiler.cmake.in | ||
|
||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) | ||
|
||
if(NOT CMAKE_Metal_COMPILER_NAMES) | ||
set(CMAKE_Metal_COMPILER_NAMES metal) | ||
endif() | ||
|
||
if("${CMAKE_GENERATOR}" STREQUAL "Xcode") | ||
set(CMAKE_Metal_COMPILER_XCODE_TYPE sourcecode.metal) | ||
|
||
execute_process(COMMAND xcrun --find metal | ||
OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_VARIABLE _xcrun_err RESULT_VARIABLE _xcrun_result) | ||
if(_xcrun_result EQUAL 0 AND EXISTS "${_xcrun_out}") | ||
set(CMAKE_Metal_COMPILER "${_xcrun_out}") | ||
else() | ||
_cmake_find_compiler_path(Metal) | ||
endif() | ||
else() | ||
if(CMAKE_Metal_COMPILER) | ||
_cmake_find_compiler_path(Metal) | ||
else() | ||
set(CMAKE_Metal_COMPILER_INIT NOTFOUND) | ||
|
||
if(NOT $ENV{METALC} STREQUAL "") | ||
get_filename_component(CMAKE_Metal_COMPILER_INIT $ENV{METALC} PROGRAM PROGRAM_ARGS CMAKE_Metal_FLAGS_ENV_INIT) | ||
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}) | ||
message(FATAL_ERROR "Could not find compiler set in environment variable METALC\n$ENV{METALC}.\n${CMAKE_Metal_COMPILER_INIT}") | ||
endif() | ||
endif() | ||
|
||
if(NOT CMAKE_Metal_COMPILER_INIT) | ||
set(CMAKE_Metal_COMPILER_LIST metal ${_CMAKE_TOOLCHAIN_PREFIX}metal) | ||
endif() | ||
|
||
_cmake_find_compiler(Metal) | ||
endif() | ||
|
||
mark_as_advanced(CMAKE_Metal_COMPILER) | ||
endif() | ||
|
||
# For Metal we need to explicitly query the version. | ||
if(CMAKE_Metal_COMPILER AND NOT CMAKE_Metal_COMPILER_VERSION) | ||
execute_process( | ||
COMMAND "${CMAKE_Metal_COMPILER}" --version | ||
OUTPUT_VARIABLE output ERROR_VARIABLE output | ||
RESULT_VARIABLE result | ||
TIMEOUT 10 | ||
) | ||
message(CONFIGURE_LOG | ||
"Running the Metal compiler: \"${CMAKE_Metal_COMPILER}\" --version\n" | ||
"${output}\n" | ||
) | ||
|
||
if(output MATCHES [[metal version ([0-9]+\.[0-9]+(\.[0-9]+)?)]]) | ||
set(CMAKE_Metal_COMPILER_VERSION "${CMAKE_MATCH_1}") | ||
if(NOT CMAKE_Metal_COMPILER_ID) | ||
set(CMAKE_Metal_COMPILER_ID "Apple") | ||
endif() | ||
endif() | ||
endif() | ||
|
||
if (NOT _CMAKE_TOOLCHAIN_LOCATION) | ||
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Metal_COMPILER}" PATH) | ||
endif () | ||
|
||
set(_CMAKE_PROCESSING_LANGUAGE "Metal") | ||
include(CMakeFindBinUtils) | ||
unset(_CMAKE_PROCESSING_LANGUAGE) | ||
|
||
configure_file( | ||
${CMAKE_CURRENT_LIST_DIR}/CMakeMetalCompiler.cmake.in | ||
${CMAKE_PLATFORM_INFO_DIR}/CMakeMetalCompiler.cmake | ||
) | ||
|
||
set(CMAKE_Metal_COMPILER_ENV_VAR "METALC") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
# file LICENCE.txt or https://cmake.org/licensing for details. | ||
|
||
# CMake(LANG)Compiler.cmake.in -> used by CMakeDetermine(LANG)Compiler.cmake | ||
# This file is used to store compiler information and is copied down into try | ||
# compile directories so that try compiles do not need to re-determine and test | ||
# the LANG | ||
|
||
set(CMAKE_Metal_COMPILER "@CMAKE_Metal_COMPILER@") | ||
set(CMAKE_Metal_COMPILER_ID "@CMAKE_Metal_COMPILER_ID@") | ||
set(CMAKE_Metal_COMPILER_VERSION "@CMAKE_Metal_COMPILER_VERSION@") | ||
|
||
set(CMAKE_Metal_COMPILER_LOADED 1) | ||
set(CMAKE_Metal_COMPILER_WORKS "@CMAKE_Metal_COMPILER_WORKS@") | ||
|
||
set(CMAKE_Metal_COMPILER_ENV_VAR "METALC") | ||
|
||
set(CMAKE_Metal_COMPILER_ID_RUN "@CMAKE_Metal_COMPILER_ID_RUN@") | ||
set(CMAKE_Metal_SOURCE_FILE_EXTENSIONS metal) | ||
set(CMAKE_Metal_OUTPUT_EXTENSION ".air") | ||
set(CMAKE_STATIC_LIBRARY_PREFIX_Metal "") | ||
set(CMAKE_STATIC_LIBRARY_SUFFIX_Metal ".metal-ar") | ||
set(CMAKE_SHARED_LIBRARY_PREFIX_Metal "") | ||
set(CMAKE_SHARED_LIBRARY_SUFFIX_Metal ".metallib") | ||
set(CMAKE_SHARED_MODULE_PREFIX_Metal "") | ||
set(CMAKE_SHARED_MODULE_SUFFIX_Metal ".metallib") | ||
set(CMAKE_EXECUTABLE_SUFFIX_Metal ".metallib") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying | ||
# file LICENCE.txt or https://cmake.org/licensing for details. | ||
|
||
# CMake(LANG)Information.cmake -> set up rule variables for LANG : | ||
# CMAKE_(LANG)_CREATE_SHARED_LIBRARY | ||
# CMAKE_(LANG)_CREATE_SHARED_MODULE | ||
# CMAKE_(LANG)_CREATE_STATIC_LIBRARY | ||
# CMAKE_(LANG)_COMPILE_OBJECT | ||
# CMAKE_(LANG)_LINK_EXECUTABLE | ||
|
||
include (CMakeCommonLanguageInclude) | ||
|
||
set(CMAKE_Metal_FLAGS_INIT "-ffast-math") | ||
set(CMAKE_Metal_FLAGS_DEBUG_INIT "-gline-tables-only -frecord-sources") | ||
set(CMAKE_Metal_FLAGS_RELWITHDEBINFO_INIT "-gline-tables-only -frecord-sources") | ||
|
||
cmake_initialize_per_config_variable(CMAKE_Metal_FLAGS "Flags used by the Metal compiler") | ||
|
||
set(CMAKE_INCLUDE_FLAG_Metal "-I ") | ||
set(CMAKE_Metal_COMPILER_ARG1 "") | ||
set(CMAKE_Metal_DEFINE_FLAG -D) | ||
set(CMAKE_Metal_FRAMEWORK_SEARCH_FLAG "-F ") | ||
set(CMAKE_Metal_LIBRARY_PATH_FLAG "-L ") | ||
set(CMAKE_Metal_SYSROOT_FLAG "-isysroot") | ||
set(CMAKE_Metal_COMPILE_OPTIONS_TARGET "-target ") | ||
set(CMAKE_DEPFILE_FLAGS_Metal "-MMD -MT dependencies -MF <DEP_FILE>") | ||
|
||
if(CMAKE_GENERATOR MATCHES "Makefiles") | ||
set(CMAKE_Metal_DEPFILE_FORMAT gcc) | ||
set(CMAKE_Metal_DEPENDS_USE_COMPILER TRUE) | ||
endif() | ||
|
||
set(CMAKE_Metal_COMPILER_PREDEFINES_COMMAND "${CMAKE_Metal_COMPILER}") | ||
if(CMAKE_Metal_COMPILER_TARGET) | ||
list(APPEND CMAKE_Metal_COMPILER_PREDEFINES_COMMAND "-target" "${CMAKE_Metal_COMPILER_TARGET}") | ||
endif() | ||
|
||
# now define the following rule variables | ||
|
||
# CMAKE_Metal_CREATE_SHARED_LIBRARY | ||
# CMAKE_Metal_CREATE_SHARED_MODULE | ||
# CMAKE_Metal_COMPILE_OBJECT | ||
# CMAKE_Metal_LINK_EXECUTABLE | ||
|
||
# variables supplied by the generator at use time | ||
# <TARGET> | ||
# <TARGET_BASE> the target without the suffix | ||
# <OBJECTS> | ||
# <OBJECT> | ||
# <LINK_LIBRARIES> | ||
# <FLAGS> | ||
# <LINK_FLAGS> | ||
|
||
# Metal compiler information | ||
# <CMAKE_Metal_COMPILER> | ||
# <CMAKE_SHARED_LIBRARY_CREATE_Metal_FLAGS> | ||
# <CMAKE_SHARED_MODULE_CREATE_Metal_FLAGS> | ||
# <CMAKE_Metal_LINK_FLAGS> | ||
|
||
if(NOT CMAKE_Metal_COMPILE_OBJECT) | ||
set(CMAKE_Metal_COMPILE_OBJECT | ||
"<CMAKE_Metal_COMPILER> -c <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>") | ||
endif() | ||
|
||
if(NOT CMAKE_Metal_CREATE_SHARED_LIBRARY) | ||
set(CMAKE_Metal_CREATE_SHARED_LIBRARY "<CMAKE_Metal_COMPILER> <CMAKE_SHARED_LIBRARY_Metal_FLAGS> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Metal_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>") | ||
endif() | ||
|
||
if(NOT CMAKE_Metal_CREATE_SHARED_MODULE) | ||
set(CMAKE_Metal_CREATE_SHARED_MODULE "${CMAKE_Metal_CREATE_SHARED_LIBRARY}") | ||
endif() | ||
|
||
if(NOT CMAKE_Metal_LINK_EXECUTABLE) | ||
# Metal shaders don't really have "executables", but we need this for the try_compile to work properly, so we'll just have it output a metallib file | ||
set(CMAKE_Metal_LINK_EXECUTABLE "<CMAKE_Metal_COMPILER> <FLAGS> <CMAKE_Metal_LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>") | ||
endif() | ||
|
||
set(CMAKE_Metal_INFORMATION_LOADED 1) |
Oops, something went wrong.