From 3f3e0cbbc16c61f940281d29dde5cb9cc02630bb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 4 Aug 2023 14:41:30 -0700 Subject: [PATCH] CMake: Fix include path discovery when using FindVulkan.cmake volk does not need libvulkan.so dependency, and in fact adding it is dangerous due to possible symbol conflicts and unnecessary as the point of using volk is to avoid direct dependencies on Vulkan loader. When FindVulkan.cmake discovered a Vulkan installation, it would erroneously depend on Vulkan::Vulkan which would add libvulkan.so dependency. Instead, rework all of this to just get the include path from the module or compute it from other variables. This setup is cleaner and it guarantees that we aren't going to get any rogue flags into the build. --- CMakeLists.txt | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 763e855..e111f04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,33 +65,25 @@ if(VOLK_PULL_IN_VULKAN) # If CMake has the FindVulkan module and it works, use it. find_package(Vulkan QUIET) - # Try an explicit CMake variable first, then any Vulkan targets + # Try an explicit CMake variable first, then any Vulkan paths # discovered by FindVulkan.cmake, then the $VULKAN_SDK environment # variable if nothing else works. if(VULKAN_HEADERS_INSTALL_DIR) - message(" Vulkan as path") - if(TARGET volk) - target_include_directories(volk PUBLIC "${VULKAN_HEADERS_INSTALL_DIR}/include") - endif() - target_include_directories(volk_headers INTERFACE "${VULKAN_HEADERS_INSTALL_DIR}/include") - elseif(TARGET Vulkan::Vulkan) - message(" Vulkan as target") - if(TARGET volk) - target_link_libraries(volk PUBLIC Vulkan::Vulkan) - endif() - target_link_libraries(volk_headers INTERFACE Vulkan::Vulkan) - elseif(TARGET Vulkan::Headers) - message(" Vulkan headers as another cmake target") - if(TARGET volk) - target_link_libraries(volk PUBLIC Vulkan::Headers) - endif() - target_link_libraries(volk_headers INTERFACE Vulkan::Headers) + message("volk: using VULKAN_HEADERS_INSTALL_DIR option") + set(VOLK_INCLUDES "${VULKAN_HEADERS_INSTALL_DIR}/include") + elseif(Vulkan_INCLUDE_DIRS) + message("volk: using Vulkan_INCLUDE_DIRS from FindVulkan module") + set(VOLK_INCLUDES "${Vulkan_INCLUDE_DIRS}") elseif(DEFINED ENV{VULKAN_SDK}) - message(" Vulkan as VULKAN_SDK path") + message("volk: using VULKAN_SDK environment variable") + set(VOLK_INCLUDES "$ENV{VULKAN_SDK}/include") + endif() + + if(VOLK_INCLUDES) if(TARGET volk) - target_include_directories(volk PUBLIC "$ENV{VULKAN_SDK}/include") + target_include_directories(volk PUBLIC "${VOLK_INCLUDES}") endif() - target_include_directories(volk_headers INTERFACE "$ENV{VULKAN_SDK}/include") + target_include_directories(volk_headers INTERFACE "${VOLK_INCLUDES}") endif() endif()