Support tests on windows with clang & clang-cl

Required adding a .def file to properly export the required symbols and
disabling pointer cast warnings that are coming from Catch2.
This commit is contained in:
Charles Giessen 2023-12-06 13:59:42 -07:00 committed by Charles Giessen
parent 767bd1baf2
commit 348e8bf796
5 changed files with 31 additions and 24 deletions

View File

@ -12,7 +12,14 @@ target_link_libraries(VulkanMock
vk-bootstrap-compiler-warnings
)
target_compile_features(VulkanMock PUBLIC cxx_std_17)
target_compile_definitions(VulkanMock PUBLIC VK_NO_PROTOTYPES)
target_compile_definitions(VulkanMock PUBLIC VK_NO_PROTOTYPES COMPILING_DLL)
if(WIN32)
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
target_link_options(VulkanMock PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/vulkan_mock.def)
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU")
target_link_options(VulkanMock PRIVATE -Wl,/DEF:${CMAKE_CURRENT_SOURCE_DIR}/vulkan_mock.def)
endif()
endif()
add_executable(vk-bootstrap-test
vulkan_library_loader.hpp
@ -37,6 +44,10 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(vk-bootstrap-test PRIVATE /wd4996)
endif()
if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE -Wno-microsoft-cast)
endif()
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
include(Catch)
catch_discover_tests(vk-bootstrap-test)

View File

@ -25,7 +25,7 @@ VkExtensionProperties get_extension_properties(const char* extName) {
}
VulkanMock& get_and_setup_default() {
VulkanMock& mock = get_vulkan_mock();
VulkanMock& mock = *get_vulkan_mock();
mock.instance_extensions.push_back(get_extension_properties(VK_KHR_SURFACE_EXTENSION_NAME));
#if defined(_WIN32)
mock.instance_extensions.push_back(get_extension_properties("VK_KHR_win32_surface"));
@ -512,7 +512,7 @@ TEST_CASE("SystemInfo Loading Vulkan Automatically", "[VkBootstrap.loading]") {
TEST_CASE("SystemInfo Loading Vulkan Manually", "[VkBootstrap.loading]") {
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
VulkanLibrary vk_lib;
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
REQUIRE(vk_lib.vkGetInstanceProcAddr);
auto info_ret = vkb::SystemInfo::get_system_info(vk_lib.vkGetInstanceProcAddr);
REQUIRE(info_ret);
vkb::InstanceBuilder builder;
@ -531,7 +531,7 @@ TEST_CASE("InstanceBuilder Loading Vulkan Automatically", "[VkBootstrap.loading]
TEST_CASE("InstanceBuilder Loading Vulkan Manually", "[VkBootstrap.loading]") {
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
VulkanLibrary vk_lib;
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
REQUIRE(vk_lib.vkGetInstanceProcAddr);
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
auto ret = builder.build();
vk_lib.close();
@ -554,7 +554,7 @@ TEST_CASE("ReLoading Vulkan Manually", "[VkBootstrap.loading]") {
[[maybe_unused]] VulkanMock& mock = get_and_setup_default();
{
VulkanLibrary vk_lib;
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
REQUIRE(vk_lib.vkGetInstanceProcAddr);
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
auto ret = builder.build();
REQUIRE(ret);
@ -562,7 +562,7 @@ TEST_CASE("ReLoading Vulkan Manually", "[VkBootstrap.loading]") {
}
{
VulkanLibrary vk_lib;
REQUIRE(vk_lib.vkGetInstanceProcAddr != NULL);
REQUIRE(vk_lib.vkGetInstanceProcAddr);
vkb::InstanceBuilder builder{ vk_lib.vkGetInstanceProcAddr };
auto ret = builder.build();
REQUIRE(ret);
@ -643,7 +643,7 @@ TEST_CASE("Passing vkb classes to Vulkan handles", "[VkBootstrap.pass_class_to_h
// Check if we can get instance functions.
PFN_vkVoidFunction instanceFunction = instance.fp_vkGetInstanceProcAddr(instance, "vkEnumeratePhysicalDevices"); // validation layers should be provided.
REQUIRE(instanceFunction != NULL);
REQUIRE(instanceFunction);
vkb::PhysicalDeviceSelector physicalDeviceSelector(instance);
auto physicalDevice =
@ -655,7 +655,7 @@ TEST_CASE("Passing vkb classes to Vulkan handles", "[VkBootstrap.pass_class_to_h
// Check if we can get a device function address, passing vkb::Device to the function.
PFN_vkVoidFunction deviceFunction = instance.fp_vkGetDeviceProcAddr(device.value(), "vkAcquireNextImageKHR");
REQUIRE(deviceFunction != NULL);
REQUIRE(deviceFunction);
}
}

View File

@ -17,9 +17,11 @@
VulkanMock mock;
EXPORT_MACRO VulkanMock& get_vulkan_mock() {
extern "C" {
VulkanMock* get_vulkan_mock() {
mock = VulkanMock{};
return mock;
return &mock;
}
}
template <typename T> VkResult fill_out_count_pointer_pair(std::vector<T> const& data_vec, uint32_t* pCount, T* pData) {
@ -368,13 +370,9 @@ PFN_vkVoidFunction shim_vkGetInstanceProcAddr([[maybe_unused]] VkInstance instan
}
extern "C" {
#if defined(WIN32)
EXPORT_MACRO VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
return shim_vkGetInstanceProcAddr(instance, pName);
}
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__)
#define DLSYM_FUNC_NAME dlsym

4
tests/vulkan_mock.def Normal file
View File

@ -0,0 +1,4 @@
LIBRARY vulkan-1
EXPORTS
get_vulkan_mock
vkGetInstanceProcAddr

View File

@ -91,12 +91,6 @@ struct VulkanMock {
}
};
#if !defined(EXPORT_MACRO)
#if defined(WIN32)
#define EXPORT_MACRO __declspec(dllexport)
#else
#define EXPORT_MACRO
#endif
#endif
EXPORT_MACRO VulkanMock& get_vulkan_mock();
extern "C" {
VulkanMock* get_vulkan_mock();
}