|
| 1 | +# This script checks for vulkan.cppm files and fixes them if they have the old format |
| 2 | +# without direct imports from the detail namespace |
| 3 | + |
| 4 | +# Function to fix a vulkan.cppm file |
| 5 | +function(fix_vulkan_cppm_file file_path) |
| 6 | + # Read the content of the file |
| 7 | + file(READ "${file_path}" VULKAN_CPPM_CONTENT) |
| 8 | + |
| 9 | + # Check if it's using the old format (without direct detail imports) |
| 10 | + if(VULKAN_CPPM_CONTENT MATCHES "using VULKAN_HPP_NAMESPACE::DispatchLoaderBase" AND |
| 11 | + NOT VULKAN_CPPM_CONTENT MATCHES "using VULKAN_HPP_NAMESPACE::detail::DispatchLoaderBase") |
| 12 | + message(STATUS "Fixing vulkan.cppm file at: ${file_path}") |
| 13 | + |
| 14 | + # Create a modified version that directly imports the detail symbols |
| 15 | + file(WRITE "${file_path}" |
| 16 | +"// Modified vulkan.cppm file |
| 17 | +module; |
| 18 | +#include <vulkan/vulkan.hpp> |
| 19 | +export module vulkan; |
| 20 | +export namespace vk { |
| 21 | + // Import symbols from the main namespace |
| 22 | + using namespace VULKAN_HPP_NAMESPACE; |
| 23 | +
|
| 24 | + // Import symbols from the detail namespace |
| 25 | + using VULKAN_HPP_NAMESPACE::detail::DispatchLoaderBase; |
| 26 | + using VULKAN_HPP_NAMESPACE::detail::DispatchLoaderDynamic; |
| 27 | + using VULKAN_HPP_NAMESPACE::detail::DispatchLoaderStatic; |
| 28 | + using VULKAN_HPP_NAMESPACE::detail::ObjectDestroy; |
| 29 | + using VULKAN_HPP_NAMESPACE::detail::ObjectDestroyShared; |
| 30 | + using VULKAN_HPP_NAMESPACE::detail::ObjectFree; |
| 31 | + using VULKAN_HPP_NAMESPACE::detail::ObjectFreeShared; |
| 32 | + using VULKAN_HPP_NAMESPACE::detail::ObjectRelease; |
| 33 | + using VULKAN_HPP_NAMESPACE::detail::ObjectReleaseShared; |
| 34 | + using VULKAN_HPP_NAMESPACE::detail::PoolFree; |
| 35 | + using VULKAN_HPP_NAMESPACE::detail::PoolFreeShared; |
| 36 | + using VULKAN_HPP_NAMESPACE::detail::createResultValueType; |
| 37 | + using VULKAN_HPP_NAMESPACE::detail::resultCheck; |
| 38 | + using VULKAN_HPP_NAMESPACE::detail::DynamicLoader; |
| 39 | +
|
| 40 | + // Export detail namespace for other symbols |
| 41 | + namespace detail { |
| 42 | + using namespace VULKAN_HPP_NAMESPACE::detail; |
| 43 | + } |
| 44 | +
|
| 45 | + // Export raii namespace |
| 46 | + namespace raii { |
| 47 | + using namespace VULKAN_HPP_RAII_NAMESPACE; |
| 48 | +
|
| 49 | + // Import symbols from the detail namespace |
| 50 | + using VULKAN_HPP_NAMESPACE::detail::ContextDispatcher; |
| 51 | + using VULKAN_HPP_NAMESPACE::detail::DeviceDispatcher; |
| 52 | + } |
| 53 | +} |
| 54 | +") |
| 55 | + message(STATUS "Fixed vulkan.cppm file at: ${file_path}") |
| 56 | + else() |
| 57 | + message(STATUS "vulkan.cppm file at ${file_path} already has the correct format or is not a standard vulkan.cppm file") |
| 58 | + endif() |
| 59 | +endfunction() |
| 60 | + |
| 61 | +# Check if vulkan.cppm exists in /usr/include/vulkan |
| 62 | +if(EXISTS "/usr/include/vulkan/vulkan.cppm") |
| 63 | + message(STATUS "Found vulkan.cppm in /usr/include/vulkan") |
| 64 | + |
| 65 | + # Try to fix the file directly |
| 66 | + execute_process( |
| 67 | + COMMAND ${CMAKE_COMMAND} -E echo "Checking write permission for /usr/include/vulkan/vulkan.cppm" |
| 68 | + COMMAND_ECHO STDOUT |
| 69 | + ) |
| 70 | + |
| 71 | + # Try to create a temporary file to check write permission |
| 72 | + execute_process( |
| 73 | + COMMAND ${CMAKE_COMMAND} -E touch /usr/include/vulkan/vulkan.cppm.tmp |
| 74 | + RESULT_VARIABLE WRITE_RESULT |
| 75 | + ERROR_QUIET |
| 76 | + ) |
| 77 | + |
| 78 | + if(WRITE_RESULT EQUAL 0) |
| 79 | + # We have write permission, remove the temporary file |
| 80 | + execute_process( |
| 81 | + COMMAND ${CMAKE_COMMAND} -E remove /usr/include/vulkan/vulkan.cppm.tmp |
| 82 | + ) |
| 83 | + |
| 84 | + # Fix the file directly |
| 85 | + fix_vulkan_cppm_file("/usr/include/vulkan/vulkan.cppm") |
| 86 | + else() |
| 87 | + message(STATUS "No write permission for /usr/include/vulkan/vulkan.cppm, creating a copy in the build directory") |
| 88 | + |
| 89 | + # Create a copy in the build directory that we can modify |
| 90 | + set(VULKAN_CPPM_COPY "${CMAKE_BINARY_DIR}/include/vulkan/vulkan.cppm") |
| 91 | + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/vulkan") |
| 92 | + file(COPY "/usr/include/vulkan/vulkan.cppm" DESTINATION "${CMAKE_BINARY_DIR}/include/vulkan") |
| 93 | + |
| 94 | + # Fix the copy |
| 95 | + fix_vulkan_cppm_file("${VULKAN_CPPM_COPY}") |
| 96 | + |
| 97 | + # Add the include directory to the include path |
| 98 | + include_directories(BEFORE "${CMAKE_BINARY_DIR}/include") |
| 99 | + |
| 100 | + # Set the VulkanHpp_CPPM_DIR variable |
| 101 | + set(VulkanHpp_CPPM_DIR "${CMAKE_BINARY_DIR}/include" CACHE PATH "Path to the directory containing vulkan.cppm" FORCE) |
| 102 | + endif() |
| 103 | +endif() |
| 104 | + |
| 105 | +# Check if vulkan.cppm exists in the Vulkan SDK |
| 106 | +if(DEFINED ENV{VULKAN_SDK} AND EXISTS "$ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm") |
| 107 | + message(STATUS "Found vulkan.cppm in Vulkan SDK") |
| 108 | + |
| 109 | + # Try to fix the file directly |
| 110 | + execute_process( |
| 111 | + COMMAND ${CMAKE_COMMAND} -E echo "Checking write permission for $ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm" |
| 112 | + COMMAND_ECHO STDOUT |
| 113 | + ) |
| 114 | + |
| 115 | + # Try to create a temporary file to check write permission |
| 116 | + execute_process( |
| 117 | + COMMAND ${CMAKE_COMMAND} -E touch "$ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm.tmp" |
| 118 | + RESULT_VARIABLE WRITE_RESULT |
| 119 | + ERROR_QUIET |
| 120 | + ) |
| 121 | + |
| 122 | + if(WRITE_RESULT EQUAL 0) |
| 123 | + # We have write permission, remove the temporary file |
| 124 | + execute_process( |
| 125 | + COMMAND ${CMAKE_COMMAND} -E remove "$ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm.tmp" |
| 126 | + ) |
| 127 | + |
| 128 | + # Fix the file directly |
| 129 | + fix_vulkan_cppm_file("$ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm") |
| 130 | + else() |
| 131 | + message(STATUS "No write permission for $ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm, creating a copy in the build directory") |
| 132 | + |
| 133 | + # Create a copy in the build directory that we can modify |
| 134 | + set(VULKAN_CPPM_COPY "${CMAKE_BINARY_DIR}/include/vulkan/vulkan.cppm") |
| 135 | + file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/vulkan") |
| 136 | + file(COPY "$ENV{VULKAN_SDK}/include/vulkan/vulkan.cppm" DESTINATION "${CMAKE_BINARY_DIR}/include/vulkan") |
| 137 | + |
| 138 | + # Fix the copy |
| 139 | + fix_vulkan_cppm_file("${VULKAN_CPPM_COPY}") |
| 140 | + |
| 141 | + # Add the include directory to the include path |
| 142 | + include_directories(BEFORE "${CMAKE_BINARY_DIR}/include") |
| 143 | + |
| 144 | + # Set the VulkanHpp_CPPM_DIR variable |
| 145 | + set(VulkanHpp_CPPM_DIR "${CMAKE_BINARY_DIR}/include" CACHE PATH "Path to the directory containing vulkan.cppm" FORCE) |
| 146 | + endif() |
| 147 | +endif() |
0 commit comments