Skip to content

Commit

Permalink
(#4634) add moltenvk/1.1.1
Browse files Browse the repository at this point in the history
* add moltenvk/1.1.1

* fix executable name

* add bin to PATH env var

* improve frameworks handling

* disable several warnings

* raise if apple-clang < 11

* add tools option

* add with_spirv_tools option

* define DEBUG macro if Debug config

* MoltenVK 1.1.1 requires XCode 12+ at build time

On the other hand, MoltenVK can be consumed by older versions of XCode

* more specific compile options

* improve genericity of build across versions

* try to define compatible packages

* raise in validate() instead of build()

* inject commit hash of spirv-cross

* fix description

* spirv-cross compatibility documentation

* change message when moltenvk < 1.1.0

* fix typo in comment

* get commit hash in CMakeLists

* raise if not apple-clang
  • Loading branch information
SpaceIm authored Feb 24, 2021
1 parent 302da2b commit a255e1f
Show file tree
Hide file tree
Showing 8 changed files with 552 additions and 0 deletions.
265 changes: 265 additions & 0 deletions recipes/moltenvk/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
cmake_minimum_required(VERSION 3.12)
project(MoltenVK)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
CMAKE_SYSTEM_NAME STREQUAL "iOS" OR
CMAKE_SYSTEM_NAME STREQUAL "tvOS"))
message(FATAL_ERROR "MoltenVK only supports MacOS, iOS and tvOS")
endif()

