cmake: build tests for UWP

This commit is contained in:
Anonymous Maarten 2023-04-19 16:28:39 +02:00 committed by Anonymous Maarten
parent b7889a7389
commit a5d9db0cd0
10 changed files with 121 additions and 8 deletions

View File

@ -23,7 +23,7 @@ jobs:
- { name: Windows (clang-cl x86), flags: -T ClangCL -A Win32, artifact: 'SDL-clang-cl-x86' }
- { name: Windows (ARM), flags: -A ARM, artifact: 'SDL-VC-arm32' }
- { name: Windows (ARM64), flags: -A ARM64, artifact: 'SDL-VC-arm64' }
- { name: UWP (x64), flags: -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0" -DSDL_TESTS=OFF, nowerror: true,
- { name: UWP (x64), flags: -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION="10.0", nowerror: true,
project: VisualC-WinRT/SDL-UWP.sln, projectflags: '/p:Platform=x64 /p:WindowsTargetPlatformVersion=10.0.17763.0', artifact: 'SDL-VC-UWP' }
steps:
@ -70,7 +70,6 @@ jobs:
run: |
cmake --build build/ --config Release --target PACKAGE
- name: Verify CMake configuration files
if: ${{ !contains(matrix.platform.name, 'UWP') }} # FIXME: cmake/test/CMakeLists.txt should support UWP
run: |
cmake -S cmake/test -B cmake_config_build `
-DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }} `

View File

@ -304,7 +304,7 @@ set_option(SDL_DUMMYAUDIO "Support the dummy audio driver" ON)
set_option(SDL_DUMMYVIDEO "Use dummy video driver" ON)
dep_option(SDL_IBUS "Enable IBus support" ON ${UNIX_SYS} OFF)
dep_option(SDL_OPENGL "Include OpenGL support" ON "NOT VISIONOS" OFF)
dep_option(SDL_OPENGLES "Include OpenGL ES support" ON "NOT VISIONOS" OFF)
dep_option(SDL_OPENGLES "Include OpenGL ES support" ON "NOT VISIONOS" OFF)
set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_DEFAULT})
dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" ON "SDL_PTHREADS" OFF)
dep_option(SDL_OSS "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF)
@ -365,7 +365,7 @@ option(SDL_TEST_LIBRARY "Build the SDL3_test library" ON)
dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" "${CMAKE_POSITION_INDEPENDENT_CODE}" "SDL_STATIC" OFF)
dep_option(SDL_TESTS "Build the test directory" OFF SDL_TEST_LIBRARY OFF)
dep_option(SDL_INSTALL_TESTS "Install test-cases" OFF "NOT SDL_DISABLE_INSTALL;NOT SDL_FRAMEWORK" OFF)
dep_option(SDL_INSTALL_TESTS "Install test-cases" OFF "NOT SDL_DISABLE_INSTALL;NOT SDL_FRAMEWORK;NOT WINDOWS_STORE" OFF)
dep_option(SDL_TESTS_LINK_SHARED "link tests to shared SDL library" "${SDL_SHARED}" "SDL_SHARED;SDL_STATIC" "${SDL_SHARED}")
set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Timeout multiplier to account for really slow machines")

View File

@ -2,6 +2,11 @@
cmake_minimum_required(VERSION 3.12)
project(sdl_test LANGUAGES C)
if(WINDOWS_STORE)
enable_language(CXX)
add_compile_options(/ZW)
set_source_files_properties(ain_cli.c main_gui.c PROPERTIES LANGUAGE CXX)
endif()
include(GenerateExportHeader)

View File

@ -15,6 +15,12 @@ if(NOT (MSVC AND SDL_CPU_ARM64))
find_package(OpenGL)
endif()
if(WINDOWS_STORE)
cmake_minimum_required(VERSION 3.19)
# CMP0112: Target file component generator expressions do not add target dependencies.
cmake_policy(SET CMP0112 NEW)
endif()
set(SDL_TEST_EXECUTABLES)
add_library(sdltests_utils OBJECT
@ -33,6 +39,14 @@ define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target i
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_TIMEOUT BRIEF_DOCS "Timeout for noninteractive executable." FULL_DOCS "Timeout for noninteractive executable.")
if(WINDOWS_STORE)
add_library(sdl_test_main_uwp OBJECT main.cpp)
target_link_libraries(sdl_test_main_uwp PRIVATE SDL3::Headers)
target_compile_options(sdl_test_main_uwp PRIVATE "/ZW")
set_source_files_properties(${RESOURCE_FILES} PROPERTIES VS_DEPLOYENT_LOCATION "Assets")
endif()
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
@ -44,13 +58,34 @@ macro(add_sdl_test_executable TARGET)
if(AST_TESTUTILS)
list(APPEND AST_SOURCES $<TARGET_OBJECTS:sdltests_utils>)
endif()
set(EXTRA_SOURCES "")
if(WINDOWS_STORE)
set(uwp_bindir "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.dir")
if(NOT IS_DIRECTORY "${uwp_bindir}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${uwp_bindir}")
endif()
string(REGEX REPLACE "[_]" "" SAFE_TARGET "${TARGET}")
file(GENERATE OUTPUT "${uwp_bindir}/${TARGET}.appxmanifest"
INPUT "${CMAKE_CURRENT_SOURCE_DIR}/uwp/Package.appxmanifest.in"
TARGET "${TARGET}"
)
set_property(SOURCE "${uwp_bindir}/${TARGET}.appxmanifest" PROPERTY VS_DEPLOYMENT_CONTENT 1)
list(APPEND EXTRA_SOURCES
"$<TARGET_OBJECTS:sdl_test_main_uwp>"
"${uwp_bindir}/${TARGET}.appxmanifest"
"uwp/logo-50x50.png"
"uwp/square-44x44.png"
"uwp/square-150x150.png"
"uwp/splash-620x300.png"
)
endif()
if(AST_NEEDS_RESOURCES)
list(APPEND AST_SOURCES ${RESOURCE_FILES})
list(APPEND EXTRA_SOURCES ${RESOURCE_FILES})
endif()
if(ANDROID)
add_library(${TARGET} SHARED ${AST_SOURCES})
add_library(${TARGET} SHARED ${AST_SOURCES} ${EXTRA_SOURCES})
else()
add_executable(${TARGET} ${AST_SOURCES})
add_executable(${TARGET} ${AST_SOURCES} ${EXTRA_SOURCES})
endif()
SDL_AddCommonCompilerFlags(${TARGET})
target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component})
@ -74,6 +109,16 @@ macro(add_sdl_test_executable TARGET)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>/sdl-${TARGET})
elseif(WINDOWS_STORE)
# MSVC does build the dependent targets (or POST_BUILD commands) when building an application
# after starting to debug. By copying the resources in a custom target, the files can be copied afterwards.
# FIXME: find out proper way to add assets to UWP package
cmake_minimum_required(VERSION 3.19)
add_custom_target(zzz-resources-copy-${TARGET}
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${TARGET}>/AppX"
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RESOURCE_FILES} "$<TARGET_FILE_DIR:${TARGET}>/AppX"
)
add_dependencies(${TARGET} zzz-resources-copy-${TARGET})
else()
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>)
@ -103,6 +148,17 @@ macro(add_sdl_test_executable TARGET)
elseif(PSP)
target_link_libraries(${TARGET} PRIVATE GL)
endif()
if(WINDOWS_STORE)
target_compile_definitions(${TARGET} PRIVATE "SDL_MAIN_NOIMPL")
set_property(TARGET ${TARGET} PROPERTY WIN32_EXECUTABLE TRUE)
set_property(TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY "${uwp_bindir}")
target_link_options(${TARGET} PRIVATE
-nodefaultlib:vccorlib$<$<CONFIG:Debug>:d>
-nodefaultlib:msvcrt$<$<CONFIG:Debug>:d>
vccorlib$<$<CONFIG:Debug>:d>.lib
msvcrt$<$<CONFIG:Debug>:d>.lib
)
endif()
if(EMSCRIPTEN)
set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html")

