mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-13 19:01:24 +00:00
401 lines
15 KiB
CMake
401 lines
15 KiB
CMake
# Copyright 2017 The NXT Authors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
set(BACKEND_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
set(D3D12_DIR ${CMAKE_CURRENT_SOURCE_DIR}/d3d12)
|
|
set(METAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/metal)
|
|
set(NULL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/null)
|
|
set(OPENGL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opengl)
|
|
set(VULKAN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan)
|
|
|
|
################################################################################
|
|
# OpenGL Backend
|
|
################################################################################
|
|
|
|
if (NXT_ENABLE_OPENGL)
|
|
Generate(
|
|
LIB_NAME opengl_autogen
|
|
LIB_TYPE STATIC
|
|
FOLDER "backend"
|
|
PRINT_NAME "OpenGL backend autogenerated files"
|
|
COMMAND_LINE_ARGS
|
|
${GENERATOR_COMMON_ARGS}
|
|
-T opengl
|
|
)
|
|
target_link_libraries(opengl_autogen glfw glad nxtcpp)
|
|
target_include_directories(opengl_autogen PRIVATE ${SRC_DIR})
|
|
target_include_directories(opengl_autogen PUBLIC ${GENERATED_DIR})
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${OPENGL_DIR}/BlendStateGL.cpp
|
|
${OPENGL_DIR}/BlendStateGL.h
|
|
${OPENGL_DIR}/BufferGL.cpp
|
|
${OPENGL_DIR}/BufferGL.h
|
|
${OPENGL_DIR}/CommandBufferGL.cpp
|
|
${OPENGL_DIR}/CommandBufferGL.h
|
|
${OPENGL_DIR}/ComputePipelineGL.cpp
|
|
${OPENGL_DIR}/ComputePipelineGL.h
|
|
${OPENGL_DIR}/DepthStencilStateGL.cpp
|
|
${OPENGL_DIR}/DepthStencilStateGL.h
|
|
${OPENGL_DIR}/InputStateGL.cpp
|
|
${OPENGL_DIR}/InputStateGL.h
|
|
${OPENGL_DIR}/OpenGLBackend.cpp
|
|
${OPENGL_DIR}/OpenGLBackend.h
|
|
${OPENGL_DIR}/PersistentPipelineStateGL.cpp
|
|
${OPENGL_DIR}/PersistentPipelineStateGL.h
|
|
${OPENGL_DIR}/PipelineGL.cpp
|
|
${OPENGL_DIR}/PipelineGL.h
|
|
${OPENGL_DIR}/PipelineLayoutGL.cpp
|
|
${OPENGL_DIR}/PipelineLayoutGL.h
|
|
${OPENGL_DIR}/RenderPipelineGL.cpp
|
|
${OPENGL_DIR}/RenderPipelineGL.h
|
|
${OPENGL_DIR}/SamplerGL.cpp
|
|
${OPENGL_DIR}/SamplerGL.h
|
|
${OPENGL_DIR}/ShaderModuleGL.cpp
|
|
${OPENGL_DIR}/ShaderModuleGL.h
|
|
${OPENGL_DIR}/SwapChainGL.cpp
|
|
${OPENGL_DIR}/SwapChainGL.h
|
|
${OPENGL_DIR}/TextureGL.cpp
|
|
${OPENGL_DIR}/TextureGL.h
|
|
)
|
|
endif()
|
|
|
|
################################################################################
|
|
# Null Backend
|
|
################################################################################
|
|
|
|
if (NXT_ENABLE_NULL)
|
|
Generate(
|
|
LIB_NAME null_autogen
|
|
LIB_TYPE STATIC
|
|
FOLDER "backend"
|
|
PRINT_NAME "Null backend autogenerated files"
|
|
COMMAND_LINE_ARGS
|
|
${GENERATOR_COMMON_ARGS}
|
|
-T null
|
|
)
|
|
target_link_libraries(null_autogen nxtcpp)
|
|
target_include_directories(null_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_include_directories(null_autogen PUBLIC ${SRC_DIR})
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${NULL_DIR}/NullBackend.cpp
|
|
${NULL_DIR}/NullBackend.h
|
|
)
|
|
endif()
|
|
|
|
################################################################################
|
|
# Metal Backend
|
|
################################################################################
|
|
|
|
if (NXT_ENABLE_METAL)
|
|
Generate(
|
|
LIB_NAME metal_autogen
|
|
LIB_TYPE STATIC
|
|
FOLDER "backend"
|
|
PRINT_NAME "Metal backend autogenerated files"
|
|
COMMAND_LINE_ARGS
|
|
${GENERATOR_COMMON_ARGS}
|
|
-T metal
|
|
)
|
|
target_link_libraries(metal_autogen glfw glad nxtcpp "-framework QuartzCore" "-framework Metal")
|
|
target_include_directories(metal_autogen PRIVATE ${SRC_DIR})
|
|
target_include_directories(metal_autogen PUBLIC ${GENERATED_DIR})
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${METAL_DIR}/BlendStateMTL.mm
|
|
${METAL_DIR}/BlendStateMTL.h
|
|
${METAL_DIR}/BufferMTL.mm
|
|
${METAL_DIR}/BufferMTL.h
|
|
${METAL_DIR}/CommandBufferMTL.mm
|
|
${METAL_DIR}/CommandBufferMTL.h
|
|
${METAL_DIR}/ComputePipelineMTL.mm
|
|
${METAL_DIR}/ComputePipelineMTL.h
|
|
${METAL_DIR}/DepthStencilStateMTL.mm
|
|
${METAL_DIR}/DepthStencilStateMTL.h
|
|
${METAL_DIR}/InputStateMTL.mm
|
|
${METAL_DIR}/InputStateMTL.h
|
|
${METAL_DIR}/MetalBackend.mm
|
|
${METAL_DIR}/MetalBackend.h
|
|
${METAL_DIR}/PipelineLayoutMTL.mm
|
|
${METAL_DIR}/PipelineLayoutMTL.h
|
|
${METAL_DIR}/RenderPipelineMTL.mm
|
|
${METAL_DIR}/RenderPipelineMTL.h
|
|
${METAL_DIR}/ResourceUploader.mm
|
|
${METAL_DIR}/ResourceUploader.h
|
|
${METAL_DIR}/SamplerMTL.mm
|
|
${METAL_DIR}/SamplerMTL.h
|
|
${METAL_DIR}/ShaderModuleMTL.mm
|
|
${METAL_DIR}/ShaderModuleMTL.h
|
|
${METAL_DIR}/SwapChainMTL.mm
|
|
${METAL_DIR}/SwapChainMTL.h
|
|
${METAL_DIR}/TextureMTL.mm
|
|
${METAL_DIR}/TextureMTL.h
|
|
)
|
|
endif()
|
|
|
|
################################################################################
|
|
# D3D12 Backend
|
|
################################################################################
|
|
|
|
if (NXT_ENABLE_D3D12)
|
|
Generate(
|
|
LIB_NAME d3d12_autogen
|
|
LIB_TYPE STATIC
|
|
FOLDER "backend"
|
|
PRINT_NAME "D3D12 backend autogenerated files"
|
|
COMMAND_LINE_ARGS
|
|
${GENERATOR_COMMON_ARGS}
|
|
-T d3d12
|
|
)
|
|
# WIN10_SDK_PATH will be something like C:\Program Files (x86)\Windows Kits\10
|
|
get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;InstallationFolder]" ABSOLUTE CACHE)
|
|
|
|
# TEMP_WIN10_SDK_VERSION will be something like ${CMAKE_CURRENT_SOURCE_DIR}\10.0.14393 or ${CMAKE_CURRENT_SOURCE_DIR}\10.0.14393.0
|
|
get_filename_component(TEMP_WIN10_SDK_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;ProductVersion]" ABSOLUTE CACHE)
|
|
|
|
# strip off ${CMAKE_CURRENT_SOURCE_DIR} to get just the version number
|
|
get_filename_component(WIN10_SDK_VERSION ${TEMP_WIN10_SDK_VERSION} NAME)
|
|
# WIN10_SDK_VERSION will be something like 10.0.14393 or 10.0.14393.0; we need the one that matches the directory name.
|
|
if (IS_DIRECTORY "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}.0")
|
|
set(WIN10_SDK_VERSION "${WIN10_SDK_VERSION}.0")
|
|
endif()
|
|
|
|
# Find the d3d12 and dxgi include path, it will typically look something like this.
|
|
# C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\d3d12.h
|
|
# C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared\dxgi1_4.h
|
|
find_path(D3D12_INCLUDE_DIR # Set variable D3D12_INCLUDE_DIR
|
|
d3d12.h # Find a path with d3d12.h
|
|
HINTS "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}/um"
|
|
DOC "path to WIN10 SDK header files"
|
|
HINTS
|
|
)
|
|
|
|
find_path(DXGI_INCLUDE_DIR # Set variable DXGI_INCLUDE_DIR
|
|
dxgi1_4.h # Find a path with dxgi1_4.h
|
|
HINTS "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}/shared"
|
|
DOC "path to WIN10 SDK header files"
|
|
HINTS
|
|
)
|
|
|
|
if (CMAKE_GENERATOR MATCHES "Visual Studio.*ARM" )
|
|
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/arm)
|
|
elseif (CMAKE_GENERATOR MATCHES "Visual Studio.*ARM64" )
|
|
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/arm64)
|
|
elseif (CMAKE_GENERATOR MATCHES "Visual Studio.*Win64" )
|
|
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/x64)
|
|
else()
|
|
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/x86)
|
|
endif()
|
|
|
|
find_library(D3D12_LIBRARY NAMES d3d12.lib HINTS ${WIN10_SDK_LIB_PATH})
|
|
find_library(DXGI_LIBRARY NAMES dxgi.lib HINTS ${WIN10_SDK_LIB_PATH})
|
|
find_library(D3DCOMPILER_LIBRARY NAMES d3dcompiler.lib HINTS ${WIN10_SDK_LIB_PATH})
|
|
|
|
list(APPEND D3D12_LIBRARIES
|
|
${D3D12_LIBRARY}
|
|
${DXGI_LIBRARY}
|
|
${D3DCOMPILER_LIBRARY}
|
|
)
|
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
find_library(DXGUID_LIBRARY NAMES dxguid.lib HINTS ${WIN10_SDK_LIB_PATH})
|
|
list(APPEND D3D12_LIBRARIES ${DXGUID_LIBRARY})
|
|
endif()
|
|
|
|
target_link_libraries(d3d12_autogen glfw nxtcpp ${D3D12_LIBRARIES})
|
|
target_include_directories(d3d12_autogen SYSTEM PRIVATE ${D3D12_INCLUDE_DIR} ${DXGI_INCLUDE_DIR})
|
|
target_include_directories(d3d12_autogen PRIVATE ${SRC_DIR})
|
|
target_include_directories(d3d12_autogen PUBLIC ${GENERATED_DIR})
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${D3D12_DIR}/d3d12_platform.h
|
|
${D3D12_DIR}/BindGroupD3D12.cpp
|
|
${D3D12_DIR}/BindGroupD3D12.h
|
|
${D3D12_DIR}/BindGroupLayoutD3D12.cpp
|
|
${D3D12_DIR}/BindGroupLayoutD3D12.h
|
|
${D3D12_DIR}/BlendStateD3D12.cpp
|
|
${D3D12_DIR}/BlendStateD3D12.h
|
|
${D3D12_DIR}/BufferD3D12.cpp
|
|
${D3D12_DIR}/BufferD3D12.h
|
|
${D3D12_DIR}/CommandAllocatorManager.cpp
|
|
${D3D12_DIR}/CommandAllocatorManager.h
|
|
${D3D12_DIR}/CommandBufferD3D12.cpp
|
|
${D3D12_DIR}/CommandBufferD3D12.h
|
|
${D3D12_DIR}/ComputePipelineD3D12.cpp
|
|
${D3D12_DIR}/ComputePipelineD3D12.h
|
|
${D3D12_DIR}/DepthStencilStateD3D12.cpp
|
|
${D3D12_DIR}/DepthStencilStateD3D12.h
|
|
${D3D12_DIR}/DescriptorHeapAllocator.cpp
|
|
${D3D12_DIR}/DescriptorHeapAllocator.h
|
|
${D3D12_DIR}/D3D12Backend.cpp
|
|
${D3D12_DIR}/D3D12Backend.h
|
|
${D3D12_DIR}/FramebufferD3D12.cpp
|
|
${D3D12_DIR}/FramebufferD3D12.h
|
|
${D3D12_DIR}/InputStateD3D12.cpp
|
|
${D3D12_DIR}/InputStateD3D12.h
|
|
${D3D12_DIR}/PipelineLayoutD3D12.cpp
|
|
${D3D12_DIR}/PipelineLayoutD3D12.h
|
|
${D3D12_DIR}/QueueD3D12.cpp
|
|
${D3D12_DIR}/QueueD3D12.h
|
|
${D3D12_DIR}/RenderPipelineD3D12.cpp
|
|
${D3D12_DIR}/RenderPipelineD3D12.h
|
|
${D3D12_DIR}/ResourceAllocator.cpp
|
|
${D3D12_DIR}/ResourceAllocator.h
|
|
${D3D12_DIR}/ResourceUploader.cpp
|
|
${D3D12_DIR}/ResourceUploader.h
|
|
${D3D12_DIR}/SamplerD3D12.cpp
|
|
${D3D12_DIR}/SamplerD3D12.h
|
|
${D3D12_DIR}/ShaderModuleD3D12.cpp
|
|
${D3D12_DIR}/ShaderModuleD3D12.h
|
|
${D3D12_DIR}/SwapChainD3D12.cpp
|
|
${D3D12_DIR}/SwapChainD3D12.h
|
|
${D3D12_DIR}/TextureCopySplitter.cpp
|
|
${D3D12_DIR}/TextureCopySplitter.h
|
|
${D3D12_DIR}/TextureD3D12.cpp
|
|
${D3D12_DIR}/TextureD3D12.h
|
|
)
|
|
endif()
|
|
|
|
################################################################################
|
|
# Vulkan Backend
|
|
################################################################################
|
|
|
|
if (NXT_ENABLE_VULKAN)
|
|
Generate(
|
|
LIB_NAME vulkan_autogen
|
|
LIB_TYPE STATIC
|
|
FOLDER "backend"
|
|
PRINT_NAME "Vulkan backend autogenerated files"
|
|
COMMAND_LINE_ARGS
|
|
${GENERATOR_COMMON_ARGS}
|
|
-T vulkan
|
|
)
|
|
target_link_libraries(vulkan_autogen nxtcpp)
|
|
target_include_directories(vulkan_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
|
target_include_directories(vulkan_autogen PUBLIC ${VULKAN_HEADERS_INCLUDE_DIR})
|
|
target_include_directories(vulkan_autogen PUBLIC ${SRC_DIR})
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${VULKAN_DIR}/vulkan_platform.h
|
|
${VULKAN_DIR}/BufferUploader.cpp
|
|
${VULKAN_DIR}/BufferUploader.h
|
|
${VULKAN_DIR}/BufferVk.cpp
|
|
${VULKAN_DIR}/BufferVk.h
|
|
${VULKAN_DIR}/CommandBufferVk.cpp
|
|
${VULKAN_DIR}/CommandBufferVk.h
|
|
${VULKAN_DIR}/FencedDeleter.cpp
|
|
${VULKAN_DIR}/FencedDeleter.h
|
|
${VULKAN_DIR}/FramebufferVk.cpp
|
|
${VULKAN_DIR}/FramebufferVk.h
|
|
${VULKAN_DIR}/InputStateVk.cpp
|
|
${VULKAN_DIR}/InputStateVk.h
|
|
${VULKAN_DIR}/MemoryAllocator.cpp
|
|
${VULKAN_DIR}/MemoryAllocator.h
|
|
${VULKAN_DIR}/PipelineLayoutVk.cpp
|
|
${VULKAN_DIR}/PipelineLayoutVk.h
|
|
${VULKAN_DIR}/RenderPassVk.cpp
|
|
${VULKAN_DIR}/RenderPassVk.h
|
|
${VULKAN_DIR}/RenderPipelineVk.cpp
|
|
${VULKAN_DIR}/RenderPipelineVk.h
|
|
${VULKAN_DIR}/ShaderModuleVk.cpp
|
|
${VULKAN_DIR}/ShaderModuleVk.h
|
|
${VULKAN_DIR}/TextureVk.cpp
|
|
${VULKAN_DIR}/TextureVk.h
|
|
${VULKAN_DIR}/VulkanBackend.cpp
|
|
${VULKAN_DIR}/VulkanBackend.h
|
|
${VULKAN_DIR}/VulkanFunctions.cpp
|
|
${VULKAN_DIR}/VulkanFunctions.h
|
|
${VULKAN_DIR}/VulkanInfo.cpp
|
|
${VULKAN_DIR}/VulkanInfo.h
|
|
)
|
|
endif()
|
|
|
|
################################################################################
|
|
# Common sources definition of the library
|
|
################################################################################
|
|
|
|
list(APPEND BACKEND_SOURCES
|
|
${BACKEND_DIR}/BindGroup.cpp
|
|
${BACKEND_DIR}/BindGroup.h
|
|
${BACKEND_DIR}/BindGroupLayout.cpp
|
|
${BACKEND_DIR}/BindGroupLayout.h
|
|
${BACKEND_DIR}/BlendState.cpp
|
|
${BACKEND_DIR}/BlendState.h
|
|
${BACKEND_DIR}/Builder.cpp
|
|
${BACKEND_DIR}/Builder.h
|
|
${BACKEND_DIR}/Buffer.cpp
|
|
${BACKEND_DIR}/Buffer.h
|
|
${BACKEND_DIR}/CommandAllocator.cpp
|
|
${BACKEND_DIR}/CommandAllocator.h
|
|
${BACKEND_DIR}/CommandBuffer.cpp
|
|
${BACKEND_DIR}/CommandBuffer.h
|
|
${BACKEND_DIR}/ComputePipeline.cpp
|
|
${BACKEND_DIR}/ComputePipeline.h
|
|
${BACKEND_DIR}/DepthStencilState.cpp
|
|
${BACKEND_DIR}/DepthStencilState.h
|
|
${BACKEND_DIR}/CommandBufferStateTracker.cpp
|
|
${BACKEND_DIR}/CommandBufferStateTracker.h
|
|
${BACKEND_DIR}/Device.cpp
|
|
${BACKEND_DIR}/Device.h
|
|
${BACKEND_DIR}/Forward.h
|
|
${BACKEND_DIR}/Framebuffer.cpp
|
|
${BACKEND_DIR}/Framebuffer.h
|
|
${BACKEND_DIR}/InputState.cpp
|
|
${BACKEND_DIR}/InputState.h
|
|
${BACKEND_DIR}/RenderPipeline.cpp
|
|
${BACKEND_DIR}/RenderPipeline.h
|
|
${BACKEND_DIR}/PerStage.cpp
|
|
${BACKEND_DIR}/PerStage.h
|
|
${BACKEND_DIR}/Pipeline.cpp
|
|
${BACKEND_DIR}/Pipeline.h
|
|
${BACKEND_DIR}/PipelineLayout.cpp
|
|
${BACKEND_DIR}/PipelineLayout.h
|
|
${BACKEND_DIR}/Queue.cpp
|
|
${BACKEND_DIR}/Queue.h
|
|
${BACKEND_DIR}/RenderPass.cpp
|
|
${BACKEND_DIR}/RenderPass.h
|
|
${BACKEND_DIR}/RefCounted.cpp
|
|
${BACKEND_DIR}/RefCounted.h
|
|
${BACKEND_DIR}/Sampler.cpp
|
|
${BACKEND_DIR}/Sampler.h
|
|
${BACKEND_DIR}/ShaderModule.cpp
|
|
${BACKEND_DIR}/ShaderModule.h
|
|
${BACKEND_DIR}/SwapChain.cpp
|
|
${BACKEND_DIR}/SwapChain.h
|
|
${BACKEND_DIR}/Texture.cpp
|
|
${BACKEND_DIR}/Texture.h
|
|
${BACKEND_DIR}/ToBackend.h
|
|
)
|
|
|
|
add_library(nxt_backend STATIC ${BACKEND_SOURCES})
|
|
NXTInternalTarget("backend" nxt_backend)
|
|
target_link_libraries(nxt_backend nxt_common glfw glad spirv_cross)
|
|
|
|
if (NXT_ENABLE_D3D12)
|
|
target_link_libraries(nxt_backend d3d12_autogen)
|
|
endif()
|
|
if (NXT_ENABLE_METAL)
|
|
target_link_libraries(nxt_backend metal_autogen)
|
|
endif()
|
|
if (NXT_ENABLE_NULL)
|
|
target_link_libraries(nxt_backend null_autogen)
|
|
endif()
|
|
if (NXT_ENABLE_OPENGL)
|
|
target_link_libraries(nxt_backend opengl_autogen)
|
|
endif()
|
|
if (NXT_ENABLE_VULKAN)
|
|
target_link_libraries(nxt_backend vulkan_autogen)
|
|
endif()
|