Commit 1866356f authored by Andrea Machizaud's avatar Andrea Machizaud
Browse files

FindVulkan: Add component for `MoltenVK`

parent 10a6bb16
Pipeline #282186 waiting for manual action with stages
in 5 minutes and 33 seconds
......@@ -17,6 +17,7 @@ Optional COMPONENTS
This module respects several optional COMPONENTS: ``glslc``,
``glslangValidator``, ``glslang``, ``shaderc_combined`` and ``SPIRV-Tools``.
On macOS, an additional component ``MoltenVK`` is available.
There are corresponding import targets for each of these flags.
IMPORTED Targets
......@@ -63,6 +64,12 @@ This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found:
Defined if SDK has the Khronos library to process SPIR-V modules
(SPIRV-Tools).
``Vulkan::MoltenVK``
.. versionadded:: 3.24
Defined if SDK has the Khronos library which implement a subset of Vulkan API
over Apple Metal graphics framework. (MoltenVK).
Result Variables
^^^^^^^^^^^^^^^^
......@@ -98,6 +105,10 @@ This module defines the following variables:
.. versionadded:: 3.24
True, if the SDK has the SPIRV-Tools library.
``Vulkan_MoltenVK_FOUND``
.. versionadded:: 3.24
True, if the SDK has the MoltenVK library.
The module will also defines these cache variables:
......@@ -121,6 +132,10 @@ The module will also defines these cache variables:
.. versionadded:: 3.24
Path to the SPIRV-Tools library.
``Vulkan_MoltenVK_LIBRARY``
.. versionadded:: 3.24
Path to the MoltenVK library.
Hints
^^^^^
......@@ -181,6 +196,28 @@ else()
"$ENV{VULKAN_SDK}/lib"
)
endif()
if(APPLE AND DEFINED ENV{VULKAN_SDK})
cmake_path(SET _MoltenVK_path NORMALIZE "$ENV{VULKAN_SDK}/../MoltenVK")
if(EXISTS "${_MoltenVK_path}")
list(APPEND _Vulkan_hint_include_search_paths
"${_MoltenVK_path}/include"
)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/iOS"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/tvOS"
)
else()
list(APPEND _Vulkan_hint_library_search_paths
"${_MoltenVK_path}/dylib/macOS"
)
endif()
endif()
unset(_MoltenVK_path)
endif()
find_path(Vulkan_INCLUDE_DIR
NAMES vulkan/vulkan.h
......@@ -323,6 +360,20 @@ if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS)
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY)
endif()
if(MoltenVK IN_LIST Vulkan_FIND_COMPONENTS)
find_library(Vulkan_MoltenVK_LIBRARY
NAMES MoltenVK
HINTS
${_Vulkan_hint_library_search_paths})
mark_as_advanced(Vulkan_MoltenVK_LIBRARY)
find_path(Vulkan_MoltenVK_INCLUDE_DIR
NAMES MoltenVK/mvk_vulkan.h
HINTS
${_Vulkan_hint_include_search_paths}
)
mark_as_advanced(Vulkan_MoltenVK_INCLUDE_DIR)
endif()
if(Vulkan_GLSLC_EXECUTABLE)
set(Vulkan_glslc_FOUND TRUE)
......@@ -387,6 +438,12 @@ _Vulkan_set_library_component_found(glslang
_Vulkan_set_library_component_found(shaderc_combined)
_Vulkan_set_library_component_found(SPIRV-Tools)
if(Vulkan_MoltenVK_INCLUDE_DIR AND Vulkan_MoltenVK_LIBRARY)
set(Vulkan_MoltenVK_FOUND TRUE)
else()
set(Vulkan_MoltenVK_FOUND FALSE)
endif()
set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
......@@ -409,6 +466,25 @@ if(Vulkan_INCLUDE_DIR)
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
set(Vulkan_MoltenVK_VERSION "")
if(Vulkan_MoltenVK_INCLUDE_DIR)
set(VK_MVK_MOLTENVK_H ${Vulkan_MoltenVK_INCLUDE_DIR}/MoltenVK/vk_mvk_moltenvk.h)
if(EXISTS ${VK_MVK_MOLTENVK_H})
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MAJOR REGEX "^#define MVK_VERSION_MAJOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MAJOR "${_Vulkan_MoltenVK_VERSION_MAJOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_MINOR REGEX "^#define MVK_VERSION_MINOR ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_MINOR "${_Vulkan_MoltenVK_VERSION_MINOR}")
file(STRINGS ${VK_MVK_MOLTENVK_H} _Vulkan_MoltenVK_VERSION_PATCH REGEX "^#define MVK_VERSION_PATCH ")
string(REGEX MATCHALL "[0-9]+" _Vulkan_MoltenVK_VERSION_PATCH "${_Vulkan_MoltenVK_VERSION_PATCH}")
set(Vulkan_MoltenVK_VERSION "${_Vulkan_MoltenVK_VERSION_MAJOR}.${_Vulkan_MoltenVK_VERSION_MINOR}.${_Vulkan_MoltenVK_VERSION_PATCH}")
unset(_Vulkan_MoltenVK_VERSION_MAJOR)
unset(_Vulkan_MoltenVK_VERSION_MINOR)
unset(_Vulkan_MoltenVK_VERSION_PATCH)
endif()
endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(Vulkan
REQUIRED_VARS
......@@ -649,6 +725,17 @@ if(Vulkan_FOUND)
endif()
endif()
if(Vulkan_MoltenVK_FOUND)
if(Vulkan_MoltenVK_LIBRARY AND NOT TARGET Vulkan::MoltenVK)
add_library(Vulkan::MoltenVK SHARED IMPORTED)
set_target_properties(Vulkan::MoltenVK
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_MoltenVK_INCLUDE_DIR}"
IMPORTED_LOCATION "${Vulkan_MoltenVK_LIBRARY}"
)
endif()
endif()
unset(_Vulkan_library_name)
unset(_Vulkan_hint_include_search_paths)
unset(_Vulkan_hint_executable_search_paths)
......
......@@ -3,11 +3,16 @@ cmake_policy(SET CMP0091 NEW)
project(TestFindVulkan C CXX)
include(CTest)
set(components
glslang
shaderc_combined
SPIRV-Tools
)
if(APPLE)
list(APPEND components MoltenVK)
endif()
find_package(Vulkan REQUIRED
COMPONENTS
glslang
shaderc_combined
SPIRV-Tools)
COMPONENTS ${components})
add_executable(test_tgt main.c)
target_link_libraries(test_tgt Vulkan::Vulkan)
......@@ -64,6 +69,12 @@ if(NOT SPIRV-Tools_debug_location)
MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
if(APPLE)
add_executable(test_tgt_MoltenVK main-MoltenVK.cxx)
target_link_libraries(test_tgt_MoltenVK Vulkan::MoltenVK)
add_test(NAME test_tgt_MoltenVK COMMAND test_tgt_MoltenVK)
endif()
if(Vulkan_GLSLC_EXECUTABLE)
add_test(NAME test_glslc
COMMAND ${CMAKE_COMMAND}
......
#include <iostream>
#include <MoltenVK/vk_mvk_moltenvk.h>
int main()
{
char mvk_version[256];
char vk_version[256];
vkGetVersionStringsMVK(mvk_version, sizeof(mvk_version), vk_version, sizeof(vk_version));
std::cout << "MoltenVK version: " << mvk_version << std::endl;
std::cout << "Vulkan version: " << vk_version << std::endl;
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment