Reputation: 59
I am currently trying to link vulkan to my project in CMake. I want to download the VulkanSDK with CMake without depending anything but CMake.
I tried to use FetchContent but it only downloads the header files of VulkanSDK. I tried to use ExternalProject but somehow it does the same thing as FetchContent.
I dont not even start implementing a script to download dxcompilerd, glslangd, shaderc_combinedd, spirv-cross-cored etc.
Test for ExternalProject
include(FetchContent)
include(ExternalProject)
set(VULKAN_VER_MAJOR 1)
set(VULKAN_VER_MINOR 3)
set(VULKAN_VER_PATCH 275)
set(VULKAN_VERSION ${VULKAN_VER_MAJOR}.${VULKAN_VER_MINOR}.${VULKAN_VER_PATCH})
ExternalProject_Add(
vulkan
PREFIX Vulkan
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
GIT_TAG v${VULKAN_VERSION}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
ExternalProject_Get_Property(vulkan SOURCE_DIR)
include_directories(${SOURCE_DIR}/include)
add_library(Vulkan INTERFACE)
add_dependencies(Vulkan vulkan)
# Add source to this project's executable.
add_executable (VulkanTest "VulkanTest.cpp" "VulkanTest.h")
target_link_libraries(VulkanTest Vulkan)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET VulkanTest PROPERTY CXX_STANDARD 20)
endif()
Test for FetchContent
include(FetchContent)
set(VULKAN_VER_MAJOR 1)
set(VULKAN_VER_MINOR 3)
set(VULKAN_VER_PATCH 275)
set(VULKAN_VERSION ${VULKAN_VER_MAJOR}.${VULKAN_VER_MINOR}.${VULKAN_VER_PATCH})
FetchContent_Declare(
vulkanheaders
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
GIT_TAG v${VULKAN_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_Declare(
vulkanloader
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Loader.git
GIT_TAG v${VULKAN_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_Declare(
vulkanvalidation
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-ValidationLayers.git
GIT_TAG v${VULKAN_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_Declare(
vulkantools
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Tools.git
GIT_TAG v${VULKAN_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
set(PROJECT_IS_TOP_LEVEL OFF)
FetchContent_MakeAvailable(vulkanheaders)
FetchContent_MakeAvailable(vulkanloader)
FetchContent_MakeAvailable(vulkanvalidation)
FetchContent_MakeAvailable(vulkantools)
add_library(myvulkan INTERFACE IMPORTED)
target_include_directories(myvulkan INTERFACE ${vulkan_headers_SOURCE_DIR}/include
${vulkan_loader_SOURCE_DIR}/loader
${vulkan_validation_layers_SOURCE_DIR}/layers
${vulkan_tools_SOURCE_DIR}/vulkaninfo)
target_link_libraries(myvulkan INTERFACE Vulkan::Vulkan)
target_link_libraries(myvulkan INTERFACE
Vulkan::Loader
Vulkan::ValidationLayers
)
# Add source to this project's executable.
add_executable (VulkanTest "VulkanTest.cpp" "VulkanTest.h")
target_link_libraries(VulkanTest PRIVATE myvulkan)
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET VulkanTest PROPERTY CXX_STANDARD 20)
endif()
What should I do to make vulkan sdk ready for my project without depending on manually downloading it?
Upvotes: 1
Views: 143
Reputation: 29240
The Khronos official Vulkan samples repository already builds without requiring you to download the SDK.
It does this by including a bunch of other repositories as Git submodules but you could accomplish the same thing with FetchContent
.
However, if you want a more detailed answer you're going to need to be more explicit about what's not working.
Upvotes: 1