From caeaabb3561b64a8525bf923395833962663f791 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 27 Oct 2021 15:50:04 +0200 Subject: FindVulkan: Add version support The version is constructed in the form .. e.g. 1.2.189. --- Modules/FindVulkan.cmake | 57 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 14 deletions(-) (limited to 'Modules/FindVulkan.cmake') diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 4f48e135aa..078e367723 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -39,18 +39,29 @@ This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found: Result Variables ^^^^^^^^^^^^^^^^ -This module defines the following variables:: - - Vulkan_FOUND - "True" if Vulkan was found - Vulkan_INCLUDE_DIRS - include directories for Vulkan - Vulkan_LIBRARIES - link against this library to use Vulkan - -The module will also define three cache variables:: - - Vulkan_INCLUDE_DIR - the Vulkan include directory - Vulkan_LIBRARY - the path to the Vulkan library - Vulkan_GLSLC_EXECUTABLE - the path to the GLSL SPIR-V compiler - Vulkan_GLSLANG_VALIDATOR_EXECUTABLE - the path to the glslangValidator tool +This module defines the following variables: + +``Vulkan_FOUND`` + set to true if Vulkan was found +``Vulkan_INCLUDE_DIRS`` + include directories for Vulkan +``Vulkan_LIBRARIES`` + link against this library to use Vulkan +``Vulkan_VERSION`` + .. versionadded:: 3.23 + + value from ``vulkan/vulkan_core.h`` + +The module will also defines these cache variables: + +``Vulkan_INCLUDE_DIR`` + the Vulkan include directory +``Vulkan_LIBRARY`` + the path to the Vulkan library +``Vulkan_GLSLC_EXECUTABLE`` + the path to the GLSL SPIR-V compiler +``Vulkan_GLSLANG_VALIDATOR_EXECUTABLE`` + the path to the glslangValidator tool Hints ^^^^^ @@ -125,10 +136,28 @@ endif() set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR}) +# detect version e.g 1.2.189 +set(Vulkan_VERSION "") +if(Vulkan_INCLUDE_DIR) + set(VULKAN_CORE_H ${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h) + if(EXISTS ${VULKAN_CORE_H}) + file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION ") + string(REGEX MATCHALL "[0-9]+" VulkanHeaderVersion "${VulkanHeaderVersionLine}") + file(STRINGS ${VULKAN_CORE_H} VulkanHeaderVersionLine REGEX "^#define VK_HEADER_VERSION_COMPLETE ") + # "#define VK_HEADER_VERSION_COMPLETE VK_MAKE_API_VERSION(0, 1, 2, VK_HEADER_VERSION)" + string(REGEX REPLACE ".*\\([0_9]+[, ]+([0-9]+)[, ]+([0-9]+)[, ].*\\)" + "\\1.\\2.${VulkanHeaderVersion}" Vulkan_VERSION "${VulkanHeaderVersionLine}") + endif() +endif() + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(Vulkan - DEFAULT_MSG - Vulkan_LIBRARY Vulkan_INCLUDE_DIR) + REQUIRED_VARS + Vulkan_LIBRARY + Vulkan_INCLUDE_DIR + VERSION_VAR + Vulkan_VERSION +) mark_as_advanced(Vulkan_INCLUDE_DIR Vulkan_LIBRARY Vulkan_GLSLC_EXECUTABLE Vulkan_GLSLANG_VALIDATOR_EXECUTABLE) -- cgit v1.2.1