diff options
author | Brad King <brad.king@kitware.com> | 2021-05-25 14:04:46 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-05-25 14:04:52 (GMT) |
commit | 52b0795d1ad588ca01b0f62ca90037abfea73aa3 (patch) | |
tree | 2a06ca5a200b08e742cb020f21b5939ab78c09ca /Tests | |
parent | 909b7a3eca08e3c558012000055f8c1676eb8e50 (diff) | |
parent | 668ba68a7af9e7511e0e6c988ccfe297956a42b6 (diff) | |
download | CMake-52b0795d1ad588ca01b0f62ca90037abfea73aa3.zip CMake-52b0795d1ad588ca01b0f62ca90037abfea73aa3.tar.gz CMake-52b0795d1ad588ca01b0f62ca90037abfea73aa3.tar.bz2 |
Merge topic 'FindVulkan-add-Headers-glslangValidator-targets'
668ba68a7a FindVulkan: add Vulkan::Headers and Vulkan::glslangValidator targets
Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !6154
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; +} |