Skip to content

Commit

Permalink
CMake: Fix include path discovery when using FindVulkan.cmake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zeux committed Aug 4, 2023
1 parent 7d1780e commit 3f3e0cb
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 3f3e0cb

Please sign in to comment.