diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cbcbdd..553822f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,6 @@ cmake_minimum_required(VERSION 3.9) project(VulkanMemoryAllocator LANGUAGES CXX) -# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html -string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL) - -if(PROJECT_IS_TOP_LEVEL) - find_package(Vulkan REQUIRED) - include_directories(${Vulkan_INCLUDE_DIR}) -endif() - # VulkanMemoryAllocator contains an sample application which is not built by default option(VMA_BUILD_SAMPLE "Build VulkanMemoryAllocator sample application" OFF) option(VMA_BUILD_SAMPLE_SHADERS "Build VulkanMemoryAllocator sample application's shaders" OFF) @@ -31,6 +23,12 @@ message(STATUS "VMA_DEBUG_INITIALIZE_ALLOCATIONS = ${VMA_DEBUG_INITIALIZE_ALLOCA message(STATUS "VMA_DEBUG_GLOBAL_MUTEX = ${VMA_DEBUG_GLOBAL_MUTEX}") message(STATUS "VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT = ${VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT}") +if(VMA_STATIC_VULKAN_FUNCTIONS OR VMA_BUILD_SAMPLE) + find_package(Vulkan REQUIRED) +else() + find_package(VulkanHeaders REQUIRED) +endif() + if(VMA_BUILD_SAMPLE) set(VMA_BUILD_SAMPLE_SHADERS ON) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 659382f..19e585c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,9 +26,11 @@ target_include_directories(VulkanMemoryAllocator PUBLIC $ ) -# Only link to Vulkan if static linking is used -if(${VMA_STATIC_VULKAN_FUNCTIONS}) +# Only link to Vulkan library if static linking is used, but always add Vulkan headers directory +if(VMA_STATIC_VULKAN_FUNCTIONS) target_link_libraries(VulkanMemoryAllocator PUBLIC Vulkan::Vulkan) +else() + target_link_libraries(VulkanMemoryAllocator PUBLIC Vulkan::Headers) endif() target_compile_definitions( diff --git a/src/cmake/install_target.cmake b/src/cmake/install_target.cmake index 6ddd455..22415c8 100644 --- a/src/cmake/install_target.cmake +++ b/src/cmake/install_target.cmake @@ -27,6 +27,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/VulkanMemoryAllocatorConfig.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/VulkanMemoryAllocator ) +add_library(VulkanMemoryAllocator::VulkanMemoryAllocator ALIAS VulkanMemoryAllocator)