Add UWP compilation support in CMake

Set BUILD_EXAMPLE to OFF in UWP.
Disable Vulkan in UWP.
Compile GLFW related sources only on supported platform.
Remove linking to user32.lib in UWP.
Add linking to dxgi.lib only in debug configuration.
Use EmptyDebugLogger in UWP.

Bug: dawn:766

Change-Id: I3e6149058048d1b597267dfb9d63342b6a54e0af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/55260
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
陈俊嘉 2021-06-24 07:00:16 +00:00 committed by Dawn LUCI CQ
parent 1af81e3128
commit b2bc57ad22
3 changed files with 60 additions and 24 deletions

View File

@ -53,9 +53,14 @@ set(ENABLE_METAL OFF)
set(ENABLE_OPENGL OFF) set(ENABLE_OPENGL OFF)
set(ENABLE_VULKAN OFF) set(ENABLE_VULKAN OFF)
set(USE_X11 OFF) set(USE_X11 OFF)
set(BUILD_EXAMPLE OFF)
if (WIN32) if (WIN32)
set(ENABLE_D3D12 ON) set(ENABLE_D3D12 ON)
if (not WINDOWS_STORE)
# Enable Vulkan in win32 compilation only
# since UWP only supports d3d
set(ENABLE_VULKAN ON) set(ENABLE_VULKAN ON)
endif()
elseif(APPLE) elseif(APPLE)
set(ENABLE_METAL ON) set(ENABLE_METAL ON)
elseif(UNIX) elseif(UNIX)
@ -64,6 +69,16 @@ elseif(UNIX)
set(USE_X11 ON) set(USE_X11 ON)
endif() endif()
# GLFW is not supported in UWP
if((WIN32 AND NOT WINDOWS_STORE) OR UNIX)
set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
endif()
# Current examples are depend on GLFW
if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
set(BUILD_EXAMPLE ON)
endif()
option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12}) option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL}) option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON) option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
@ -72,7 +87,7 @@ option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VU
option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF) option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
option(DAWN_BUILD_EXAMPLES "Enables building Dawn's exmaples" ON) option(DAWN_BUILD_EXAMPLES "Enables building Dawn's exmaples" ${BUILD_EXAMPLE})
set(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" CACHE STRING "Directory in which to find third-party dependencies.") set(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" CACHE STRING "Directory in which to find third-party dependencies.")

View File

@ -191,10 +191,22 @@ if (DAWN_USE_X11)
) )
endif() endif()
if (WIN32) # Only win32 app needs to link with user32.lib
# In UWP, all availiable APIs are defined in WindowsApp.lib
# and is automatically linked when WINDOWS_STORE set
if (WIN32 AND NOT WINDOWS_STORE)
target_link_libraries(dawn_native PRIVATE user32.lib) target_link_libraries(dawn_native PRIVATE user32.lib)
endif() endif()
# DXGIGetDebugInterface1 is defined in dxgi.lib
# But this API is tagged as a development-only capability
# which implies that linking to this function will cause
# the application to fail Windows store certification
# So we only link to it in debug build when compiling for UWP.
# In win32 we load dxgi.dll using LoadLibrary
# so no need for static linking.
target_link_libraries(dawn_native PRIVATE debug dxgi.lib)
if (DAWN_ENABLE_D3D12) if (DAWN_ENABLE_D3D12)
target_sources(dawn_native PRIVATE target_sources(dawn_native PRIVATE
"${DAWN_INCLUDE_DIR}/dawn_native/D3D12Backend.h" "${DAWN_INCLUDE_DIR}/dawn_native/D3D12Backend.h"

View File

@ -14,14 +14,10 @@
add_library(dawn_utils STATIC ${DAWN_DUMMY_FILE}) add_library(dawn_utils STATIC ${DAWN_DUMMY_FILE})
target_sources(dawn_utils PRIVATE target_sources(dawn_utils PRIVATE
"BackendBinding.cpp"
"BackendBinding.h"
"ComboRenderBundleEncoderDescriptor.cpp" "ComboRenderBundleEncoderDescriptor.cpp"
"ComboRenderBundleEncoderDescriptor.h" "ComboRenderBundleEncoderDescriptor.h"
"ComboRenderPipelineDescriptor.cpp" "ComboRenderPipelineDescriptor.cpp"
"ComboRenderPipelineDescriptor.h" "ComboRenderPipelineDescriptor.h"
"GLFWUtils.cpp"
"GLFWUtils.h"
"PlatformDebugLogger.h" "PlatformDebugLogger.h"
"SystemUtils.cpp" "SystemUtils.cpp"
"SystemUtils.h" "SystemUtils.h"
@ -48,7 +44,7 @@ target_link_libraries(dawn_utils
glfw glfw
) )
if(WIN32) if(WIN32 AND NOT WINDOWS_STORE)
target_sources(dawn_utils PRIVATE "WindowsDebugLogger.cpp") target_sources(dawn_utils PRIVATE "WindowsDebugLogger.cpp")
else() else()
target_sources(dawn_utils PRIVATE "EmptyDebugLogger.cpp") target_sources(dawn_utils PRIVATE "EmptyDebugLogger.cpp")
@ -67,6 +63,19 @@ elseif(UNIX)
target_sources(dawn_utils PRIVATE "PosixTimer.cpp") target_sources(dawn_utils PRIVATE "PosixTimer.cpp")
endif() endif()
if (DAWN_ENABLE_METAL)
target_link_libraries(dawn_utils PRIVATE "-framework Metal")
endif()
if(DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
target_sources(dawn_utils PRIVATE
"BackendBinding.cpp"
"BackendBinding.h"
"GLFWUtils.cpp"
"GLFWUtils.h"
)
target_link_libraries(dawn_utils PRIVATE glfw)
if (DAWN_ENABLE_D3D12) if (DAWN_ENABLE_D3D12)
target_sources(dawn_utils PRIVATE "D3D12Binding.cpp") target_sources(dawn_utils PRIVATE "D3D12Binding.cpp")
endif() endif()
@ -76,7 +85,6 @@ if (DAWN_ENABLE_METAL)
"GLFWUtils_metal.mm" "GLFWUtils_metal.mm"
"MetalBinding.mm" "MetalBinding.mm"
) )
target_link_libraries(dawn_utils PRIVATE "-framework Metal")
endif() endif()
if (DAWN_ENABLE_NULL) if (DAWN_ENABLE_NULL)
@ -90,3 +98,4 @@ endif()
if (DAWN_ENABLE_VULKAN) if (DAWN_ENABLE_VULKAN)
target_sources(dawn_utils PRIVATE "VulkanBinding.cpp") target_sources(dawn_utils PRIVATE "VulkanBinding.cpp")
endif() endif()
endif()