2023-11-30 20:43:00 +00:00
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
|
|
|
|
include(gen/CurrentBuildVulkanVersion.cmake)
|
|
|
|
|
2023-09-25 00:48:10 +00:00
|
|
|
project(VulkanBootstrap
|
|
|
|
LANGUAGES CXX
|
2023-11-30 20:43:00 +00:00
|
|
|
DESCRIPTION "A Vulkan utility library to ease the initialization steps in Vulkan"
|
|
|
|
VERSION ${VK_BOOTSTRAP_SOURCE_HEADER_VERSION})
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2023-02-15 17:16:24 +00:00
|
|
|
option(VK_BOOTSTRAP_DISABLE_WARNINGS "Disable warnings during compilation" OFF)
|
2021-04-18 20:09:32 +00:00
|
|
|
option(VK_BOOTSTRAP_WERROR "Enable warnings as errors during compilation" OFF)
|
|
|
|
|
2023-11-30 20:43:00 +00:00
|
|
|
if (CMAKE_VERSION VERSION_LESS "3.21")
|
|
|
|
# By default, only build tests & install if this repo is standalone, but still allow configuration by the user
|
|
|
|
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL)
|
|
|
|
endif()
|
2021-03-02 03:59:49 +00:00
|
|
|
|
2023-11-30 20:43:00 +00:00
|
|
|
option(VK_BOOTSTRAP_TEST "Test Vk-Bootstrap using Catch2 as well as build examples" ${PROJECT_IS_TOP_LEVEL})
|
2024-02-11 18:46:39 +00:00
|
|
|
option(VK_BOOTSTRAP_INSTALL "Enable installing of vk-bootstrap" ${PROJECT_IS_TOP_LEVEL})
|
2023-11-30 20:43:00 +00:00
|
|
|
|
|
|
|
set(VK_BOOTSTRAP_VULKAN_HEADER_DIR "" CACHE FILEPATH "Specify the location of the Vulkan-Headers include directory.")
|
2021-03-02 03:59:49 +00:00
|
|
|
mark_as_advanced(VK_BOOTSTRAP_VULKAN_HEADER_DIR)
|
|
|
|
|
2023-11-30 20:43:00 +00:00
|
|
|
# Check if the user has set this variable explicitly
|
|
|
|
if(IS_DIRECTORY ${VK_BOOTSTRAP_VULKAN_HEADER_DIR})
|
|
|
|
add_library(Vulkan-Headers INTERFACE)
|
|
|
|
add_library(Vulkan::Headers ALIAS Vulkan-Headers)
|
|
|
|
target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${VK_BOOTSTRAP_VULKAN_HEADER_DIR}>)
|
2023-12-06 20:57:34 +00:00
|
|
|
# If we had to use a direct path to get the headers, disable installing
|
|
|
|
set(VK_BOOTSTRAP_INSTALL OFF)
|
2023-11-30 20:43:00 +00:00
|
|
|
# Check if the target is already defined
|
|
|
|
elseif(NOT TARGET Vulkan::Headers)
|
|
|
|
# Try looking for the VulkanHeaders package directly
|
|
|
|
find_package(VulkanHeaders CONFIG QUIET)
|
|
|
|
if (NOT VulkanHeaders_FOUND)
|
|
|
|
# Try looking using the CMake built in Vulkan support
|
|
|
|
find_package(Vulkan QUIET)
|
2023-12-14 18:20:51 +00:00
|
|
|
|
|
|
|
if(Vulkan_FOUND)
|
|
|
|
# Older CMake versions don't contain Vulkan::Headers - create it in that case
|
|
|
|
if (NOT TARGET Vulkan::Headers)
|
|
|
|
add_library(Vulkan-Headers INTERFACE)
|
|
|
|
add_library(Vulkan::Headers ALIAS Vulkan-Headers)
|
|
|
|
target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${Vulkan_INCLUDE_DIRS}>)
|
|
|
|
set(VK_BOOTSTRAP_INSTALL OFF)
|
|
|
|
endif()
|
|
|
|
else()
|
2023-11-30 20:43:00 +00:00
|
|
|
# Lastly just grab Vulkan-Headers directly using FetchContent
|
|
|
|
include(FetchContent)
|
|
|
|
FetchContent_Declare(
|
|
|
|
Vulkan-Headers-for-vk-bootstrap
|
|
|
|
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers
|
|
|
|
GIT_TAG ${VK_BOOTSTRAP_SOURCE_HEADER_VERSION_GIT_TAG}
|
|
|
|
)
|
|
|
|
FetchContent_MakeAvailable(Vulkan-Headers-for-vk-bootstrap)
|
|
|
|
# If we had to use FetchContent to get the headers, disable installing
|
|
|
|
set(VK_BOOTSTRAP_INSTALL OFF)
|
|
|
|
endif()
|
2023-09-25 00:48:10 +00:00
|
|
|
endif()
|
2021-03-01 22:21:45 +00:00
|
|
|
endif()
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2023-11-30 20:43:00 +00:00
|
|
|
if(NOT TARGET Vulkan::Headers)
|
|
|
|
message(FATAL_ERROR "Unable to locate required dependency Vulkan::Headers!")
|
|
|
|
endif()
|
2020-01-30 08:15:10 +00:00
|
|
|
|
2020-03-26 16:40:47 +00:00
|
|
|
add_library(vk-bootstrap-compiler-warnings INTERFACE)
|
2020-05-14 12:20:46 +00:00
|
|
|
|
2023-12-06 20:57:34 +00:00
|
|
|
set(VK_BOOTSTRAP_COMPILER_FRONTEND ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT})
|
|
|
|
if(NOT VK_BOOTSTRAP_COMPILER_FRONTEND)
|
|
|
|
set(VK_BOOTSTRAP_COMPILER_FRONTEND "None")
|
2020-05-14 12:20:46 +00:00
|
|
|
endif()
|
|
|
|
|
2023-02-15 16:55:36 +00:00
|
|
|
if(NOT VK_BOOTSTRAP_DISABLE_WARNINGS)
|
2023-12-06 20:57:34 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|AppleClang" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND VK_BOOTSTRAP_COMPILER_FRONTEND MATCHES "GNU"))
|
|
|
|
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE -Wall -Wextra -Wconversion -Wsign-conversion)
|
|
|
|
if(VK_BOOTSTRAP_WERROR)
|
|
|
|
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE -pedantic-errors)
|
|
|
|
endif()
|
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND VK_BOOTSTRAP_COMPILER_FRONTEND MATCHES "MSVC"))
|
|
|
|
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE /W4)
|
|
|
|
if(VK_BOOTSTRAP_WERROR)
|
|
|
|
target_compile_options(vk-bootstrap-compiler-warnings INTERFACE /WX)
|
|
|
|
endif()
|
2023-09-25 00:48:10 +00:00
|
|
|
endif()
|
2021-04-18 20:09:32 +00:00
|
|
|
endif()
|
|
|
|
|
2023-11-30 20:43:00 +00:00
|
|
|
add_library(vk-bootstrap STATIC src/VkBootstrap.h src/VkBootstrap.cpp src/VkBootstrapDispatch.h)
|
|
|
|
add_library(vk-bootstrap::vk-bootstrap ALIAS vk-bootstrap)
|
|
|
|
|
2021-03-01 17:34:23 +00:00
|
|
|
target_include_directories(vk-bootstrap PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
|
|
|
|
$<INSTALL_INTERFACE:include>)
|
2020-03-26 16:40:47 +00:00
|
|
|
target_link_libraries(vk-bootstrap
|
2023-11-30 20:43:00 +00:00
|
|
|
PUBLIC
|
|
|
|
Vulkan::Headers
|
2023-09-25 00:48:10 +00:00
|
|
|
PRIVATE
|
2021-03-01 17:28:56 +00:00
|
|
|
vk-bootstrap-compiler-warnings
|
|
|
|
${CMAKE_DL_LIBS})
|
2023-10-30 17:38:23 +00:00
|
|
|
target_compile_features(vk-bootstrap PUBLIC cxx_std_17)
|
2020-03-07 08:44:34 +00:00
|
|
|
|
2022-08-30 16:42:35 +00:00
|
|
|
if(VK_BOOTSTRAP_TEST)
|
2023-10-03 22:22:02 +00:00
|
|
|
enable_testing()
|
2020-03-26 16:40:47 +00:00
|
|
|
add_subdirectory(ext)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
add_subdirectory(example)
|
2020-03-25 18:15:36 +00:00
|
|
|
endif ()
|
2023-11-30 20:43:00 +00:00
|
|
|
|
|
|
|
if (VK_BOOTSTRAP_INSTALL)
|
|
|
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
install(FILES src/VkBootstrap.h src/VkBootstrapDispatch.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
|
|
install(
|
|
|
|
TARGETS vk-bootstrap vk-bootstrap-compiler-warnings
|
|
|
|
EXPORT vk-bootstrap-targets
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
EXPORT vk-bootstrap-targets
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vk-bootstrap
|
|
|
|
NAMESPACE vk-bootstrap::
|
|
|
|
)
|
|
|
|
|
|
|
|
# Create vk-bootstrap-config.cmake
|
|
|
|
set(VK_BOOTSTRAP_EXPORT_TARGETS ${CMAKE_INSTALL_LIBDIR}/cmake/vk-bootstrap/vk-bootstrap-targets.cmake)
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/vk-bootstrap-config.cmake.in" [=[
|
|
|
|
@PACKAGE_INIT@
|
|
|
|
|
|
|
|
# Try to find Vulkan-Headers using find_package. Assume the package is available through either Vulkan-Headers or the older Vulkan
|
|
|
|
# Package managers should have Vulkan-Headers be a dependency of this repo.
|
|
|
|
find_package(VulkanHeaders CONFIG)
|
|
|
|
if (NOT VulkanHeaders_FOUND)
|
|
|
|
find_package(Vulkan)
|
|
|
|
if (NOT Vulkan_FOUND)
|
|
|
|
message(FATAL_ERROR "Unable to locate required dependency Vulkan::Headers!")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
include(@PACKAGE_VK_BOOTSTRAP_EXPORT_TARGETS@)
|
|
|
|
]=])
|
|
|
|
|
|
|
|
configure_package_config_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/vk-bootstrap-config.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/vk-bootstrap-config.cmake
|
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vk-bootstrap
|
|
|
|
PATH_VARS VK_BOOTSTRAP_EXPORT_TARGETS
|
|
|
|
NO_SET_AND_CHECK_MACRO
|
|
|
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
|
|
|
)
|
|
|
|
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vk-bootstrap-config.cmake
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vk-bootstrap
|
|
|
|
)
|
|
|
|
|
|
|
|
endif()
|