diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b7287bbb..471121581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,11 +96,11 @@ option_if_not_defined(GPGMM_ENABLE_D3D12 "Enable compilation of the D3D12 backen option_if_not_defined(GPGMM_ENABLE_VK "Enable compilation of the Vulkan backend" ${ENABLE_VK}) option_if_not_defined(GPGMM_ENABLE_VK_STATIC_FUNCTIONS "Links Vulkan functions by statically importing them" ON) option_if_not_defined(GPGMM_ENABLE_VK_LOADER "Enables compilation of Vulkan loader" ${ENABLE_VK_LOADER}) +option_if_not_defined(GPGMM_ENABLE_VK_USE_SDK "Enable compilation of the Vulkan backend by using the installed Vulkan SDK." OFF) set_if_not_defined(GPGMM_THIRD_PARTY_DIR "${GPGMM_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.") set_if_not_defined(GPGMM_VK_DEPS_DIR "${GPGMM_THIRD_PARTY_DIR}/vulkan-deps" "Directory in which to find vulkan-deps") set_if_not_defined(GPGMM_VK_HEADERS_DIR "${GPGMM_VK_DEPS_DIR}/vulkan-headers/src" "Directory in which to find Vulkan-Headers") -set_if_not_defined(GPGMM_VK_TOOLS_DIR "${GPGMM_VK_DEPS_DIR}/vulkan-tools/src" "Directory in which to find Vulkan-Tools") option_if_not_defined(GPGMM_ALWAYS_ASSERT "Enable assertions on all build types" OFF) option_if_not_defined(GPGMM_FORCE_TRACING "Enables event tracing even in release builds" OFF) diff --git a/src/gpgmm/CMakeLists.txt b/src/gpgmm/CMakeLists.txt index 8bb995c0a..37b43d8df 100644 --- a/src/gpgmm/CMakeLists.txt +++ b/src/gpgmm/CMakeLists.txt @@ -112,13 +112,22 @@ if (GPGMM_ENABLE_VK) ) if (GPGMM_ENABLE_VK_LOADER) - target_link_libraries(gpgmm PRIVATE - Vulkan::Vulkan - ) + if (GPGMM_ENABLE_VK_USE_SDK) + target_link_libraries(gpgmm PRIVATE + ${GPGMM_VK_LIBRARIES_DIR} + ) + else() + target_link_libraries(gpgmm PRIVATE + Vulkan::Vulkan + ) + endif() endif() - target_link_libraries(gpgmm PUBLIC Vulkan-Headers) - target_include_directories(gpgmm PRIVATE ${GPGMM_VK_TOOLS_DIR}) + if (GPGMM_ENABLE_VK_USE_SDK) + target_include_directories(gpgmm PUBLIC ${GPGMM_VK_INCLUDE_DIR}) + else() + target_link_libraries(gpgmm PUBLIC Vulkan-Headers) + endif() endif() diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 363577569..580478acb 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -84,10 +84,6 @@ if (GPGMM_ENABLE_VK) "VKTest.h" "end2end/VKResourceAllocatorTests.cpp" ) - - target_link_libraries(gpgmm_end2end_tests PRIVATE - Vulkan::Vulkan - ) endif() target_link_libraries(gpgmm_end2end_tests PRIVATE diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index c2e1fc79c..5b62612f8 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -58,19 +58,32 @@ if (GPGMM_ENABLE_TESTS) endif() # GPGMM_ENABLE_TESTS if (GPGMM_ENABLE_VK) - FetchContent_Declare( - vulkan-headers - GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git - GIT_TAG ${GPGMM_VULKAN_HEADERS_REVISION} - ) - FetchContent_MakeAvailable(vulkan-headers) + if (GPGMM_ENABLE_VK_USE_SDK) + message(INFO "Using installed Vulkan SDK") + find_package(Vulkan REQUIRED) + + set(GPGMM_VK_INCLUDE_DIR ${Vulkan_INCLUDE_DIRS} CACHE STRING "" FORCE) + set(GPGMM_VK_LIBRARIES_DIR ${Vulkan_LIBRARIES} CACHE STRING "" FORCE) + message(INFO "Using Vulkan include directory: ${GPGMM_VK_INCLUDE_DIR}") + message(INFO "Using Vulkan library directory: ${GPGMM_VK_LIBRARIES_DIR}") + + else() + FetchContent_Declare( + vulkan-headers + GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git + GIT_TAG ${GPGMM_VULKAN_HEADERS_REVISION} + ) + FetchContent_MakeAvailable(vulkan-headers) + + if (GPGMM_ENABLE_VK_LOADER) + FetchContent_Declare( + vulkan-loader + GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Loader.git + GIT_TAG ${GPGMM_VULKAN_LOADER_REVISION} + ) + FetchContent_MakeAvailable(vulkan-loader) + + endif() # GPGMM_ENABLE_VK_LOADER + endif() # GPGMM_ENABLE_VK_USE_SDK - if (GPGMM_ENABLE_VK_LOADER) - FetchContent_Declare( - vulkan-loader - GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Loader.git - GIT_TAG ${GPGMM_VULKAN_LOADER_REVISION} - ) - FetchContent_MakeAvailable(vulkan-loader) - endif() # GPGMM_ENABLE_VK_LOADER endif() # GPGMM_ENABLE_VK