option(MVK_WITH_SPIRV_TOOLS "Build MoltenVK without the MVK_EXCLUDE_SPIRV_TOOLS build setting" ON)
option(MVK_BUILD_SHADERCONVERTER_TOOL "Build MoltenVKShaderConverter" ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# PIC required for objects targets linked into shared MoltenVK
if(BUILD_SHARED_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# Required Apple Frameworks
find_library(METAL_FRAMEWORK Metal)
if(NOT METAL_FRAMEWORK)
message(FATAL_ERROR "Metal framework not found")
endif()
find_library(FOUNDATION_FRAMEWORK Foundation)
if(NOT FOUNDATION_FRAMEWORK)
message(FATAL_ERROR "Foundation framework not found")
endif()
find_library(QUARTZ_CORE_FRAMEWORK QuartzCore)
if(NOT QUARTZ_CORE_FRAMEWORK)
message(FATAL_ERROR "QuartzCore framework not found")
endif()
find_library(APPKIT_FRAMEWORK AppKit)
if(NOT APPKIT_FRAMEWORK)
message(FATAL_ERROR "AppKit framework not found")
endif()
find_library(IOSURFACE_FRAMEWORK IOSurface)
if(NOT IOSURFACE_FRAMEWORK)
message(FATAL_ERROR "IOSurface framework not found")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library(IO_OR_UI_KIT_FRAMEWORK IOKit)
if(NOT IO_OR_UI_KIT_FRAMEWORK)
message(FATAL_ERROR "IOKit framework not found")
endif()
else()
find_library(IO_OR_UI_KIT_FRAMEWORK UIKit)
if(NOT IO_OR_UI_KIT_FRAMEWORK)
message(FATAL_ERROR "UIKit framework not found")
endif()
endif()

set(MVK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder)
set(MVK_INSTALL_TARGETS "")

# MoltenVKCommon
# * direct dependencies:
# - external: None
# - internal: None
# - frameworks: Foundation
file(GLOB MVK_COMMON_SOURCES ${MVK_DIR}/common/*.mm)
add_library(MoltenVKCommon OBJECT ${MVK_COMMON_SOURCES})
target_include_directories(MoltenVKCommon PUBLIC ${MVK_DIR}/common)
target_compile_definitions(MoltenVKCommon PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
target_link_libraries(MoltenVKCommon PRIVATE ${FOUNDATION_FRAMEWORK})

# MoltenVKShaderConverter
# * direct dependencies:
# - external: spirv-cross, glslang, and spirv-tools (optional)
# - internal: MoltenVKCommon
# - frameworks: Foundation
file(GLOB MVK_SC_COMMON_SOURCES ${MVK_DIR}/MoltenVKShaderConverter/common/*.cpp)
if(MVK_VERSION VERSION_LESS "1.1.0")
file(GLOB MVK_SC_CONVERTERS_SOURCES
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/*.cpp
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/*.mm
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/*.cpp
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/*.mm
)
else()
file(GLOB MVK_SC_CONVERTERS_SOURCES
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverter/*.cpp
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverter/*.mm
)
endif()
add_library(MoltenVKShaderConverter OBJECT ${MVK_SC_COMMON_SOURCES} ${MVK_SC_CONVERTERS_SOURCES})
target_include_directories(MoltenVKShaderConverter
PRIVATE ${MVK_DIR}/MoltenVKShaderConverter/common
INTERFACE ${MVK_DIR}/MoltenVKShaderConverter
)
if(MVK_VERSION VERSION_LESS "1.1.0")
target_include_directories(MoltenVKShaderConverter PRIVATE
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter
)
endif()
target_link_libraries(MoltenVKShaderConverter
PRIVATE
CONAN_PKG::glslang
MoltenVKCommon
${FOUNDATION_FRAMEWORK}
PUBLIC
CONAN_PKG::spirv-cross
)
if(NOT MVK_WITH_SPIRV_TOOLS)
target_compile_definitions(MoltenVKShaderConverter PRIVATE MVK_EXCLUDE_SPIRV_TOOLS)
target_link_libraries(MoltenVKShaderConverter PRIVATE CONAN_PKG::spirv-tools)
endif()

# MoltenVKShaderConverterTool
# * direct dependencies:
# - external: None
# - internal: MoltenVKShaderConverter and MoltenVKCommon
# - frameworks: Metal and Foundation
if(MVK_BUILD_SHADERCONVERTER_TOOL)
file(GLOB MVK_SCT_SOURCES
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverterTool/*.cpp
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverterTool/*.mm
)
add_executable(MoltenVKShaderConverterTool ${MVK_SCT_SOURCES})
set_property(TARGET MoltenVKShaderConverterTool PROPERTY OUTPUT_NAME "MoltenVKShaderConverter")
target_include_directories(MoltenVKShaderConverterTool PRIVATE
${MVK_DIR}/MoltenVKShaderConverter/common
)
if(MVK_VERSION VERSION_LESS "1.1.0")
target_include_directories(MoltenVKShaderConverterTool PRIVATE
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter
)
else()
target_include_directories(MoltenVKShaderConverterTool PRIVATE
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverter
)
endif()
target_link_libraries(MoltenVKShaderConverterTool PRIVATE
MoltenVKCommon
MoltenVKShaderConverter
${METAL_FRAMEWORK}
${FOUNDATION_FRAMEWORK}
)
list(APPEND MVK_INSTALL_TARGETS MoltenVKShaderConverterTool)
endif()

# MoltenVK
# * direct dependencies:
# - external: cereal, spirv-cross and vulkan-headers (+ vulkan-portability if moltenvk < 1.1.0)
# - internal: MoltenVKShaderConverter and MoltenVKCommon
# - frameworks: Foundation, Metal, QuartzCore, AppKit, IOSurface + IOKit (Macos) or UIKit (iOS/tvOS)
file(GLOB_RECURSE MVK_SOURCES
${MVK_DIR}/MoltenVK/*.m
${MVK_DIR}/MoltenVK/*.mm
${MVK_DIR}/MoltenVK/*.cpp
)
add_library(MoltenVK ${MVK_SOURCES})
target_include_directories(MoltenVK PRIVATE
${MVK_DIR}/MoltenVK/MoltenVK/API
${MVK_DIR}/MoltenVK/MoltenVK/Commands
${MVK_DIR}/MoltenVK/MoltenVK/GPUObjects
${MVK_DIR}/MoltenVK/MoltenVK/Layers
${MVK_DIR}/MoltenVK/MoltenVK/OS
${MVK_DIR}/MoltenVK/MoltenVK/Utility
${MVK_DIR}/MoltenVK/MoltenVK/Vulkan
)
target_link_libraries(MoltenVK
PRIVATE
CONAN_PKG::cereal
CONAN_PKG::spirv-cross
MoltenVKCommon
MoltenVKShaderConverter
${FOUNDATION_FRAMEWORK}
${QUARTZ_CORE_FRAMEWORK}
${APPKIT_FRAMEWORK}
${IO_OR_UI_KIT_FRAMEWORK}
PUBLIC
CONAN_PKG::vulkan-headers
${METAL_FRAMEWORK}
${IOSURFACE_FRAMEWORK}
)
if(MVK_VERSION VERSION_LESS "1.1.0")
target_link_libraries(MoltenVK PUBLIC CONAN_PKG::vulkan-portability)
endif()
target_compile_options(MoltenVK PRIVATE
-Wno-unguarded-availability-new
-Wno-deprecated-declarations
-Wno-nonportable-include-path
)
list(APPEND MVK_INSTALL_TARGETS MoltenVK)

# Custom Target to generate internal header file required by MoltenVK target.
# This header should contain:
# - if moltenvk < 1.44 : spirv-cross commit hash in spirvCrossRevisionString variable
# - if moltenvk >= 1.44: moltenvk commit hash in mvkRevString variable (but we still
# use spirv-cross commit hash, since MoltenVK hash is not available in this context,
# and hash value is no really important)
set(MVK_REVISION_FILE ${MVK_DIR}/ExternalRevisions/SPIRV-Cross_repo_revision)
set(MVK_REVISION_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/mvk_hash_generated)
if(MVK_VERSION VERSION_LESS "1.0.44")
set(MVK_REVISION_HEADER ${MVK_REVISION_HEADER_DIR}/SPIRV-Cross/mvkSpirvCrossRevisionDerived.h)
set(MVK_REV_VAR_NAME "spirvCrossRevisionString")
else()
set(MVK_REVISION_HEADER ${MVK_REVISION_HEADER_DIR}/mvkGitRevDerived.h)
set(MVK_REV_VAR_NAME "mvkRevString")
endif()
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/mvk_git_hash_generator.in
"file(READ @MVK_REVISION_FILE@ MVK_SPIRV_CROSS_GIT_REV)\n"
"string(REPLACE \"\\n\" \"\" MVK_SPIRV_CROSS_GIT_REV \${MVK_SPIRV_CROSS_GIT_REV})\n"
"file(WRITE @MVK_REVISION_HEADER@ \"static const char* @MVK_REV_VAR_NAME@ = \\\"\${MVK_SPIRV_CROSS_GIT_REV}\\\";\")\n"
)
configure_file(
${CMAKE_CURRENT_BINARY_DIR}/mvk_git_hash_generator.in
${CMAKE_CURRENT_BINARY_DIR}/mvk_git_hash_generator.cmake
@ONLY
)
add_custom_target(mvk-commit-hash-header DEPENDS ${MVK_REVISION_FILE} ${MVK_REVISION_HEADER})
add_custom_command(
COMMENT "Create ${MVK_REVISION_HEADER}"
OUTPUT ${MVK_REVISION_HEADER}
DEPENDS ${MVK_REVISION_FILE}
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/mvk_git_hash_generator.cmake"
)
add_dependencies(MoltenVK mvk-commit-hash-header)
target_include_directories(MoltenVK PRIVATE ${MVK_REVISION_HEADER_DIR})

# Installation
install(
TARGETS ${MVK_INSTALL_TARGETS}
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

if(BUILD_SHARED_LIBS)
install(
FILES ${MVK_DIR}/MoltenVK/icd/MoltenVK_icd.json
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

file(GLOB MVK_PUBLIC_HEADERS ${MVK_DIR}/MoltenVK/MoltenVK/API/*.h)
install(
FILES ${MVK_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/MoltenVK
)

if(MVK_VERSION VERSION_LESS "1.1.0")
file(GLOB MVK_SC_PUBLIC_HEADERS
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/*Conversion.h
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKGLSLToSPIRVConverter/*Converter.h
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/*Conversion.h
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKSPIRVToMSLConverter/*Converter.h
)
else()
file(GLOB MVK_SC_PUBLIC_HEADERS
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverter/*Conversion.h
${MVK_DIR}/MoltenVKShaderConverter/MoltenVKShaderConverter/*Converter.h
)
endif()
install(
FILES ${MVK_SC_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/MoltenVKShaderConverter
)
8 changes: 8 additions & 0 deletions recipes/moltenvk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"1.1.1":
url: "https://github.com/KhronosGroup/MoltenVK/archive/v1.1.1.tar.gz"
sha256: "cd1712c571d4155f4143c435c8551a5cb8cbb311ad7fff03595322ab971682c0"
patches:
"1.1.1":
- patch_file: "patches/0001-fix-spirv-cross-includes-1.1.x.patch"
base_path: "source_subfolder"
Loading

0 comments on commit a255e1f

Please sign in to comment.