Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Store UWP apps support #1108

Merged
merged 12 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ env:
PULL_REQUEST: yes

jobs:
build-windows:
name: build-windows
build-win32:
name: build-win32
runs-on: windows-latest
strategy:
matrix:
Expand All @@ -38,6 +38,30 @@ jobs:
- name: Build
run: tools\win-ci\build.ps1 $env:BUILD_ARCH $env:BUILD_DLL

build-winuwp:
name: build-winuwp
runs-on: windows-latest
strategy:
matrix:
arch:
- x64
- amd64_arm64

env:
BUILD_ARCH: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Setup Python
uses: actions/setup-python@v3
- uses: ilammy/msvc-dev-cmd@v1.12.1
with:
arch: ${{ env.BUILD_ARCH }}
uwp: true
- name: Build
run: tools\win-ci\build.ps1 $env:BUILD_ARCH false true

build-linux:
name: build-linux
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: windows
name: win32

on:
push:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/winuwp-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: winuwp

on:
push:
branches:
- dev
- release

paths-ignore:
- '**.md'
- 'docs/**'

jobs:
toolset-latest:
if: ${{ !startsWith(github.event.commits[0].message, 'Merge pull request') }}
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
runs-on: windows-latest
strategy:
matrix:
arch:
- x64

env:
BUILD_ARCH: ${{ matrix.arch }}

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Setup Python
uses: actions/setup-python@v3

- uses: ilammy/msvc-dev-cmd@v1.12.1
with:
arch: ${{ env.BUILD_ARCH }}
uwp: true

- name: Build
run: tools\win-ci\build.ps1 $env:BUILD_ARCH false true

- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.arch }}
path: |
build_*/AppPackages/**/*.msix
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,32 @@ add_subdirectory(${_AX_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/axmol/core)
set(BUILD_ENGINE_DONE ON)

if(AX_BUILD_TESTS)

message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")

macro(add_test_target target_name dir)
add_subdirectory(${dir} ${CMAKE_BINARY_DIR}/tests/${target_name})
set_target_properties(${target_name} PROPERTIES FOLDER "Apps")
endmacro()

# add cpp-template-default into project(axmol) for tmp test
add_subdirectory(${_AX_ROOT_PATH}/templates/cpp-template-default ${ENGINE_BINARY_PATH}/tests/HelloCpp)
add_test_target(HelloCpp ${_AX_ROOT_PATH}/templates/cpp-template-default )

# add cpp tests default
add_subdirectory(${_AX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
# add cpp tests default
add_test_target(cpp_tests ${_AX_ROOT_PATH}/tests/cpp-tests)

# add fairygui tests when fairygui extension is enabled
# add fairygui tests when fairygui extension is enabled
if(AX_ENABLE_EXT_FAIRYGUI)
add_subdirectory(${_AX_ROOT_PATH}/tests/fairygui-tests ${ENGINE_BINARY_PATH}/tests/fairygui-tests)
add_test_target(fairygui_tests ${_AX_ROOT_PATH}/tests/fairygui-tests)
endif()

if(AX_ENABLE_EXT_LIVE2D)
add_subdirectory(${_AX_ROOT_PATH}/tests/live2d-tests ${ENGINE_BINARY_PATH}/tests/live2d-tests)
add_test_target(live2d_tests ${_AX_ROOT_PATH}/tests/live2d-tests)
endif()

if(AX_ENABLE_EXT_LUA)
add_subdirectory(${_AX_ROOT_PATH}/templates/lua-template-default ${ENGINE_BINARY_PATH}/tests/HelloLua)
add_subdirectory(${_AX_ROOT_PATH}/tests/lua-tests ${ENGINE_BINARY_PATH}/tests/lua-test)
add_test_target(HelloLua ${_AX_ROOT_PATH}/templates/lua-template-default)
add_test_target(lua_tests ${_AX_ROOT_PATH}/tests/lua-tests)
endif(AX_ENABLE_EXT_LUA)

endif()
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ Examples:
- add `-DCMAKE_CXX_STANDARD=17` for C++17 on your command line like:
cmake -S . -B build `-DCMAKE_CXX_STANDARD=17` -G "Visual Studio 17 2022" -A x64


6. Use Visual Studio to open the newly created solution file. For example, `./build/ProjectName.sln`


#### Windows UWP (Visual Studio 2022), because microsoft limit, only support C++17
```cmake -B build_uwp -DCMAKE_SYSTEM_NAME=WindowsStore "-DCMAKE_SYSTEM_VERSION=10.0"```

##### Creating the Visual Studio solution for all axmol test projects

1. Open a console window (Command Prompt, Window Terminal or Powershell)
Expand Down
129 changes: 80 additions & 49 deletions cmake/Modules/AXBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,52 +160,11 @@ function(get_target_depends_ext_dlls ax_target all_depend_dlls_out)
set(${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE)
endfunction()

function(copy_thirdparty_dlls ax_target destDir)
# init dependency list with direct dependencies
get_property(DEPENDENCIES TARGET ${_AX_THIRDPARTY_NAME} PROPERTY LINK_LIBRARIES)
# We're not intersted in interface link libraries of the top-most target
# if (INCLUDE_INTERFACE_LINK_LIBRARIES)
# get_property(INTERFACE_LINK_LIBRARIES TARGET ${_AX_THIRDPARTY_NAME} PROPERTY
# INTERFACE_LINK_LIBRARIES)
# list(APPEND DEPENDENCIES ${INTERFACE_LINK_LIBRARIES})
# endif()

if(AX_ENABLE_EXT_LUA)
list(APPEND DEPENDENCIES ${LUA_ENGINE})
list(APPEND DEPENDENCIES tolua)
endif()

if (DEPENDENCIES)
list(REMOVE_DUPLICATES DEPENDENCIES)
# message (STATUS "${LIB} dependens on ${DEPENDENCIES}")
endif()

SET(EXT_LIB_FILES "")

foreach(DEPENDENCY ${DEPENDENCIES})
# message(STATUS ${DEPENDENCY} " depends by ${_AX_THIRDPARTY_NAME}")
get_property(IMPORTLIB TARGET ${DEPENDENCY} PROPERTY IMPORTED_IMPLIB)
get_property(IMPORTDLL TARGET ${DEPENDENCY} PROPERTY IMPORTED_LOCATION)
if(IMPORTLIB)
# message(STATUS "${DEPENDENCY} have import lib ${IMPORTLIB}")
list(APPEND EXT_LIB_FILES ${IMPORTLIB})
endif()
if(IMPORTDLL)
list(APPEND EXT_LIB_FILES ${IMPORTDLL})
endif()
endforeach()

message(STATUS "EXT_LIB_FILES=${EXT_LIB_FILES}")
add_custom_command(TARGET ${ax_target}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${EXT_LIB_FILES}
${destDir} # ${CMAKE_BINARY_DIR}/lib/$<CONFIG>
)
endfunction()

# copy the `ax_target` needed dlls into TARGET_FILE_DIR
function(ax_copy_target_dll ax_target)
get_target_depends_ext_dlls(${ax_target} all_depend_dlls)

# remove repeat items
if(all_depend_dlls)
list(REMOVE_DUPLICATES all_depend_dlls)
Expand All @@ -219,7 +178,6 @@ function(ax_copy_target_dll ax_target)
endforeach()

# copy thirdparty dlls to target bin dir
# copy_thirdparty_dlls(${ax_target} $<TARGET_FILE_DIR:${ax_target}>)
if(NOT CMAKE_GENERATOR STREQUAL "Ninja")
set(BUILD_CONFIG_DIR "\$\(Configuration\)/")
endif()
Expand Down Expand Up @@ -278,10 +236,43 @@ function(ax_mark_resources)
get_filename_component(RES_FILE_ABS ${RES_FILE} ABSOLUTE)
file(RELATIVE_PATH RES ${BASEDIR_ABS} ${RES_FILE_ABS})
get_filename_component(RES_LOC ${RES} PATH)
set_source_files_properties(${RES_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION "${opt_RESOURCEBASE}/${RES_LOC}"
HEADER_FILE_ONLY 1
)
if (APPLE)
set_source_files_properties(${RES_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION "${opt_RESOURCEBASE}/${RES_LOC}"
HEADER_FILE_ONLY 1
)
elseif(WINRT)
# MakeAppx.exe require deployment location path rule
# - must full quailfied windows style path
# - can't start with .\xxx.txt, must be xxx.txt
#
# Otherwise, will fail with:
# MakeAppx : error : 0x8007007b - The filename, directory name, or volume label syntax is incorrect.
if (opt_RESOURCEBASE STREQUAL ".")
set(basedir "")
if (NOT DEFINED basedir)
message(FATAL_ERROR "empty string as false")
endif()
else()
set(basedir "${opt_RESOURCEBASE}\\")
endif()
get_filename_component(RES_EXTENSION ${RES_FILE} LAST_EXT)
string(TOLOWER "${RES_EXTENSION}" RES_EXTENSION)
if (RES_EXTENSION STREQUAL ".obj")
set_source_files_properties(${RES_FILE} PROPERTIES HEADER_FILE_ONLY 1)
endif()
string(REPLACE "/" "\\" VSDEPLOY_LOC "${basedir}${RES_LOC}")
# dir path can have one trailing / -> remove
string(REGEX REPLACE "(.)\\\\$" "\\1" VSDEPLOY_LOC "${VSDEPLOY_LOC}")
set_source_files_properties(${RES_FILE} PROPERTIES
VS_DEPLOYMENT_CONTENT 1
VS_DEPLOYMENT_LOCATION "${VSDEPLOY_LOC}"
)
else()
set_source_files_properties(${RES_FILE} PROPERTIES
HEADER_FILE_ONLY 1
)
endif()

if(XCODE OR VS)
string(REPLACE "/" "\\" ide_source_group "${opt_RESOURCEBASE}/${RES_LOC}")
Expand Down Expand Up @@ -326,8 +317,14 @@ function(source_group_single_file single_file)
endfunction()

# setup a ax application
function(setup_ax_app_config app_name)
if(WIN64)
function(ax_setup_app_config app_name)
if (WINRT)
target_include_directories(${APP_NAME}
PRIVATE "proj.winrt"
)
set_target_properties(${APP_NAME} PROPERTIES VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "10.0.19041.0")
endif()
if(WIN32)
target_link_options(${APP_NAME} PRIVATE "/STACK:4194304")
endif()
# put all output app into bin/${app_name}
Expand Down Expand Up @@ -383,6 +380,40 @@ macro(ax_set_default_value cc_variable cc_value)
endif()
endmacro()

macro(ax_setup_winrt_sources )
set_property(SOURCE "proj.winrt/App.xaml" PROPERTY VS_XAML_TYPE "ApplicationDefinition")

ax_mark_multi_resources(platform_content_files RES_TO "Content" FOLDERS "${CMAKE_CURRENT_SOURCE_DIR}/proj.winrt/Content")

get_target_depends_ext_dlls(thirdparty prebuilt_dlls)
ax_mark_multi_resources(prebuilt_dlls RES_TO "." FILES ${prebuilt_dlls})

list(APPEND PLATFORM_SOURCES
proj.winrt/App.xaml
proj.winrt/App.xaml.h
proj.winrt/App.xaml.cpp
proj.winrt/Package.appxmanifest
${_AX_ROOT_PATH}/core/platform/winrt/xaml/OpenGLES.h
${_AX_ROOT_PATH}/core/platform/winrt/xaml/OpenGLES.cpp
${_AX_ROOT_PATH}/core/platform/winrt/xaml/OpenGLESPage.xaml
${_AX_ROOT_PATH}/core/platform/winrt/xaml/OpenGLESPage.xaml.h
${_AX_ROOT_PATH}/core/platform/winrt/xaml/OpenGLESPage.xaml.cpp
${_AX_ROOT_PATH}/core/platform/winrt/xaml/AxmolRenderer.h
${_AX_ROOT_PATH}/core/platform/winrt/xaml/AxmolRenderer.cpp
)

list(APPEND GAME_INC_DIRS ${_AX_ROOT_PATH}/core/platform/winrt/xaml)

list(APPEND GAME_HEADER
${PLATFORM_HEADERS}
)
list(APPEND GAME_SOURCE
${PLATFORM_SOURCES}
${platform_content_files}
${prebuilt_dlls}
)
endmacro()

# set Xcode property for application, include all depend target
macro(ax_config_app_xcode_property ax_app)
set(depend_libs)
Expand Down
25 changes: 15 additions & 10 deletions cmake/Modules/AXBuildSet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ find_program(PYTHON_COMMAND NAMES python3 python2 python)
find_program(_AX_COMMAND NAME axmol
PATHS ${_AX_ROOT_PATH}/tools/console/bin $ENV{AX_CONSOLE_ROOT})

message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "_AX_ROOT_PATH:" ${_AX_ROOT_PATH})
message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
# delete binary dir if you hope a full clean re-build
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
message(STATUS "PYTHON_PATH:" ${PYTHON_COMMAND})
message(STATUS "_AX_COMMAND_PATH:" ${_AX_COMMAND})
message(STATUS "HOST_SYSTEM:" ${CMAKE_HOST_SYSTEM_NAME})
# the default behavior of build module
option(AX_ENABLE_EXT_LUA "Build lua libraries" ON)

Expand All @@ -45,6 +35,21 @@ include(AXConfigDefine)
# config libraries dependence
include(AXConfigDepend)

message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "_AX_ROOT_PATH:" ${_AX_ROOT_PATH})
message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
# delete binary dir if you hope a full clean re-build
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
message(STATUS "PYTHON_PATH:" ${PYTHON_COMMAND})
message(STATUS "_AX_COMMAND_PATH:" ${_AX_COMMAND})
message(STATUS "HOST_SYSTEM:" ${CMAKE_HOST_SYSTEM_NAME})
message(STATUS "CMAKE_SYSTEM_NAME:" ${CMAKE_SYSTEM_NAME})
message(STATUS "CMAKE_GENERATOR_PLATFORM:" ${CMAKE_GENERATOR_PLATFORM})
message(STATUS "CMAKE_SYSTEM_PROCESSOR:" ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "ARCH_ALIAS:" ${ARCH_ALIAS})

if(_AX_COMMAND)
get_filename_component(ax_console_dir ${_AX_COMMAND} DIRECTORY)
set(_AX_LUAJIT_ROOT ${ax_console_dir}/../plugins/plugin_luacompile/bin)
Expand Down
Loading