Because vulkan has such a beautiful eco system with SDK libraries that are open source you can integrate that directly inside your environment. To do that I use CPM: cmake/CPM.cmake:
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)
include(${CPM_DOWNLOAD_LOCATION})```
With that you can download the lunar-G and glfw3 and other dependencies in the most recent version:
```include(cmake/CPM.cmake)
set(khronos_version v1.3.272)
set(vulkan_sdk vulkan-sdk-1.3.268.0)
CPMAddPackage(
NAME GLFW
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.3.8
OPTIONS
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BULID_DOCS OFF")
CPMAddPackage(
NAME VulkanHeaders
GITHUB_REPOSITORY KhronosGroup/Vulkan-Headers
GIT_TAG ${khronos_version}
)
# Vulkan-Headers defines a header target but not one for the module.
if(VulkanHeaders_ADDED)
add_library(VulkanModule INTERFACE)
## this only applies with gcc-14 and clang-17? and most recent cl...
##target_sources(VulkanModule
## PUBLIC FILE_SET CXX_MODULES
## BASE_DIRS "${VulkanHeaders_SOURCE_DIR}/include"
## FILES "${VulkanHeaders_SOURCE_DIR}/include/vulkan/vulkan.cppm"
## )
target_compile_features(VulkanModule INTERFACE cxx_std_23)
target_compile_definitions(VulkanModule INTERFACE
VULKAN_HPP_NO_CONSTRUCTORS=1
VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1
VULKAN_HPP_NO_STRUCT_SETTERS=1
# Your options here, project-dependent:
# https://github.com/KhronosGroup/Vulkan-Hpp#configuration-options
)
target_link_libraries(VulkanModule INTERFACE Vulkan::Headers)
endif()
CPMAddPackage(NAME robin_hood
GITHUB_REPOSITORY martinus/robin-hood-hashing
GIT_TAG 3.11.5
)
CPMAddPackage(NAME VulkanUtilityLibraries
GITHUB_REPOSITORY KhronosGroup/Vulkan-Utility-Libraries
GIT_TAG ${khronos_version}
OPTIONS
"BUILD_TESTS OFF"
"BUILD_EXAMPLES OFF"
)
CPMAddPackage(NAME SPIRV-Headers
GITHUB_REPOSITORY KhronosGroup/SPIRV-Headers
GIT_TAG ${vulkan_sdk}
)
CPMAddPackage(NAME SPIRV-Tools
GITHUB_REPOSITORY KhronosGroup/SPIRV-Tools
GIT_TAG ${vulkan_sdk}
OPTIONS
"robin_hood_DIR ${robin_hood_SOURCE_DIR}"
)
CPMAddPackage(NAME VulkanValidationLayers
GITHUB_REPOSITORY KhronosGroup/Vulkan-ValidationLayers
GIT_TAG ${khronos_version}
OPTIONS
"BUILD_TESTS OFF"
)
CPMAddPackage(NAME glslang
GITHUB_REPOSITORY KhronosGroup/glslang
GIT_TAG ${vulkan_sdk}
)
## TODO GLM is missing here
get_target_property(GLSLANG_PATH glslang-standalone BINARY_DIR)
set(GLSLANG_NAME "glslang-standalone")
get_target_property(GLSLANG_NAME glslang-standalone OUTPUT_NAME)
function(create_spirv target in)
cmake_path(GET in STEM name)
cmake_path(GET in EXTENSION ext)
if(ext STREQUAL ".frag")
set(name "${name}_frag")
elseif(ext STREQUAL ".vert")
set(name "${name}_vert")
endif()
set(out ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
set(in ${CMAKE_CURRENT_SOURCE_DIR}/${in})
add_custom_command(OUTPUT ${out}
COMMAND ${GLSLANG_PATH}/${GLSLANG_NAME} --target-env vulkan1.0 -x --vn ${name} -o ${out} ${in}
DEPENDS ${in}
glslang-standalone)
target_sources(${target} PRIVATE ${out})
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endfunction()
Because vulkan has such a beautiful eco system with SDK libraries that are open source you can integrate that directly inside your environment. To do that I use CPM: cmake/CPM.cmake: