vk-bootstrap/tests/CMakeLists.txt
Charles Giessen f223c8d5ae Cleanup CMake finding of Vulkan & installation code
Adds extensive integration tests that exercise the various ways of finding
the Vulkan-Headers.

vk-bootstrap should now use the Vulkan-Headers or Vulkan::Headers targets if
they were already defined (such as is the case of FetchContent), and will
look for the VulkanHeaders package and Vulkan package as a fallback, and will
FetchContent Vulkan-Headers directly if that fails.

This should make integration seamless with the various ways vulkan-headers
is acquired.

The vk-bootstrap-vulkan-headers target was dropped in favor of directly
linking to Vulkan-Headers (creating a target by that name if none exists).
2023-12-02 19:49:54 -07:00

117 lines
4.9 KiB
CMake

if (WIN32)
add_library(VulkanMock SHARED vulkan_mock.hpp vulkan_mock.cpp)
# Need to name the target "vulkan-1" so that it'll be loaded instead of the *actual* vulkan-1.dll on the system
set_target_properties(VulkanMock PROPERTIES OUTPUT_NAME "vulkan-1")
else()
add_library(VulkanMock STATIC vulkan_mock.hpp vulkan_mock.cpp)
endif()
target_link_libraries(VulkanMock
PUBLIC
Vulkan::Headers
PRIVATE
vk-bootstrap-compiler-warnings
)
target_compile_features(VulkanMock PUBLIC cxx_std_17)
target_compile_definitions(VulkanMock PUBLIC VK_NO_PROTOTYPES)
add_executable(vk-bootstrap-test
vulkan_library_loader.hpp
bootstrap_tests.cpp
error_code_tests.cpp
unit_tests.cpp
include_checks.cpp
)
target_link_libraries(vk-bootstrap-test
PRIVATE
vk-bootstrap
Vulkan::Headers
vk-bootstrap-compiler-warnings
VulkanMock
Catch2::Catch2WithMain
)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(vk-bootstrap-test PRIVATE -Wno-error=deprecated-declarations)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(vk-bootstrap-test PRIVATE /wd4996)
endif()
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
include(Catch)
catch_discover_tests(vk-bootstrap-test)
# Test add_subdirectory suppport using fetch content vulkan headers
add_test(NAME integration.add_subdirectory.fetch_content_vulkan_headers
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory/fetch_content_vulkan_headers
--build-generator ${CMAKE_GENERATOR}
--build-options -DADD_SUBDIRECTORY_TESTING=ON -DVULKAN_HEADER_VERSION_GIT_TAG=${VK_BOOTSTRAP_SOURCE_HEADER_VERSION_GIT_TAG}
)
get_target_property(vulkan_headers_include_dir Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES)
# Test add_subdirectory suppport by setting VK_BOOTSTRAP_VULKAN_HEADER_DIR to the include directory of the Vulkan::Headers
add_test(NAME integration.add_subdirectory.vulkan_header_dir
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory/vulkan_header_dir
--build-generator ${CMAKE_GENERATOR}
--build-options -DADD_SUBDIRECTORY_TESTING=ON -DVK_BOOTSTRAP_VULKAN_HEADER_DIR=${vulkan_headers_include_dir}
)
set(test_install_dir "${CMAKE_CURRENT_BINARY_DIR}/install")
add_test(NAME integration.install
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix ${test_install_dir} --config $<CONFIG>
)
find_package(VulkanHeaders CONFIG)
if (VulkanHeaders_FOUND)
set(vulkan_headers_package_location ${VulkanHeaders_DIR})
# Test add_subdirectory suppport using find_package(VulkanHeaders)
add_test(NAME integration.add_subdirectory.find_package_vulkan_headers
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory/find_package_vulkan_headers
--build-generator ${CMAKE_GENERATOR}
--build-options -DADD_SUBDIRECTORY_TESTING=ON -DCMAKE_PREFIX_PATH=${vulkan_headers_install_dir}
)
# Test find_package suppport using find_package(VulkanHeaders)
add_test(NAME integration.find_package.find_package_vulkan_headers
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/find_package/find_package_vulkan_headers
--build-generator ${CMAKE_GENERATOR}
--build-options -DFIND_PACKAGE_TESTING=ON "-DCMAKE_PREFIX_PATH=${vulkan_headers_install_dir};${test_install_dir}"
)
set_tests_properties(integration.find_package.find_package_vulkan_headers PROPERTIES DEPENDS integration.install)
endif()
find_package(Vulkan)
if (Vulkan_FOUND)
# Test add_subdirectory suppport using find_package(Vulkan)
add_test(NAME integration.add_subdirectory.find_package_vulkan
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/add_subdirectory/find_package_vulkan
--build-generator ${CMAKE_GENERATOR}
--build-options -DADD_SUBDIRECTORY_TESTING=ON -DFIND_PACKAGE_VULKAN=ON
)
# Test find_package suppport using find_package(Vulkan)
add_test(NAME integration.find_package.find_package_vulkan
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test ${CMAKE_CURRENT_LIST_DIR}/integration
${CMAKE_CURRENT_BINARY_DIR}/find_package/find_package_vulkan
--build-generator ${CMAKE_GENERATOR}
--build-options -DFIND_PACKAGE_TESTING=ON -DCMAKE_PREFIX_PATH=${test_install_dir} -DFIND_PACKAGE_VULKAN=ON
)
set_tests_properties(integration.find_package.find_package_vulkan PROPERTIES DEPENDS integration.install)
endif()