From b2bc57ad22afaee2131ece17dbffd8b58c73be38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BF=8A=E5=98=89?= Date: Thu, 24 Jun 2021 07:00:16 +0000 Subject: [PATCH] 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 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng --- CMakeLists.txt | 19 +++++++++++-- src/dawn_native/CMakeLists.txt | 14 +++++++++- src/utils/CMakeLists.txt | 51 ++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 161709463f..c5c4a94a6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,14 @@ set(ENABLE_METAL OFF) set(ENABLE_OPENGL OFF) set(ENABLE_VULKAN OFF) set(USE_X11 OFF) +set(BUILD_EXAMPLE OFF) if (WIN32) set(ENABLE_D3D12 ON) - set(ENABLE_VULKAN ON) + if (not WINDOWS_STORE) + # Enable Vulkan in win32 compilation only + # since UWP only supports d3d + set(ENABLE_VULKAN ON) + endif() elseif(APPLE) set(ENABLE_METAL ON) elseif(UNIX) @@ -64,6 +69,16 @@ elseif(UNIX) set(USE_X11 ON) 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_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL}) 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_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.") diff --git a/src/dawn_native/CMakeLists.txt b/src/dawn_native/CMakeLists.txt index d97bea3106..f585ccd145 100644 --- a/src/dawn_native/CMakeLists.txt +++ b/src/dawn_native/CMakeLists.txt @@ -191,10 +191,22 @@ if (DAWN_USE_X11) ) 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) 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) target_sources(dawn_native PRIVATE "${DAWN_INCLUDE_DIR}/dawn_native/D3D12Backend.h" diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 59b2a1943f..13b858c3f4 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -14,14 +14,10 @@ add_library(dawn_utils STATIC ${DAWN_DUMMY_FILE}) target_sources(dawn_utils PRIVATE - "BackendBinding.cpp" - "BackendBinding.h" "ComboRenderBundleEncoderDescriptor.cpp" "ComboRenderBundleEncoderDescriptor.h" "ComboRenderPipelineDescriptor.cpp" "ComboRenderPipelineDescriptor.h" - "GLFWUtils.cpp" - "GLFWUtils.h" "PlatformDebugLogger.h" "SystemUtils.cpp" "SystemUtils.h" @@ -48,7 +44,7 @@ target_link_libraries(dawn_utils glfw ) -if(WIN32) +if(WIN32 AND NOT WINDOWS_STORE) target_sources(dawn_utils PRIVATE "WindowsDebugLogger.cpp") else() target_sources(dawn_utils PRIVATE "EmptyDebugLogger.cpp") @@ -67,26 +63,39 @@ elseif(UNIX) target_sources(dawn_utils PRIVATE "PosixTimer.cpp") endif() -if (DAWN_ENABLE_D3D12) - target_sources(dawn_utils PRIVATE "D3D12Binding.cpp") -endif() - if (DAWN_ENABLE_METAL) - target_sources(dawn_utils PRIVATE - "GLFWUtils_metal.mm" - "MetalBinding.mm" - ) target_link_libraries(dawn_utils PRIVATE "-framework Metal") endif() -if (DAWN_ENABLE_NULL) - target_sources(dawn_utils PRIVATE "NullBinding.cpp") -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_OPENGL) - target_sources(dawn_utils PRIVATE "OpenGLBinding.cpp") -endif() + if (DAWN_ENABLE_D3D12) + target_sources(dawn_utils PRIVATE "D3D12Binding.cpp") + endif() -if (DAWN_ENABLE_VULKAN) - target_sources(dawn_utils PRIVATE "VulkanBinding.cpp") + if (DAWN_ENABLE_METAL) + target_sources(dawn_utils PRIVATE + "GLFWUtils_metal.mm" + "MetalBinding.mm" + ) + endif() + + if (DAWN_ENABLE_NULL) + target_sources(dawn_utils PRIVATE "NullBinding.cpp") + endif() + + if (DAWN_ENABLE_OPENGL) + target_sources(dawn_utils PRIVATE "OpenGLBinding.cpp") + endif() + + if (DAWN_ENABLE_VULKAN) + target_sources(dawn_utils PRIVATE "VulkanBinding.cpp") + endif() endif()