View File

@ -19,8 +19,9 @@
#include <emscripten/emscripten.h>
#endif
#include <SDL3/SDL_test_common.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test_common.h>
#define NUM_OBJECTS 100

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="mp uap">
<Identity Name="5a2cfb51-9dcf-4830-81e5-49472403b04d"
Publisher="O=libsdl.org"
Version="1.0.0.0" />
<mp:PhoneIdentity
PhoneProductId="5a2cfb51-9dcf-4830-81e5-49472403b04d"
PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>$<TARGET_PROPERTY:NAME></DisplayName>
<PublisherDisplayName>libsdl.org</PublisherDisplayName>
<Logo>logo-50x50.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily
Name="Windows.Universal"
MinVersion="10.0.0.0"
MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App"
Executable="$<TARGET_PROPERTY:NAME>.exe"
EntryPoint="$<TARGET_PROPERTY:NAME>.App">
<uap:VisualElements
DisplayName="$<TARGET_PROPERTY:NAME>"
Description="$<TARGET_PROPERTY:NAME>"
BackgroundColor="#FFFFFF"
Square150x150Logo="square-150x150.png"
Square44x44Logo="square-44x44.png">
<uap:SplashScreen Image="splash-620x300.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<DeviceCapability Name="microphone" />
</Capabilities>
</Package>

BIN
test/uwp/logo-50x50.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
test/uwp/splash-620x300.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
test/uwp/square-150x150.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
test/uwp/square-44x44.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB