Match Xcode flags more closely

This commit is contained in:
Darryl Pogue 2024-06-01 23:53:20 -07:00
parent 9c7adfe297
commit 7b7efe65ce
No known key found for this signature in database
GPG key ID: CB824715C3E6FD41
4 changed files with 29 additions and 36 deletions

View file

@ -20,24 +20,6 @@ if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
else()
_cmake_find_compiler_path(Metal)
endif()
execute_process(COMMAND xcrun --find metallib
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_LINKER "${_xcrun_out}")
else()
set(CMAKE_Metal_COMPILER_LINKER "${CMAKE_Metal_COMPILER}lib")
endif()
execute_process(COMMAND xcrun --find metal-ar
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_AR "${_xcrun_out}")
else()
set(CMAKE_Metal_COMPILER_AR "${CMAKE_Metal_COMPILER}-ar")
endif()
else()
if(CMAKE_Metal_COMPILER)
_cmake_find_compiler_path(Metal)
@ -61,10 +43,7 @@ else()
_cmake_find_compiler(Metal)
endif()
set(CMAKE_Metal_COMPILER_LINKER "${CMAKE_Metal_COMPILER}lib")
set(CMAKE_Metal_COMPILER_AR "${CMAKE_Metal_COMPILER}-ar")
mark_as_advanced(CMAKE_Metal_COMPILER CMAKE_Metal_COMPILER_LINKER CMAKE_Metal_COMPILER_AR)
mark_as_advanced(CMAKE_Metal_COMPILER)
endif()
# For Metal we need to explicitly query the version.

View file

@ -9,8 +9,6 @@
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_LINKER "@CMAKE_Metal_COMPILER_LINKER@")
set(CMAKE_Metal_COMPILER_AR "@CMAKE_Metal_COMPILER_AR@")
set(CMAKE_Metal_COMPILER_LOADED 1)
set(CMAKE_Metal_COMPILER_WORKS "@CMAKE_Metal_COMPILER_WORKS@")

View file

@ -10,8 +10,30 @@
include (CMakeCommonLanguageInclude)
set(CMAKE_INCLUDE_FLAG_Metal "-I ")
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
@ -37,15 +59,11 @@ set(CMAKE_INCLUDE_FLAG_Metal "-I ")
if(NOT CMAKE_Metal_COMPILE_OBJECT)
set(CMAKE_Metal_COMPILE_OBJECT
"<CMAKE_Metal_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -c -o <OBJECT> <SOURCE>")
endif()
if(NOT CMAKE_Metal_CREATE_STATIC_LIBRARY)
set(CMAKE_Metal_CREATE_STATIC_LIBRARY "${CMAKE_Metal_COMPILER_AR} crs <TARGET> <OBJECTS>")
"<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_LINKER} <CMAKE_SHARED_LIBRARY_Metal_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_Metal_CREATE_SHARED_LIBRARY "<CMAKE_Metal_COMPILER> <CMAKE_SHARED_LIBRARY_Metal_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Metal_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()
if(NOT CMAKE_Metal_CREATE_SHARED_MODULE)
@ -53,8 +71,8 @@ if(NOT CMAKE_Metal_CREATE_SHARED_MODULE)
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 (identical to the "shared library" configuration)
set(CMAKE_Metal_LINK_EXECUTABLE "${CMAKE_Metal_CREATE_SHARED_LIBRARY}")
# 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> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()
set(CMAKE_Metal_INFORMATION_LOADED 1)

View file

@ -16,9 +16,7 @@ add_library(ShaderBase MODULE
set_target_properties(ShaderBase PROPERTIES
XCODE_PRODUCT_TYPE com.apple.product-type.metal-library
XCODE_ATTRIBUTE_MTL_LANGUAGE_REVISION Metal21
SUFFIX ".metallib"
PREFIX ""
#XCODE_ATTRIBUTE_MTL_LANGUAGE_REVISION Metal21
XCODE_ATTRIBUTE_MTL_FAST_MATH "YES"
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=Debug] "INCLUDE_SOURCE"
XCODE_ATTRIBUTE_MTL_ENABLE_DEBUG_INFO[variant=RelWithDebInfo] "INCLUDE_SOURCE"