blob: 1f06adb6597d397a64fb77dfbbff0f798db60345 [file] [log] [blame]
# Copyright 2017 The Dawn 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(DAWN_NATIVE_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)
set(DAWN_NATIVE_INCLUDE_DIR ${INCLUDE_DIR}/dawn_native)
Generate(
LIB_NAME dawn_native_utils_autogen
LIB_TYPE STATIC
FOLDER "dawn_native"
PRINT_NAME "Autogenerated dawn_native utilities"
COMMAND_LINE_ARGS
${GENERATOR_COMMON_ARGS}
-T dawn_native_utils
)
set(DAWN_NATIVE_SOURCES)
set(DAWN_NATIVE_DEPS dawn_common spirv_cross dawn_native_utils_autogen SPIRV-Tools)
set(DAWN_NATIVE_INCLUDE_DIRS ${SPIRV_CROSS_INCLUDE_DIR} ${SPIRV_TOOLS_INCLUDE_DIR})
################################################################################
# OpenGL Backend
################################################################################
if (DAWN_ENABLE_OPENGL)
list(APPEND DAWN_NATIVE_DEPS glad)
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${GLAD_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_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}/DeviceGL.cpp
${OPENGL_DIR}/DeviceGL.h
${OPENGL_DIR}/Forward.h
${OPENGL_DIR}/InputStateGL.cpp
${OPENGL_DIR}/InputStateGL.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}/QueueGL.cpp
${OPENGL_DIR}/QueueGL.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
${DAWN_NATIVE_INCLUDE_DIR}/OpenGLBackend.h
)
endif()
################################################################################
# Null Backend
################################################################################
if (DAWN_ENABLE_NULL)
list(APPEND DAWN_NATIVE_SOURCES
${NULL_DIR}/NullBackend.cpp
${NULL_DIR}/NullBackend.h
${DAWN_NATIVE_INCLUDE_DIR}/NullBackend.h
)
endif()
################################################################################
# Metal Backend
################################################################################
if (DAWN_ENABLE_METAL)
list(APPEND DAWN_NATIVE_DEPS "-framework Metal" "-framework Cocoa")
list(APPEND DAWN_NATIVE_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}/DeviceMTL.mm
${METAL_DIR}/DeviceMTL.h
${METAL_DIR}/Forward.h
${METAL_DIR}/InputStateMTL.mm
${METAL_DIR}/InputStateMTL.h
${METAL_DIR}/PipelineLayoutMTL.mm
${METAL_DIR}/PipelineLayoutMTL.h
${METAL_DIR}/QueueMTL.mm
${METAL_DIR}/QueueMTL.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
${DAWN_NATIVE_INCLUDE_DIR}/MetalBackend.h
)
endif()
################################################################################
# D3D12 Backend
################################################################################
if (DAWN_ENABLE_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()
list(APPEND DAWN_NATIVE_DEPS ${D3D12_LIBRARIES})
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${D3D12_INCLUDE_DIR} ${DXGI_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_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}/DeviceD3D12.cpp
${D3D12_DIR}/DeviceD3D12.h
${D3D12_DIR}/Forward.h
${D3D12_DIR}/InputStateD3D12.cpp
${D3D12_DIR}/InputStateD3D12.h
${D3D12_DIR}/NativeSwapChainImplD3D12.cpp
${D3D12_DIR}/NativeSwapChainImplD3D12.h
${D3D12_DIR}/PipelineLayoutD3D12.cpp
${D3D12_DIR}/PipelineLayoutD3D12.h
${D3D12_DIR}/PlatformFunctions.cpp
${D3D12_DIR}/PlatformFunctions.h
${D3D12_DIR}/QueueD3D12.cpp
${D3D12_DIR}/QueueD3D12.h
${D3D12_DIR}/RenderPassDescriptorD3D12.cpp
${D3D12_DIR}/RenderPassDescriptorD3D12.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
${DAWN_NATIVE_INCLUDE_DIR}/D3D12Backend.h
)
endif()
################################################################################
# Vulkan Backend
################################################################################
if (DAWN_ENABLE_VULKAN)
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${VULKAN_HEADERS_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_SOURCES
${VULKAN_DIR}/BindGroupVk.cpp
${VULKAN_DIR}/BindGroupVk.h
${VULKAN_DIR}/BindGroupLayoutVk.cpp
${VULKAN_DIR}/BindGroupLayoutVk.h
${VULKAN_DIR}/BlendStateVk.cpp
${VULKAN_DIR}/BlendStateVk.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}/ComputePipelineVk.cpp
${VULKAN_DIR}/ComputePipelineVk.h
${VULKAN_DIR}/DeviceVk.cpp
${VULKAN_DIR}/DeviceVk.h
${VULKAN_DIR}/DepthStencilStateVk.cpp
${VULKAN_DIR}/DepthStencilStateVk.h
${VULKAN_DIR}/FencedDeleter.cpp
${VULKAN_DIR}/FencedDeleter.h
${VULKAN_DIR}/Forward.h
${VULKAN_DIR}/InputStateVk.cpp
${VULKAN_DIR}/InputStateVk.h
${VULKAN_DIR}/MemoryAllocator.cpp
${VULKAN_DIR}/MemoryAllocator.h
${VULKAN_DIR}/NativeSwapChainImplVk.cpp
${VULKAN_DIR}/NativeSwapChainImplVk.h
${VULKAN_DIR}/PipelineLayoutVk.cpp
${VULKAN_DIR}/PipelineLayoutVk.h
${VULKAN_DIR}/QueueVk.cpp
${VULKAN_DIR}/QueueVk.h
${VULKAN_DIR}/RenderPassCache.cpp
${VULKAN_DIR}/RenderPassCache.h
${VULKAN_DIR}/RenderPassDescriptorVk.cpp
${VULKAN_DIR}/RenderPassDescriptorVk.h
${VULKAN_DIR}/RenderPipelineVk.cpp
${VULKAN_DIR}/RenderPipelineVk.h
${VULKAN_DIR}/SamplerVk.cpp
${VULKAN_DIR}/SamplerVk.h
${VULKAN_DIR}/ShaderModuleVk.cpp
${VULKAN_DIR}/ShaderModuleVk.h
${VULKAN_DIR}/SwapChainVk.cpp
${VULKAN_DIR}/SwapChainVk.h
${VULKAN_DIR}/TextureVk.cpp
${VULKAN_DIR}/TextureVk.h
${VULKAN_DIR}/VulkanFunctions.cpp
${VULKAN_DIR}/VulkanFunctions.h
${VULKAN_DIR}/VulkanInfo.cpp
${VULKAN_DIR}/VulkanInfo.h
${DAWN_NATIVE_INCLUDE_DIR}/VulkanBackend.h
)
endif()
################################################################################
# Common sources and definition of the library
################################################################################
list(APPEND DAWN_NATIVE_SOURCES
${DAWN_NATIVE_DIR}/dawn_platform.h
${DAWN_NATIVE_DIR}/BindGroup.cpp
${DAWN_NATIVE_DIR}/BindGroup.h
${DAWN_NATIVE_DIR}/BindGroupLayout.cpp
${DAWN_NATIVE_DIR}/BindGroupLayout.h
${DAWN_NATIVE_DIR}/BlendState.cpp
${DAWN_NATIVE_DIR}/BlendState.h
${DAWN_NATIVE_DIR}/Builder.cpp
${DAWN_NATIVE_DIR}/Builder.h
${DAWN_NATIVE_DIR}/Buffer.cpp
${DAWN_NATIVE_DIR}/Buffer.h
${DAWN_NATIVE_DIR}/Commands.cpp
${DAWN_NATIVE_DIR}/Commands.h
${DAWN_NATIVE_DIR}/CommandAllocator.cpp
${DAWN_NATIVE_DIR}/CommandAllocator.h
${DAWN_NATIVE_DIR}/CommandBuffer.cpp
${DAWN_NATIVE_DIR}/CommandBuffer.h
${DAWN_NATIVE_DIR}/ComputePassEncoder.cpp
${DAWN_NATIVE_DIR}/ComputePassEncoder.h
${DAWN_NATIVE_DIR}/ComputePipeline.cpp
${DAWN_NATIVE_DIR}/ComputePipeline.h
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.cpp
${DAWN_NATIVE_DIR}/CommandBufferStateTracker.h
${DAWN_NATIVE_DIR}/DawnNative.cpp
${DAWN_NATIVE_DIR}/DepthStencilState.cpp
${DAWN_NATIVE_DIR}/DepthStencilState.h
${DAWN_NATIVE_DIR}/Device.cpp
${DAWN_NATIVE_DIR}/Device.h
${DAWN_NATIVE_DIR}/Error.cpp
${DAWN_NATIVE_DIR}/Error.h
${DAWN_NATIVE_DIR}/ErrorData.cpp
${DAWN_NATIVE_DIR}/ErrorData.h
${DAWN_NATIVE_DIR}/Forward.h
${DAWN_NATIVE_DIR}/InputState.cpp
${DAWN_NATIVE_DIR}/InputState.h
${DAWN_NATIVE_DIR}/ObjectBase.cpp
${DAWN_NATIVE_DIR}/ObjectBase.h
${DAWN_NATIVE_DIR}/PassResourceUsage.h
${DAWN_NATIVE_DIR}/PerStage.cpp
${DAWN_NATIVE_DIR}/PerStage.h
${DAWN_NATIVE_DIR}/Pipeline.cpp
${DAWN_NATIVE_DIR}/Pipeline.h
${DAWN_NATIVE_DIR}/PipelineLayout.cpp
${DAWN_NATIVE_DIR}/PipelineLayout.h
${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.cpp
${DAWN_NATIVE_DIR}/ProgrammablePassEncoder.h
${DAWN_NATIVE_DIR}/Queue.cpp
${DAWN_NATIVE_DIR}/Queue.h
${DAWN_NATIVE_DIR}/RefCounted.cpp
${DAWN_NATIVE_DIR}/RefCounted.h
${DAWN_NATIVE_DIR}/RenderPassDescriptor.cpp
${DAWN_NATIVE_DIR}/RenderPassDescriptor.h
${DAWN_NATIVE_DIR}/RenderPassEncoder.cpp
${DAWN_NATIVE_DIR}/RenderPassEncoder.h
${DAWN_NATIVE_DIR}/RenderPipeline.cpp
${DAWN_NATIVE_DIR}/RenderPipeline.h
${DAWN_NATIVE_DIR}/Sampler.cpp
${DAWN_NATIVE_DIR}/Sampler.h
${DAWN_NATIVE_DIR}/ShaderModule.cpp
${DAWN_NATIVE_DIR}/ShaderModule.h
${DAWN_NATIVE_DIR}/SwapChain.cpp
${DAWN_NATIVE_DIR}/SwapChain.h
${DAWN_NATIVE_DIR}/Texture.cpp
${DAWN_NATIVE_DIR}/Texture.h
${DAWN_NATIVE_DIR}/ToBackend.h
${DAWN_NATIVE_INCLUDE_DIR}/dawn_native_export.h
${DAWN_NATIVE_INCLUDE_DIR}/DawnNative.h
)
# We want to produce both a static and a shared libdawn_native library. The static one is for
# unittests that need access to all the symbols of the library. The shared one is for the other
# users that access libdawn_native through the regular interface.
# We use a CMake "OBJECT" library type which allows precompiling the source files and reusing
# them for both the static and the shared library. Recent CMake versions make it so if you
# depend on an OBJECT library you get its dependencies and source files, which is very similar to
# GN's source_set. However the versions of CMake on our test bots is too old and doesn't support
# this, so instead we duplicate the deps everywhere.
add_library(libdawn_native_objects OBJECT ${DAWN_NATIVE_SOURCES})
DawnInternalTarget("dawn_native" libdawn_native_objects)
target_compile_definitions(libdawn_native_objects PRIVATE DAWN_NATIVE_IMPLEMENTATION SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS)
target_include_directories(libdawn_native_objects PRIVATE ${DAWN_NATIVE_INCLUDE_DIRS})
add_dependencies(libdawn_native_objects dawn_native_utils_autogen)
add_library(libdawn_native SHARED $<TARGET_OBJECTS:libdawn_native_objects>)
DawnInternalTarget("dawn_native" libdawn_native)
target_link_libraries(libdawn_native PRIVATE ${DAWN_NATIVE_DEPS})
set_property(TARGET libdawn_native PROPERTY OUTPUT_NAME "dawn_native")
add_library(libdawn_native_static STATIC $<TARGET_OBJECTS:libdawn_native_objects>)
DawnInternalTarget("dawn_native" libdawn_native_static)
target_link_libraries(libdawn_native_static ${DAWN_NATIVE_DEPS})