mirror of
https://github.com/KhronosGroup/Vulkan-Headers
synced 2024-11-21 14:29:07 -07:00
b379292b2a
Some checks failed
ci / cmake-unix (3.15, macos-latest) (push) Has been cancelled
ci / cmake-unix (3.15, ubuntu-latest) (push) Has been cancelled
ci / cmake-unix (latest, macos-latest) (push) Has been cancelled
ci / cmake-unix (latest, ubuntu-latest) (push) Has been cancelled
ci / cmake-windows (3.15) (push) Has been cancelled
ci / cmake-windows (latest) (push) Has been cancelled
ci / windows_clang (clang) (push) Has been cancelled
ci / windows_clang (clang-cl) (push) Has been cancelled
ci / reuse (push) Has been cancelled
clang ships the clang-scan-deps tool separately from the compiler, making it possible that the clang compiler supports modules but cannot be used by CMake for VulkanHppModule. The straightforward solution is to, when using clang, check that the scan deps tools was located. This prevents people who are using clang but not the modules from being unable to use Vulkan-Headers when the clang-scan-deps tools is missing.
101 lines
4.5 KiB
CMake
101 lines
4.5 KiB
CMake
# ~~~
|
|
# Copyright 2018-2023 The Khronos Group Inc.
|
|
# Copyright 2018-2023 Valve Corporation
|
|
# Copyright 2018-2023 LunarG, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
# ~~~
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
# NOTE: Parsing the version like this is suboptimal but neccessary due to our release process:
|
|
# https://github.com/KhronosGroup/Vulkan-Headers/pull/346
|
|
#
|
|
# As shown a more robust approach would be just to add basic test code to check the project version.
|
|
function(vlk_get_header_version)
|
|
set(vulkan_core_header_file "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan_core.h")
|
|
if (NOT EXISTS ${vulkan_core_header_file})
|
|
message(FATAL_ERROR "Couldn't find vulkan_core.h!")
|
|
endif()
|
|
|
|
file(READ ${vulkan_core_header_file} ver)
|
|
|
|
if (ver MATCHES "#define[ ]+VK_HEADER_VERSION_COMPLETE[ ]+VK_MAKE_API_VERSION\\([ ]*[0-9]+,[ ]*([0-9]+),[ ]*([0-9]+),[ ]*VK_HEADER_VERSION[ ]*\\)")
|
|
set(MAJOR_VERSION "${CMAKE_MATCH_1}")
|
|
set(MINOR_VERSION "${CMAKE_MATCH_2}")
|
|
else()
|
|
message(FATAL_ERROR "Couldn't get major/minor version")
|
|
endif()
|
|
|
|
if (ver MATCHES "#define[ ]+VK_HEADER_VERSION[ ]+([0-9]+)")
|
|
set(PATCH_VERSION "${CMAKE_MATCH_1}")
|
|
else()
|
|
message(FATAL_ERROR "Couldn't get the patch version")
|
|
endif()
|
|
|
|
set(VK_VERSION_STRING "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" PARENT_SCOPE)
|
|
endfunction()
|
|
vlk_get_header_version()
|
|
|
|
project(VULKAN_HEADERS LANGUAGES C CXX VERSION ${VK_VERSION_STRING})
|
|
|
|
add_library(Vulkan-Headers INTERFACE)
|
|
add_library(Vulkan::Headers ALIAS Vulkan-Headers)
|
|
target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
|
|
|
if (MSVC AND (MSVC_VERSION GREATER_EQUAL "1941") OR
|
|
# clang-cl doesn't currently support modules
|
|
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
|
|
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16.0"
|
|
AND (NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
|
|
AND (NOT CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS STREQUAL CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-NOTFOUND)) OR
|
|
(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0"))
|
|
set(COMPILER_SUPPORTS_CXX_MODULES TRUE)
|
|
endif()
|
|
|
|
option(VULKAN_HEADERS_ENABLE_MODULE "Enables building of the Vulkan C++ module. Default is true if supported by the CMake version and compilers" ${COMPILER_SUPPORTS_CXX_MODULES})
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28" AND VULKAN_HEADERS_ENABLE_MODULE)
|
|
add_library(Vulkan-Module)
|
|
add_library(Vulkan::VulkanHppModule ALIAS Vulkan-Module)
|
|
target_sources(Vulkan-Module
|
|
PUBLIC
|
|
FILE_SET module
|
|
TYPE CXX_MODULES
|
|
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
FILES "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan.cppm"
|
|
)
|
|
target_compile_features(Vulkan-Module PUBLIC cxx_std_20)
|
|
target_link_libraries(Vulkan-Module PUBLIC Vulkan-Headers)
|
|
endif ()
|
|
|
|
if (CMAKE_VERSION VERSION_LESS "3.21")
|
|
# 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)
|
|
endif()
|
|
|
|
option(VULKAN_HEADERS_ENABLE_TESTS "Test Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})
|
|
option(VULKAN_HEADERS_ENABLE_INSTALL "Install Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})
|
|
|
|
if (VULKAN_HEADERS_ENABLE_TESTS)
|
|
enable_testing() # This is only effective in the top level CMakeLists.txt file.
|
|
add_subdirectory(tests)
|
|
endif()
|
|
|
|
if (VULKAN_HEADERS_ENABLE_INSTALL)
|
|
include(GNUInstallDirs)
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vk_video" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
# Preserve source permissions https://github.com/KhronosGroup/Vulkan-Headers/issues/336
|
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan" USE_SOURCE_PERMISSIONS)
|
|
|
|
set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
|
|
install(TARGETS Vulkan-Headers EXPORT VulkanHeadersConfig INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
install(EXPORT VulkanHeadersConfig NAMESPACE "Vulkan::" DESTINATION "share/cmake/VulkanHeaders")
|
|
|
|
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/generated/VulkanHeadersConfigVersion.cmake")
|
|
write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
|
|
install(FILES "${version_config}" DESTINATION "share/cmake/VulkanHeaders")
|
|
endif()
|