181 lines
6.7 KiB
CMake
181 lines
6.7 KiB
CMake
macro(Vulkan_isDeviceFunction outVar funcName funcParams)
|
|||
|
|
string(FIND "${funcParams}" "VkDevice" out1)
|
||
|
|
if(("${out1}" EQUAL 0) AND NOT("${funcName}" STREQUAL "PFN_vkGetDeviceProcAddr"))
|
||
|
|
set(${outVar} 1)
|
||
|
|
else()
|
||
|
|
set(${outVar} 0)
|
||
|
|
endif()
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
macro(Vulkan_isDeviceCmdFunction outVar funcName funcParams)
|
||
|
|
string(FIND "${funcParams}" "VkCommandBuffer" out1)
|
||
|
|
if("${out1}" EQUAL 0)
|
||
|
|
set(${outVar} 1)
|
||
|
|
else()
|
||
|
|
set(${outVar} 0)
|
||
|
|
endif()
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
macro(Vulkan_isDeviceQueueFunction outVar funcName funcParams)
|
||
|
|
string(FIND "${funcParams}" "VkQueue" out1)
|
||
|
|
if("${out1}" EQUAL 0)
|
||
|
|
set(${outVar} 1)
|
||
|
|
else()
|
||
|
|
set(${outVar} 0)
|
||
|
|
endif()
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
macro(Vulkan_isInstanceFunction outVar funcName funcParams)
|
||
|
|
string(FIND "${funcParams}" "VkInstance" out1)
|
||
|
|
string(FIND "${funcParams}" "VkPhysicalDevice" out2)
|
||
|
|
if(("${out1}" EQUAL 0) OR ("${out2}" EQUAL 0) OR ("${funcName}" STREQUAL "PFN_vkGetDeviceProcAddr"))
|
||
|
|
set(${outVar} 1)
|
||
|
|
else()
|
||
|
|
set(${outVar} 0)
|
||
|
|
endif()
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
macro(Vulkan_isGlobalFunction outVar funcName funcParams)
|
||
|
|
if(NOT(${funcName} MATCHES ".*MyFolderName$") AND NOT(${funcName} MATCHES ".*Function$") AND NOT(${funcName} MATCHES ".*Notification$"))
|
||
|
|
set(${outVar} 1)
|
||
|
|
else()
|
||
|
|
set(${outVar} 0)
|
||
|
|
endif()
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
set(Vulkan_paramNameRegex "([^* ]+)[ ]*$")
|
||
|
|
set(Vulkan_paramSplitFirstRestRegex "([ ]*[^,]+)[ ]*\,*[ ]*(.*)")
|
||
|
|
|
||
|
|
macro(Vulkan_functionsFile_function className funcResultType funcName funcParams contextVarName)
|
||
|
|
string(REPLACE "PFN_" "" cleanFuncName ${funcName})
|
||
|
|
|
||
|
|
string(APPEND ${className}Loaders " _${cleanFuncName} = reinterpret_cast<${funcName}>(loader(\"${cleanFuncName}\"))\;\n" )
|
||
|
|
|
||
|
|
set(callArgs "")
|
||
|
|
if (NOT("${contextVarName}" STREQUAL ""))
|
||
|
|
string(REGEX MATCH "${Vulkan_paramSplitFirstRestRegex}" matchResultVar "${funcParams}")
|
||
|
|
set(InputCallParams "${CMAKE_MATCH_2}")
|
||
|
|
list(APPEND callArgs "_${contextVarName}")
|
||
|
|
else()
|
||
|
|
set(InputCallParams "${funcParams}")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
string(APPEND ${className}Pointers " ${funcName} _${cleanFuncName}\;\n")
|
||
|
|
|
||
|
|
string(REPLACE "," ";" SplittedParams "${InputCallParams}")
|
||
|
|
foreach(param ${SplittedParams})
|
||
|
|
string(REGEX MATCH "${Vulkan_paramNameRegex}" matchResultVar "${param}")
|
||
|
|
set(ParamName ${CMAKE_MATCH_1})
|
||
|
|
|
||
|
|
#Clean param name
|
||
|
|
string(REGEX MATCH "[ ]*([^ \[]+)" matchResultVar "${ParamName}")
|
||
|
|
#[ ]*([^ ]+)[ ]*\[.\]*[ ]*$
|
||
|
|
list(APPEND callArgs ${CMAKE_MATCH_1})
|
||
|
|
endforeach()
|
||
|
|
|
||
|
|
list(JOIN callArgs ", " callArgsStr)
|
||
|
|
|
||
|
|
if("${funcResultType}" STREQUAL "void")
|
||
|
|
set(returnString "")
|
||
|
|
else()
|
||
|
|
set(returnString "return ")
|
||
|
|
endif()
|
||
|
|
string(APPEND ${className}Functions " ${funcResultType} ${cleanFuncName}(${InputCallParams}) const {\n")
|
||
|
|
string(APPEND ${className}Functions " ${returnString}_${cleanFuncName}(${callArgsStr})\;\n")
|
||
|
|
string(APPEND ${className}Functions " }\n")
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
macro(Vulkan_functionsFile_make className contextVarName contextVarType outFilePath )
|
||
|
|
#File begin
|
||
|
|
set(${className}Result "")
|
||
|
|
string(APPEND ${className}Result "#pragma once\n")
|
||
|
|
string(APPEND ${className}Result "#include <vulkan/vulkan.h>\n")
|
||
|
|
string(APPEND ${className}Result "#include <functional>\n")
|
||
|
|
#string(APPEND ${className}Result "#include \"VulkanInstance.h\"\n")
|
||
|
|
string(APPEND ${className}Result "class ${className} { \n")
|
||
|
|
|
||
|
|
#File constructor
|
||
|
|
string(APPEND ${className}Result "public:\n")
|
||
|
|
if (NOT("${contextVarType}" STREQUAL ""))
|
||
|
|
set(ctroArgSuffix ", ${contextVarType} ${contextVarName}")
|
||
|
|
set(CtorInit " : _${contextVarName}(${contextVarName})")
|
||
|
|
else()
|
||
|
|
set(ctroArgSuffix "")
|
||
|
|
set(CtorInit "")
|
||
|
|
endif()
|
||
|
|
string(APPEND ${className}Result " ${className}(std::function<void*(const char*)> loader${ctroArgSuffix})${CtorInit}{\n")
|
||
|
|
string(APPEND ${className}Result "${${className}Loaders}\n")
|
||
|
|
string(APPEND ${className}Result " }\n")
|
||
|
|
string(APPEND ${className}Result " ${className}(){}\n")
|
||
|
|
|
||
|
|
|
||
|
|
#Public functions
|
||
|
|
string(APPEND ${className}Result "${${className}Functions}\n")
|
||
|
|
#Private fields
|
||
|
|
string(APPEND ${className}Result "private:\n")
|
||
|
|
string(APPEND ${className}Result "${${className}Pointers}\n")
|
||
|
|
|
||
|
|
#Context object
|
||
|
|
if (NOT("${contextVarType}" STREQUAL ""))
|
||
|
|
string(APPEND ${className}Result " ${contextVarType} _${contextVarName} = {}\;\n")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
#File end
|
||
|
|
string(APPEND ${className}Result "}\;\n") #End class
|
||
|
|
|
||
|
|
#File save
|
||
|
|
file(WRITE "${outFilePath}" ${${className}Result})
|
||
|
|
endmacro()
|
||
|
|
|
||
|
|
function(Vulkan_generateFunctionsFile outFileDir)
|
||
|
|
set(VULKAN_CORE_H "${Vulkan_INCLUDE_DIR}/vulkan/vulkan_core.h")
|
||
|
|
file(STRINGS "${VULKAN_CORE_H}" VULKAN_CORE_H_STRINGS)
|
||
|
|
|
||
|
|
|
||
|
|
foreach(STR ${VULKAN_CORE_H_STRINGS})
|
||
|
|
string(REGEX MATCH ".*typedef[ ]+([^ ]+)[ ]+\\([ ]*VKAPI_PTR[ ]+\\*([^\\)]+)\\)[ ]*\\(([^\\)]+)\\)" matchResultVar "${STR}")
|
||
|
|
if(NOT("${CMAKE_MATCH_2}" STREQUAL ""))
|
||
|
|
set(FN_RESULT "${CMAKE_MATCH_1}")
|
||
|
|
set(FN_NAME "${CMAKE_MATCH_2}")
|
||
|
|
set(FN_PARAMS "${CMAKE_MATCH_3}")
|
||
|
|
|
||
|
|
Vulkan_isDeviceFunction("found" "${FN_NAME}" "${FN_PARAMS}")
|
||
|
|
if("${found}" EQUAL 1)
|
||
|
|
Vulkan_functionsFile_function(VulkanDeviceFunctions "${FN_RESULT}" "${FN_NAME}" "${FN_PARAMS}" "device")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
Vulkan_isDeviceCmdFunction("found" "${FN_NAME}" "${FN_PARAMS}")
|
||
|
|
if("${found}" EQUAL 1)
|
||
|
|
Vulkan_functionsFile_function(VulkanDeviceFunctions "${FN_RESULT}" "${FN_NAME}" "${FN_PARAMS}" "")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
Vulkan_isDeviceQueueFunction("found" "${FN_NAME}" "${FN_PARAMS}")
|
||
|
|
if("${found}" EQUAL 1)
|
||
|
|
Vulkan_functionsFile_function(VulkanDeviceFunctions "${FN_RESULT}" "${FN_NAME}" "${FN_PARAMS}" "")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
Vulkan_isInstanceFunction("found" "${FN_NAME}" "${FN_PARAMS}")
|
||
|
|
if("${found}" EQUAL 1)
|
||
|
|
Vulkan_functionsFile_function(VulkanInstanceFunctions "${FN_RESULT}" "${FN_NAME}" "${FN_PARAMS}" "")
|
||
|
|
endif()
|
||
|
|
|
||
|
|
Vulkan_isGlobalFunction("found" "${FN_NAME}" "${FN_PARAMS}")
|
||
|
|
if("${found}" EQUAL 1)
|
||
|
|
Vulkan_functionsFile_function(VulkanGlobalFunctions "${FN_RESULT}" "${FN_NAME}" "${FN_PARAMS}" "")
|
||
|
|
endif()
|
||
|
|
endif()
|
||
|
|
endforeach()
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
Vulkan_functionsFile_make(VulkanDeviceFunctions "device" "VkDevice" "${outFileDir}/VulkanDeviceFunctions.h")
|
||
|
|
Vulkan_functionsFile_make(VulkanInstanceFunctions "" "" "${outFileDir}/VulkanInstanceFunctions.h")
|
||
|
|
Vulkan_functionsFile_make(VulkanGlobalFunctions "" "" "${outFileDir}/VulkanGlobalFunctions.h")
|
||
|
|
|
||
|
|
endfunction()
|