diff options
author | PCJohn <peciva@fit.vut.cz> | 2021-05-22 13:34:17 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-24 16:53:15 (GMT) |
commit | 668ba68a7af9e7511e0e6c988ccfe297956a42b6 (patch) | |
tree | b9b0985700f021731746fe92904c6e473776b164 /Tests | |
parent | 7ee3ccbbeabfcd27ebfbab48b05539134e63cb8f (diff) | |
download | CMake-668ba68a7af9e7511e0e6c988ccfe297956a42b6.zip CMake-668ba68a7af9e7511e0e6c988ccfe297956a42b6.tar.gz CMake-668ba68a7af9e7511e0e6c988ccfe297956a42b6.tar.bz2 |
FindVulkan: add Vulkan::Headers and Vulkan::glslangValidator targets
The `Vulkan::Headers` target complements existing Vulkan::Vulkan target.
It is the same except it omits the Vulkan library which supports
applications that loads the Vulkan library in at runtime.
The `Vulkan::glslangValidator` target provides the glslangValidator
executable which is the tool for converting between shader languages
(GLSL, SPIR-V, etc.).
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/FindVulkan/Test/CMakeLists.txt | 20 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/Run-glslangValidator.cmake | 20 | ||||
-rw-r--r-- | Tests/FindVulkan/Test/main-dynamicVulkanLoading.cpp | 55 |
3 files changed, 94 insertions, 1 deletions
diff --git a/Tests/FindVulkan/Test/CMakeLists.txt b/Tests/FindVulkan/Test/CMakeLists.txt index 9d36a0d..7ae8a11 100644 --- a/Tests/FindVulkan/Test/CMakeLists.txt +++ b/Tests/FindVulkan/Test/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.4) -project(TestFindVulkan C) +project(TestFindVulkan C CXX) include(CTest) SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../) @@ -14,6 +14,15 @@ target_include_directories(test_var PRIVATE ${Vulkan_INCLUDE_DIRS}) target_link_libraries(test_var PRIVATE ${Vulkan_LIBRARIES}) add_test(NAME test_var COMMAND test_var) +add_executable(test_tgt_dl main-dynamicVulkanLoading.cpp) +target_link_libraries(test_tgt_dl Vulkan::Headers ${CMAKE_DL_LIBS}) +add_test(NAME test_tgt_dl COMMAND test_tgt_dl) + +add_executable(test_var_dl main-dynamicVulkanLoading.cpp) +target_include_directories(test_var_dl PRIVATE ${Vulkan_INCLUDE_DIRS}) +target_link_libraries(test_var_dl ${CMAKE_DL_LIBS}) +add_test(NAME test_var_dl COMMAND test_var_dl) + if(Vulkan_GLSLC_EXECUTABLE) add_test(NAME test_glslc COMMAND ${CMAKE_COMMAND} @@ -22,3 +31,12 @@ if(Vulkan_GLSLC_EXECUTABLE) -P "${CMAKE_CURRENT_LIST_DIR}/Run-glslc.cmake" ) endif() + +if(Vulkan_GLSLANG_VALIDATOR_EXECUTABLE) + add_test(NAME test_glslangValidator + COMMAND ${CMAKE_COMMAND} + "-DVULKAN_GLSLANG_VALIDATOR_EXECUTABLE=${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}" + "-DVULKAN_GLSLANG_VALIDATOR_EXECUTABLE_TARGET=$<TARGET_FILE:Vulkan::glslangValidator>" + -P "${CMAKE_CURRENT_LIST_DIR}/Run-glslangValidator.cmake" + ) +endif() diff --git a/Tests/FindVulkan/Test/Run-glslangValidator.cmake b/Tests/FindVulkan/Test/Run-glslangValidator.cmake new file mode 100644 index 0000000..27fd950 --- /dev/null +++ b/Tests/FindVulkan/Test/Run-glslangValidator.cmake @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.12) + +function(run_glslangValidator exe exe_display) + execute_process(COMMAND ${exe} --help + OUTPUT_VARIABLE output + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE result + ) + + if(NOT result EQUAL 1) + message(SEND_ERROR "Result of ${exe_display} --help is ${result}, should be 1") + endif() + + if(NOT output MATCHES "^Usage: glslangValidator") + message(SEND_ERROR "Output of ${exe_display} --help is \"${output}\", should begin with \"Usage: glslangValidator\"") + endif() +endfunction() + +run_glslangValidator("${VULKAN_GLSLANG_VALIDATOR_EXECUTABLE}" "\${VULKAN_GLSLANG_VALIDATOR_EXECUTABLE}") +run_glslangValidator("${VULKAN_GLSLANG_VALIDATOR_EXECUTABLE_TARGET}" "Vulkan::glslangValidator") diff --git a/Tests/FindVulkan/Test/main-dynamicVulkanLoading.cpp b/Tests/FindVulkan/Test/main-dynamicVulkanLoading.cpp new file mode 100644 index 0000000..f6f909f --- /dev/null +++ b/Tests/FindVulkan/Test/main-dynamicVulkanLoading.cpp @@ -0,0 +1,55 @@ +#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 + +#include <iostream> + +#include <vulkan/vulkan.hpp> + +using namespace std; + +VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE + +int main() +{ + // catch exceptions + // (vulkan.hpp functions throws if they fail) + try { + + // initialize dynamic dispatcher + vk::DynamicLoader dl; + PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = + dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr"); + VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr); + + // Vulkan instance + vk::UniqueInstance instance = + vk::createInstanceUnique(vk::InstanceCreateInfo{ + vk::InstanceCreateFlags(), // flags + &(const vk::ApplicationInfo&)vk::ApplicationInfo{ + "CMake Test application", // application name + VK_MAKE_VERSION(0, 0, 0), // application version + "CMake Test Engine", // engine name + VK_MAKE_VERSION(0, 0, 0), // engine version + VK_API_VERSION_1_0, // api version + }, + 0, // enabled layer count + nullptr, // enabled layer names + 0, // enabled extension count + nullptr, // enabled extension names + }); + VULKAN_HPP_DEFAULT_DISPATCHER.init(instance.get()); + + // catch exceptions + } catch (vk::Error& e) { + cout << "Failed because of Vulkan exception: " << e.what() << endl; + } catch (exception& e) { + cout << "Failed because of exception: " << e.what() << endl; + } catch (...) { + cout << "Failed because of unspecified exception." << endl; + } + + // We can't assert in this code because in general vk::createInstanceUnique + // might throw if no driver is found - but if we get here, FindVulkan is + // working + + return 0; +} |