From 6ddf2a066039252770f534ac89cb2b5cd4834775 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 13 Dec 2017 18:37:46 -0800 Subject: Adding UWP to CMake (in progress) --- .../GhostCubePlugin/PluginSource/CMakeLists.txt | 7 ++- unityplugin/GhostCubeScene/CMakeLists.txt | 14 ++++- unityplugin/UnityEmulator/CMakeLists.txt | 70 +++++++++++++++------- 3 files changed, 68 insertions(+), 23 deletions(-) (limited to 'unityplugin') diff --git a/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt b/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt index 8fa2d1e..b1eda3b 100644 --- a/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt +++ b/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.3) +cmake_minimum_required (VERSION 3.8) project(GhostCubePlugin CXX) @@ -39,7 +39,7 @@ add_library(GhostCubePlugin-shared SHARED ${SOURCE} ${INCLUDE} ${UNITY_INTERFACES} ) -if(PLATFORM_WIN32 OR PLATFORM_UNVIRSAL_WINDOWS) +if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS) if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") set(ARCH 64) else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") @@ -88,6 +88,9 @@ if(MSVC) # Disable MSVC-specific warnings # - w4201: nonstandard extension used: nameless struct/unio target_compile_options(GhostCubePlugin-shared PRIVATE /wd4201) + if(PLATFORM_UNIVERSAL_WINDOWS) + target_compile_definitions(GhostCubePlugin-shared PRIVATE WINDOWS_UWP UNITY_METRO) + endif() # Enable link-time code generation for release builds (I was not able to # find any way to set these settings through interface library BuildSettings) set_target_properties(GhostCubePlugin-shared PROPERTIES diff --git a/unityplugin/GhostCubeScene/CMakeLists.txt b/unityplugin/GhostCubeScene/CMakeLists.txt index 4f4aaf9..aa7860c 100644 --- a/unityplugin/GhostCubeScene/CMakeLists.txt +++ b/unityplugin/GhostCubeScene/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.3) +cmake_minimum_required (VERSION 3.8) project(GhostCubeScene CXX) @@ -28,6 +28,9 @@ if(PLATFORM_WIN32) "\"$\"" "\"$\"") +elseif(PLATFORM_UNIVERSAL_WINDOWS) + add_executable(GhostCubeScene WIN32 ${SOURCE} ${INCLUDE}) + #elseif(APPLE) #add_executable(GhostCubeScene MACOSX_BUNDLE Main.cpp) #elseif(UNIX) @@ -36,6 +39,15 @@ else() message(FATAL_ERROR "Unknown platform") endif() +if(PLATFORM_UNIVERSAL_WINDOWS) + get_emulator_uwp_source(UWP_SOURCE UWP_INCLUDE UWP_INCLUDE_DIR) + source_group("UWP\\src" FILES ${UWP_SOURCE}) + source_group("UWP\\include" FILES ${UWP_INCLUDE}) + target_include_directories(GhostCubeScene PRIVATE ${UWP_INCLUDE_DIR}) + target_sources(GhostCubeScene PRIVATE ${UWP_SOURCE} ${UWP_INCLUDE}) +endif() + + target_include_directories(GhostCubeScene PRIVATE ../GhostCubePlugin/PluginSource/src/Unity diff --git a/unityplugin/UnityEmulator/CMakeLists.txt b/unityplugin/UnityEmulator/CMakeLists.txt index 59d3b55..da260a4 100644 --- a/unityplugin/UnityEmulator/CMakeLists.txt +++ b/unityplugin/UnityEmulator/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.3) +cmake_minimum_required (VERSION 3.8) project(UnityEmulator CXX) @@ -50,17 +50,38 @@ endif() if(PLATFORM_WIN32) list(APPEND SOURCE src/Windows/WinMain.cpp) + elseif(PLATFORM_UNIVERSAL_WINDOWS) - list(APPEND SOURCE src/UWP/App.cpp) - list(APPEND INCLUDE src/UWP/DeviceResources.cpp) - list(APPEND INCLUDE src/UWP/UnityEmulatorAppMain.cpp) - - list(APPEND INCLUDE src/UWP/App.h) - list(APPEND INCLUDE src/UWP/DeviceResources.h) - list(APPEND INCLUDE src/UWP/DirectXHelper.h) - list(APPEND INCLUDE src/UWP/pch2.h) - list(APPEND INCLUDE src/UWP/StepTimer.h) - list(APPEND INCLUDE src/UWP/UnityEmulatorAppMain.h) + + # Windows Runtime types cannot be included into static libraries + # https://social.msdn.microsoft.com/Forums/en-US/269db513-64ef-4817-a025-43954f614eb3/lnk4264-why-are-static-libraries-not-recommended-when-authoring-windows-runtime-types?forum=winappswithnativecode + # So as a workaround, we will include all source files into the target app project + function(get_emulator_uwp_source UWP_SOURCE UWP_INCLUDE UWP_INCLUDE_DIR) + get_target_property(EMULATOR_SOURCE_DIR UnityEmulator SOURCE_DIR) + + set(${UWP_SOURCE} + ${EMULATOR_SOURCE_DIR}/src/UWP/App.cpp + ${EMULATOR_SOURCE_DIR}/src/UWP/DeviceResources.cpp + ${EMULATOR_SOURCE_DIR}/src/UWP/UnityEmulatorAppMain.cpp + PARENT_SCOPE + ) + + set(${UWP_INCLUDE} + ${EMULATOR_SOURCE_DIR}/src/UWP/App.h + ${EMULATOR_SOURCE_DIR}/src/UWP/DeviceResources.h + ${EMULATOR_SOURCE_DIR}/src/UWP/DirectXHelper.h + ${EMULATOR_SOURCE_DIR}/src/UWP/pch2.h + ${EMULATOR_SOURCE_DIR}/src/UWP/StepTimer.h + ${EMULATOR_SOURCE_DIR}/src/UWP/UnityEmulatorAppMain.h + PARENT_SCOPE + ) + + set(${UWP_INCLUDE_DIR} + ${EMULATOR_SOURCE_DIR}/Src/UWP + PARENT_SCOPE + ) + endfunction(get_emulator_uwp_source) + elseif(PLATFORM_ANDROID) list(APPEND SOURCE src/Android/AndroidMainImpl.cpp) else() @@ -92,22 +113,31 @@ endif() target_link_libraries(UnityEmulator PRIVATE BuildSettings - glew-static PUBLIC Common GraphicsEngine - GraphicsEngineOpenGL-static GraphicsTools TargetPlatform ) -if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS) - target_link_libraries(UnityEmulator - PUBLIC - GraphicsEngineD3DBase - GraphicsEngineD3D11-static - GraphicsEngineD3D12-static -) +if(GL_SUPPORTED) + target_link_libraries(UnityEmulator PRIVATE glew-static) +endif() + +if(GL_SUPPORTED OR GLES_SUPPORTED) + target_link_libraries(UnityEmulator PUBLIC GraphicsEngineOpenGL-static) +endif() + +if(D3D11_SUPPORTED) + target_link_libraries(UnityEmulator PUBLIC GraphicsEngineD3DBase GraphicsEngineD3D11-static) +endif() + +if(D3D12_SUPPORTED) + target_link_libraries(UnityEmulator PUBLIC GraphicsEngineD3DBase GraphicsEngineD3D12-static) +endif() + +if(PLATFORM_UNIVERSAL_WINDOWS) + target_link_libraries(UnityEmulator PRIVATE dxguid.lib) endif() source_group("src" FILES ${SOURCE}) -- cgit v1.2.3