From 2bb598acd0ac144bab6813925c3a39400e329694 Mon Sep 17 00:00:00 2001 From: Pierre Narvor Date: Tue, 14 Jun 2022 17:40:18 +0200 Subject: [PATCH] [cmake] Updated installation process to use modern CMake targets --- src/CMakeLists.txt | 7 ++++--- src/cmake/Config.cmake.in | 10 ++++++++++ src/cmake/install_target.cmake | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/cmake/Config.cmake.in create mode 100644 src/cmake/install_target.cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a14bc8a..879eaee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,9 @@ set_target_properties( CXX_STANDARD_REQUIRED ON ) -target_include_directories(VulkanMemoryAllocator PUBLIC "${PROJECT_SOURCE_DIR}/include") +target_include_directories(VulkanMemoryAllocator PUBLIC + $ +) # Only link to Vulkan if static linking is used if(${VMA_STATIC_VULKAN_FUNCTIONS}) @@ -44,8 +46,7 @@ target_compile_definitions( VMA_RECORDING_ENABLED=$ ) -install(TARGETS VulkanMemoryAllocator DESTINATION "lib") -install(FILES "${PROJECT_SOURCE_DIR}/include/vk_mem_alloc.h" DESTINATION "include") +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_target.cmake) if(VMA_BUILD_SAMPLE) if(WIN32) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in new file mode 100644 index 0000000..a7d7543 --- /dev/null +++ b/src/cmake/Config.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +find_package(Vulkan REQUIRED) + +include("${CMAKE_CURRENT_LIST_DIR}/VulkanMemoryAllocatorTargets.cmake") +check_required_components("@PROJECT_NAME@") + + diff --git a/src/cmake/install_target.cmake b/src/cmake/install_target.cmake new file mode 100644 index 0000000..6ddd455 --- /dev/null +++ b/src/cmake/install_target.cmake @@ -0,0 +1,32 @@ +include(GNUInstallDirs) +target_include_directories(VulkanMemoryAllocator PUBLIC + $ +) +install(TARGETS VulkanMemoryAllocator + EXPORT VulkanMemoryAllocatorTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +# install(FILES "${PROJECT_SOURCE_DIR}/include/vk_mem_alloc.h" DESTINATION "include") +install(FILES "${PROJECT_SOURCE_DIR}/include/vk_mem_alloc.h" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(EXPORT VulkanMemoryAllocatorTargets + FILE VulkanMemoryAllocatorTargets.cmake + NAMESPACE VulkanMemoryAllocator:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/VulkanMemoryAllocator +) +include(CMakePackageConfigHelpers) +configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/Config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/VulkanMemoryAllocatorConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/VulkanMemoryAllocator +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/VulkanMemoryAllocatorConfig.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/VulkanMemoryAllocator +) + + +