comparison fuhtark_test/Vulkan-Headers-1.4.334/CMakeLists.txt @ 1501:f40d9d814c08 default tip main

did: correct vulkan-api generator
author sam <sam@basx.dev>
date Wed, 26 Nov 2025 23:34:29 +0700
parents
children
comparison
equal deleted inserted replaced
1500:91c8c3b7cbf0 1501:f40d9d814c08
1 # ~~~
2 # Copyright 2018-2023 The Khronos Group Inc.
3 # Copyright 2018-2023 Valve Corporation
4 # Copyright 2018-2023 LunarG, Inc.
5 #
6 # SPDX-License-Identifier: Apache-2.0
7 # ~~~
8 cmake_minimum_required(VERSION 3.22.1)
9
10 include(CMakeDependentOption)
11
12
13 # NOTE: Parsing the version like this is suboptimal but neccessary due to our release process:
14 # https://github.com/KhronosGroup/Vulkan-Headers/pull/346
15 #
16 # As shown a more robust approach would be just to add basic test code to check the project version.
17 function(vlk_get_header_version)
18 set(vulkan_core_header_file "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan_core.h")
19 if (NOT EXISTS ${vulkan_core_header_file})
20 message(FATAL_ERROR "Couldn't find vulkan_core.h!")
21 endif()
22
23 file(READ ${vulkan_core_header_file} ver)
24
25 if (ver MATCHES "#define[ ]+VK_HEADER_VERSION_COMPLETE[ ]+VK_MAKE_API_VERSION\\([ ]*[0-9]+,[ ]*([0-9]+),[ ]*([0-9]+),[ ]*VK_HEADER_VERSION[ ]*\\)")
26 set(MAJOR_VERSION "${CMAKE_MATCH_1}")
27 set(MINOR_VERSION "${CMAKE_MATCH_2}")
28 else()
29 message(FATAL_ERROR "Couldn't get major/minor version")
30 endif()
31
32 if (ver MATCHES "#define[ ]+VK_HEADER_VERSION[ ]+([0-9]+)")
33 set(PATCH_VERSION "${CMAKE_MATCH_1}")
34 else()
35 message(FATAL_ERROR "Couldn't get the patch version")
36 endif()
37
38 set(VK_VERSION_STRING "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" PARENT_SCOPE)
39 endfunction()
40 vlk_get_header_version()
41
42 project(VULKAN_HEADERS LANGUAGES C CXX VERSION ${VK_VERSION_STRING})
43
44 # options for Vulkan-Headers and the Vulkan-Hpp C++20 module
45 option(VULKAN_HEADERS_ENABLE_TESTS "Test Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})
46 option(VULKAN_HEADERS_ENABLE_INSTALL "Install Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})
47 cmake_dependent_option(VULKAN_HEADERS_ENABLE_MODULE "Build and install the Vulkan-Hpp C++20 module" ON [[TARGET __CMAKE::CXX23]] OFF)
48 # This CMake target is only available when the entire stack (CMake, compiler, standard library) supports C++20 modules and supports importing the standard library as a module.
49 # See https://gitlab.kitware.com/ben.boeckel/cmake/-/blob/cxxmodules-docs/Help/manual/cmake-cxxmodules.7.rst?ref_type=heads&plain=1#L398
50
51 # set up Vulkan-Headers
52 add_library(Vulkan-Headers INTERFACE)
53 add_library(Vulkan::Headers ALIAS Vulkan-Headers)
54 target_include_directories(Vulkan-Headers INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
55
56 if (VULKAN_HEADERS_ENABLE_MODULE)
57 add_library(Vulkan-HppModule OBJECT)
58 add_library(Vulkan::HppModule ALIAS Vulkan-HppModule)
59 target_sources(Vulkan-HppModule PUBLIC
60 FILE_SET CXX_MODULES
61 BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
62 FILES
63 "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan.cppm"
64 "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan_video.cppm")
65
66 target_compile_features(Vulkan-HppModule PUBLIC cxx_std_23) # C++23 is required for both the standard library module, and other details of Vulkan-Hpp such as std::expected
67 set_target_properties(Vulkan-HppModule PROPERTIES CXX_MODULE_STD ON)
68 target_link_libraries(Vulkan-HppModule PUBLIC Vulkan::Headers)
69
70 # set up fallback targets to notify about name deprecation
71 add_library(Vulkan-Module INTERFACE)
72 add_library(Vulkan::Module ALIAS Vulkan-Module)
73 target_link_libraries(Vulkan-Module INTERFACE Vulkan::HppModule)
74 set_target_properties(Vulkan-Module PROPERTIES
75 DEPRECATION "The Vulkan-Module and Vulkan::Module targets have been deprecated by the Vulkan-HppModule and Vulkan::HppModule targets respectively and will be removed at a future date."
76 )
77 endif()
78
79 if (VULKAN_HEADERS_ENABLE_TESTS)
80 enable_testing() # This is only effective in the top level CMakeLists.txt file.
81 add_subdirectory(tests)
82 endif()
83
84 if (VULKAN_HEADERS_ENABLE_INSTALL)
85 include(GNUInstallDirs)
86 include(CMakePackageConfigHelpers)
87
88 # Remove the module interface files from the header target if the named module installation is ENABLED.
89 # This ensures that the module interface files are only installed once.
90 if(VULKAN_HEADERS_ENABLE_MODULE)
91 set(CPPM_PATTERN "*.cppm")
92 else()
93 set(CPPM_PATTERN "")
94 endif()
95
96 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vk_video" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "${CPPM_PATTERN}" EXCLUDE)
97 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "${CPPM_PATTERN}" EXCLUDE)
98 # Preserve source permissions https://github.com/KhronosGroup/Vulkan-Headers/issues/336
99 install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION "${CMAKE_INSTALL_DATADIR}/vulkan" USE_SOURCE_PERMISSIONS PATTERN "${CPPM_PATTERN}" EXCLUDE)
100
101 set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
102 install(TARGETS Vulkan-Headers
103 EXPORT VulkanHeadersConfig
104 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
105
106 # Install the C++ module target and export it
107 if (VULKAN_HEADERS_ENABLE_MODULE)
108 set_target_properties(Vulkan-HppModule PROPERTIES EXPORT_NAME "HppModule")
109 install(TARGETS Vulkan-HppModule
110 EXPORT VulkanHeadersConfig
111 FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
112 install(EXPORT VulkanHeadersConfig
113 NAMESPACE "Vulkan::"
114 DESTINATION "share/cmake/VulkanHeaders"
115 CXX_MODULES_DIRECTORY "")
116 else()
117 install(EXPORT VulkanHeadersConfig
118 NAMESPACE "Vulkan::"
119 DESTINATION "share/cmake/VulkanHeaders")
120 endif()
121
122 set(version_config "${CMAKE_CURRENT_BINARY_DIR}/generated/VulkanHeadersConfigVersion.cmake")
123 write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
124 install(FILES "${version_config}" DESTINATION "share/cmake/VulkanHeaders")
125 endif()