Commit bf2336078ca70eaeed8aef9dd8700553984db83e

Wouter Wijsman 2022-01-03T18:41:21

Make tests build for PSP and make them able to launch

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0dfb69d..bbc3df5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -4,7 +4,26 @@ project(SDL2 C)
 # Global settings for all of the test targets
 # FIXME: is this wrong?
 remove_definitions(-DUSING_GENERATED_CONFIG_H)
-link_libraries(SDL2_test SDL2-static)
+
+if(PSP)
+    link_libraries(
+        SDL2main
+        SDL2_test
+        SDL2-static
+        GL
+        pspvram
+        pspvfpu
+        pspdisplay
+        pspgu
+        pspge
+        pspaudio
+        pspctrl
+        psphprm
+        psppower
+    )
+else()
+    link_libraries(SDL2_test SDL2-static)
+endif()
 
 if(WINDOWS)
     # mingw32 must come before SDL2main to link successfully
@@ -123,7 +142,6 @@ set(NEEDS_RESOURCES
     testgamecontroller
     testshape
     testshader
-    testnative
     testspriteminimal
     testautomation
     testcustomcursor
@@ -135,9 +153,109 @@ set(NEEDS_RESOURCES
     testaudiohotplug
     testmultiaudio
 )
+if(NOT PSP)
+    set(NEEDS_RESOURCES ${NEEDS_RESOURCES} testnative)
+endif()
+
+if(PSP)
+    set(BUILD_EBOOT
+        ${NEEDS_RESOURCES}
+        testoffscreen
+        testvulkan
+        testbounds
+        testhotplug
+        testgles2
+        testhaptic
+        testrelative
+        testgl2
+        testsem
+        testdisplayinfo
+        testgles
+        teststreaming
+        testgeometry
+        testgesture
+        testfile
+        testdropfile
+        testdraw2
+        testviewport
+        testhittesting
+        checkkeys
+        testoverlay2
+        testver
+        testdrawchessboard
+        testsurround
+        testintersections
+        testmessage
+        testaudiocapture
+        testerror
+        testatomic
+        testjoystick
+        testrumble
+        testiconv
+        testfilesystem
+        testplatform
+        testthread
+        testkeys
+        testloadso
+        testmouse
+        testqsort
+        testime
+        testaudioinfo
+        testlock
+        checkkeysthreads
+        testtimer
+        testpower
+        testwm2
+        torturethread
+    )
+    foreach(APP IN LISTS BUILD_EBOOT)
+        create_pbp_file(
+            TARGET          ${APP}
+            TITLE           SDL-${APP}
+            ICON_PATH       NULL
+            BACKGROUND_PATH NULL
+            PREVIEW_PATH    NULL
+            BUILD_PRX
+            ENC_PRX
+        )
+        add_custom_command(
+            TARGET ${APP} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E make_directory
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/psp-${APP}
+        )
+        add_custom_command(
+            TARGET ${APP} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E rename
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/psp-${APP}/EBOOT.PBP
+        )
+        add_custom_command(
+            TARGET ${APP} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E rename
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/psp-${APP}/${APP}
+        )
+        add_custom_command(
+            TARGET ${APP} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E rename
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/psp-${APP}/${APP}.prx
+        )
+        add_custom_command(
+            TARGET ${APP} POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E remove
+            $<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
+        )
+    endforeach()
+endif()
+
 foreach(APP IN LISTS NEEDS_RESOURCES)
     foreach(RESOURCE_FILE ${RESOURCE_FILES})
-        add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
+        if(PSP)
+            add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/psp-${APP})
+        else()
+            add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
+        endif()
     endforeach(RESOURCE_FILE)
     if(APPLE)
         # Make sure resource files get installed into macOS/iOS .app bundles.