diff options
author | MACHIZAUD Andréa <andrea.machizaud@gmail.com> | 2022-05-18 15:18:57 (GMT) |
---|---|---|
committer | MACHIZAUD Andréa <andrea.machizaud@gmail.com> | 2022-05-18 21:15:50 (GMT) |
commit | 8d133f49e31d049b782dffaf2d444486f9461702 (patch) | |
tree | d86d921e5318721d167d16fd0170a222082ebbd8 | |
parent | 6e4d20921d92458890837859ad36d1783331abc8 (diff) | |
download | CMake-8d133f49e31d049b782dffaf2d444486f9461702.zip CMake-8d133f49e31d049b782dffaf2d444486f9461702.tar.gz CMake-8d133f49e31d049b782dffaf2d444486f9461702.tar.bz2 |
FindVulkan: Add component for `SPIRV-Tools`
-rw-r--r-- | Modules/FindVulkan.cmake | 57 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/main-SPIRV-Tools.c | 15 |
3 files changed, 81 insertions, 5 deletions
diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake index 6c17b08..8446c6c 100644 --- a/Modules/FindVulkan.cmake +++ b/Modules/FindVulkan.cmake @@ -15,8 +15,9 @@ Optional COMPONENTS .. versionadded:: 3.24 -This module respects several optional COMPONENTS: ``shaderc_combined``. There -are corresponding import targets for each of these flags. +This module respects several optional COMPONENTS: ``shaderc_combined`` and +``SPIRV-Tools``. There are corresponding import targets for each of these +flags. IMPORTED Targets ^^^^^^^^^^^^^^^^ @@ -50,6 +51,12 @@ This module defines :prop_tgt:`IMPORTED` targets if Vulkan has been found: Defined if SDK has the Google static library for Vulkan shader compilation (shaderc_combined). +``Vulkan::SPIRV-Tools`` + .. versionadded:: 3.24 + + Defined if SDK has the Khronos library to process SPIR-V modules + (SPIRV-Tools). + Result Variables ^^^^^^^^^^^^^^^^ @@ -69,9 +76,10 @@ This module defines the following variables: .. versionadded:: 3.24 True, if the SDK has the shaderc_combined library. +``Vulkan_SPIRV-Tools_FOUND`` + .. versionadded:: 3.24 -.. versionadded:: 3.24 - Variables for component library ``shaderc_combined``. + True, if the SDK has the SPIRV-Tools library. The module will also defines these cache variables: @@ -87,6 +95,10 @@ The module will also defines these cache variables: .. versionadded:: 3.24 Path to the shaderc_combined library. +``Vulkan_SPIRV-Tools_LIBRARY`` + .. versionadded:: 3.24 + + Path to the SPIRV-Tools library. Hints ^^^^^ @@ -177,6 +189,19 @@ if(shaderc_combined IN_LIST Vulkan_FIND_COMPONENTS) ${_Vulkan_hint_library_search_paths}) mark_as_advanced(Vulkan_shaderc_combined_DEBUG_LIBRARY) endif() +if(SPIRV-Tools IN_LIST Vulkan_FIND_COMPONENTS) + find_library(Vulkan_SPIRV-Tools_LIBRARY + NAMES SPIRV-Tools + HINTS + ${_Vulkan_hint_library_search_paths}) + mark_as_advanced(Vulkan_SPIRV-Tools_LIBRARY) + + find_library(Vulkan_SPIRV-Tools_DEBUG_LIBRARY + NAMES SPIRV-Toolsd + HINTS + ${_Vulkan_hint_library_search_paths}) + mark_as_advanced(Vulkan_SPIRV-Tools_DEBUG_LIBRARY) +endif() function(_Vulkan_set_library_component_found component) if(Vulkan_${component}_LIBRARY OR Vulkan_${component}_DEBUG_LIBRARY) @@ -202,6 +227,7 @@ function(_Vulkan_set_library_component_found component) endfunction() _Vulkan_set_library_component_found(shaderc_combined) +_Vulkan_set_library_component_found(SPIRV-Tools) set(Vulkan_LIBRARIES ${Vulkan_LIBRARY}) set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR}) @@ -288,6 +314,29 @@ if(Vulkan_FOUND) Threads::Threads) endif() endif() + + if((Vulkan_SPIRV-Tools_LIBRARY OR Vulkan_SPIRV-Tools_DEBUG_LIBRARY) AND NOT TARGET Vulkan::SPIRV-Tools) + add_library(Vulkan::SPIRV-Tools STATIC IMPORTED) + set_property(TARGET Vulkan::SPIRV-Tools + PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${Vulkan_INCLUDE_DIRS}") + if(Vulkan_SPIRV-Tools_LIBRARY) + set_property(TARGET Vulkan::SPIRV-Tools APPEND + PROPERTY + IMPORTED_CONFIGURATIONS Release) + set_property(TARGET Vulkan::SPIRV-Tools + PROPERTY + IMPORTED_LOCATION_RELEASE "${Vulkan_SPIRV-Tools_LIBRARY}") + endif() + if(Vulkan_SPIRV-Tools_DEBUG_LIBRARY) + set_property(TARGET Vulkan::SPIRV-Tools APPEND + PROPERTY + IMPORTED_CONFIGURATIONS Debug) + set_property(TARGET Vulkan::SPIRV-Tools + PROPERTY + IMPORTED_LOCATION_DEBUG "${Vulkan_SPIRV-Tools_DEBUG_LIBRARY}") + endif() + endif() endif() unset(_Vulkan_library_name) diff --git a/Tests/FindVulkan/Test/CMakeLists.txt b/Tests/FindVulkan/Test/CMakeLists.txt index 005497c..be407c5 100644 --- a/Tests/FindVulkan/Test/CMakeLists.txt +++ b/Tests/FindVulkan/Test/CMakeLists.txt @@ -6,7 +6,8 @@ include(CTest) SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../../Modules) find_package(Vulkan REQUIRED COMPONENTS - shaderc_combined) + shaderc_combined + SPIRV-Tools) add_executable(test_tgt main.c) target_link_libraries(test_tgt Vulkan::Vulkan) @@ -37,6 +38,17 @@ if(NOT shaderc_combined_debug_location) MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") endif() +add_executable(test_tgt_SPIRV-Tools main-SPIRV-Tools.c) +target_link_libraries(test_tgt_SPIRV-Tools Vulkan::SPIRV-Tools) +add_test(NAME test_tgt_SPIRV-Tools COMMAND test_tgt_SPIRV-Tools) + +get_property(SPIRV-Tools_debug_location TARGET Vulkan::SPIRV-Tools PROPERTY IMPORTED_LOCATION_DEBUG) +if(NOT SPIRV-Tools_debug_location) + set_property(TARGET test_tgt_SPIRV-Tools + PROPERTY + MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + if(Vulkan_GLSLC_EXECUTABLE) add_test(NAME test_glslc COMMAND ${CMAKE_COMMAND} diff --git a/Tests/FindVulkan/Test/main-SPIRV-Tools.c b/Tests/FindVulkan/Test/main-SPIRV-Tools.c new file mode 100644 index 0000000..097198d --- /dev/null +++ b/Tests/FindVulkan/Test/main-SPIRV-Tools.c @@ -0,0 +1,15 @@ +#include <assert.h> +#include <spirv-tools/libspirv.h> +#include <stdio.h> + +int main() +{ + const char* spv_version = spvSoftwareVersionString(); + const char* spv_details = spvSoftwareVersionDetailsString(); + assert(spv_version); + assert(spv_details); + + printf("SPIRV-Tools version: %s (details: %s)", spv_version, spv_details); + + return 0; +} |