Make it possible to build with cmake (#4)

* Initial support for building with cmake

This is still WIP. I still need to test the resulting libraries and some
changes to the sdl2.pc and sdl2config files are still required to make
them useful.

* Fix 2 errors when loading SDL2 made with cmake

* Disable more functions, enable renderer and add missing source file

Threading was missing a source file

* Fix errors when building psp renderer code

* Add variables for sdl2-config and pkgconf

It doesn't quite work yet, because the EXTRA_LIBS list gets reordered
for some reason.

* Fixed library order returned by sdl2-config --libs

Somehow listtostr reverses lists

* Removed NOT in check for PSP_PLATFORM

* Removed uneccessary newlines

* Don't reorder code as much to pass checks

Now the execution patch stays intact

* Undo small change in execution

This wasn't a necessary change

* Remove double ;
This commit is contained in:
Wouter Wijsman 2020-12-07 15:33:10 +01:00 committed by GitHub
parent 17769844cb
commit 768e689ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 166 additions and 48 deletions

View File

@ -151,7 +151,7 @@ if(APPLE OR ARCH_64)
set(OPT_DEF_SSEMATH ON)
endif()
endif()
if(UNIX OR MINGW OR MSYS)
if(UNIX OR MINGW OR MSYS OR PLATFORM_PSP)
set(OPT_DEF_LIBC ON)
endif()
@ -1554,6 +1554,104 @@ elseif(HAIKU)
endif()
CheckPTHREAD()
elseif(PLATFORM_PSP)
# Disable some functions which cmake thinks exist but don't
set(HAVE_SYSCTLBYNAME FALSE)
set(HAVE_FSEEKO64 FALSE)
set(HAVE_SYSCONF FALSE)
set(HAVE_SIGACTION FALSE)
set(HAVE_FOPEN64 FALSE)
set(HAVE__STRREV FALSE)
set(HAVE__STRUPR FALSE)
set(HAVE__STRLWR FALSE)
set(HAVE_ITOA FALSE)
set(HAVE__UITOA FALSE)
set(HAVE__LTOA FALSE)
set(HAVE__ULTOA FALSE)
set(HAVE__I64TOA FALSE)
set(HAVE__UI64TOA FALSE)
# Set variables for pkgconf and sdl2config in reverse order
set(EXTRA_LIBS
pspuser
pspge
pspgu
pspvram
pspaudio
psprtc
pspirkeyb
psphprm
pspdisplay
pspvfpu
pspaudiolib
pspsdk
pspctrl
pspdebug
g
GL
m
)
set(SDL_CFLAGS "${SDL_CFLAGS} -Dmain=SDL_main -I$PSPDEV/psp/sdk/include")
list(APPEND SDL_LIBS "-lSDL2main")
list(APPEND EXTRA_LDFLAGS "-L$PSPDEV/psp/sdk/lib")
set(SDL_SHARED FALSE)
# Set source files for SDL2main
file(GLOB PSP_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/psp/*.c)
set(SDLMAIN_SOURCES ${SDLMAIN_SOURCES} ${PSP_MAIN_SOURCES})
set(HAVE_SDL_LOADSO FALSE)
set(HAVE_SDL_FILESYSTEM FALSE)
set(HAVE_SDL_SENSORS FALSE)
set(HAVE_SDL_HAPTIC FALSE)
if(SDL_AUDIO)
set(SDL_AUDIO_DRIVER_PSP 1)
file(GLOB AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${AUDIO_SOURCES})
set(HAVE_SDL_AUDIO TRUE)
endif()
if(SDL_VIDEO)
set(SDL_VIDEO_DRIVER_PSP 1)
set(SDL_VIDEO_RENDER_PSP 1)
file(GLOB VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_SOURCES})
set(HAVE_SDL_VIDEO TRUE)
if(SDL_TIMERS)
set(SDL_TIMER_PSP 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
set(HAVE_SDL_TIMERS TRUE)
endif(SDL_TIMERS)
if(VIDEO_OPENGL)
set(SDL_VIDEO_OPENGL 1)
set(HAVE_VIDEO_OPENGL TRUE)
endif()
endif()
if(SDL_JOYSTICK)
set(SDL_JOYSTICK_PSP 1)
file(GLOB JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${JOYSTICK_SOURCES})
set(HAVE_SDL_JOYSTICK TRUE)
endif()
if(SDL_POWER)
set(SDL_POWER_PSP 1)
file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
set(HAVE_SDL_POWER TRUE)
endif()
if(SDL_THREADS)
set(SDL_THREAD_PSP 1)
file(GLOB THREAD_SOURCES ${SDL2_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL2_SOURCE_DIR}/src/thread/psp/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${THREAD_SOURCES})
set(HAVE_SDL_THREADS TRUE)
endif()
endif()
if(VIDEO_VULKAN)
@ -1664,7 +1762,11 @@ if(NOT WINDOWS OR CYGWIN)
# Clean up the different lists
listtostr(EXTRA_LIBS _EXTRA_LIBS "-l")
set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
if(PLATFORM_PSP)
set(SDL_STATIC_LIBS ${EXTRA_LDFLAGS} ${_EXTRA_LIBS} ${SDL_LIBS})
else()
set(SDL_STATIC_LIBS ${SDL_LIBS} ${EXTRA_LDFLAGS} ${_EXTRA_LIBS})
endif()
list(REMOVE_DUPLICATES SDL_STATIC_LIBS)
listtostr(SDL_STATIC_LIBS _SDL_STATIC_LIBS)
set(SDL_STATIC_LIBS ${_SDL_STATIC_LIBS})

View File

@ -263,6 +263,7 @@
#cmakedefine SDL_AUDIO_DRIVER_PAUDIO @SDL_AUDIO_DRIVER_PAUDIO@
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
#cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
#cmakedefine SDL_AUDIO_DRIVER_PSP @SDL_AUDIO_DRIVER_PSP@
#cmakedefine SDL_AUDIO_DRIVER_QSA @SDL_AUDIO_DRIVER_QSA@
#cmakedefine SDL_AUDIO_DRIVER_SNDIO @SDL_AUDIO_DRIVER_SNDIO@
#cmakedefine SDL_AUDIO_DRIVER_SNDIO_DYNAMIC @SDL_AUDIO_DRIVER_SNDIO_DYNAMIC@
@ -286,6 +287,7 @@
#cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@
#cmakedefine SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H@
#cmakedefine SDL_JOYSTICK_EMSCRIPTEN @SDL_JOYSTICK_EMSCRIPTEN@
#cmakedefine SDL_JOYSTICK_PSP @SDL_JOYSTICK_PSP@
#cmakedefine SDL_HAPTIC_DUMMY @SDL_HAPTIC_DUMMY@
#cmakedefine SDL_HAPTIC_LINUX @SDL_HAPTIC_LINUX@
#cmakedefine SDL_HAPTIC_IOKIT @SDL_HAPTIC_IOKIT@
@ -307,11 +309,13 @@
#cmakedefine SDL_THREAD_PTHREAD @SDL_THREAD_PTHREAD@
#cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX@
#cmakedefine SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP @SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP@
#cmakedefine SDL_THREAD_PSP @SDL_THREAD_PSP@
#cmakedefine SDL_THREAD_WINDOWS @SDL_THREAD_WINDOWS@
/* Enable various timer systems */
#cmakedefine SDL_TIMER_HAIKU @SDL_TIMER_HAIKU@
#cmakedefine SDL_TIMER_DUMMY @SDL_TIMER_DUMMY@
#cmakedefine SDL_TIMER_PSP @SDL_TIMER_PSP@
#cmakedefine SDL_TIMER_UNIX @SDL_TIMER_UNIX@
#cmakedefine SDL_TIMER_WINDOWS @SDL_TIMER_WINDOWS@
#cmakedefine SDL_TIMER_WINCE @SDL_TIMER_WINCE@
@ -323,6 +327,7 @@
#cmakedefine SDL_VIDEO_DRIVER_DIRECTFB @SDL_VIDEO_DRIVER_DIRECTFB@
#cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@
#cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
#cmakedefine SDL_VIDEO_DRIVER_PSP @SDL_VIDEO_DRIVER_PSP@
#cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
#cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
#cmakedefine SDL_VIDEO_DRIVER_RPI @SDL_VIDEO_DRIVER_RPI@
@ -372,6 +377,7 @@
#cmakedefine SDL_VIDEO_RENDER_OGL_ES2 @SDL_VIDEO_RENDER_OGL_ES2@
#cmakedefine SDL_VIDEO_RENDER_DIRECTFB @SDL_VIDEO_RENDER_DIRECTFB@
#cmakedefine SDL_VIDEO_RENDER_METAL @SDL_VIDEO_RENDER_METAL@
#cmakedefine SDL_VIDEO_RENDER_PSP @SDL_VIDEO_RENDER_PSP@
/* Enable OpenGL support */
#cmakedefine SDL_VIDEO_OPENGL @SDL_VIDEO_OPENGL@
@ -396,6 +402,7 @@
#cmakedefine SDL_POWER_HAIKU @SDL_POWER_HAIKU@
#cmakedefine SDL_POWER_EMSCRIPTEN @SDL_POWER_EMSCRIPTEN@
#cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@
#cmakedefine SDL_POWER_PSP @SDL_POWER_PSP@
/* Enable system filesystem support */
#cmakedefine SDL_FILESYSTEM_ANDROID @SDL_FILESYSTEM_ANDROID@

View File

@ -132,7 +132,7 @@
#define SDL_THREAD_PSP 1
/* Enable the PSP timer support (src/timer/psp/\*.c) */
#define SDL_TIMERS_PSP 1
#define SDL_TIMER_PSP 1
/* Enable the PSP joystick driver (src/joystick/psp/\*.c) */
#define SDL_JOYSTICK_PSP 1

View File

@ -174,11 +174,11 @@ typedef struct
static int
TextureNextPow2(unsigned int w)
{
unsigned int n = 2;
if(w == 0)
return 0;
unsigned int n = 2;
while(w > n)
n <<= 1;
@ -218,31 +218,32 @@ StartDrawing(SDL_Renderer * renderer)
int
TextureSwizzle(PSP_TextureData *psp_texture)
{
int bytewidth, height;
int rowblocks, rowblocksadd;
unsigned int blockaddress;
unsigned int *src = NULL;
unsigned char *data = NULL;
if(psp_texture->swizzled)
return 1;
int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
int height = psp_texture->size / bytewidth;
bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
height = psp_texture->size / bytewidth;
int rowblocks = (bytewidth>>4);
int rowblocksadd = (rowblocks-1)<<7;
unsigned int blockaddress = 0;
unsigned int *src = (unsigned int*) psp_texture->data;
rowblocks = (bytewidth>>4);
rowblocksadd = (rowblocks-1)<<7;
blockaddress = 0;
src = (unsigned int*) psp_texture->data;
unsigned char *data = NULL;
data = malloc(psp_texture->size);
int j;
for(j = 0; j < height; j++, blockaddress += 16)
for(int j = 0; j < height; j++, blockaddress += 16)
{
unsigned int *block;
block = (unsigned int*)&data[blockaddress];
int i;
for(i = 0; i < rowblocks; i++)
for(int i = 0; i < rowblocks; i++)
{
*block++ = *src++;
*block++ = *src++;
@ -263,23 +264,27 @@ TextureSwizzle(PSP_TextureData *psp_texture)
}
int TextureUnswizzle(PSP_TextureData *psp_texture)
{
int blockx, blocky;
int bytewidth, height;
int widthblocks, heightblocks;
int dstpitch, dstrow;
unsigned int *src = NULL;
unsigned char *ydst = NULL;
unsigned char *data = NULL;
if(!psp_texture->swizzled)
return 1;
int blockx, blocky;
bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
height = psp_texture->size / bytewidth;
int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
int height = psp_texture->size / bytewidth;
widthblocks = bytewidth/16;
heightblocks = height/8;
int widthblocks = bytewidth/16;
int heightblocks = height/8;
dstpitch = (bytewidth - 16)/4;
dstrow = bytewidth * 8;
int dstpitch = (bytewidth - 16)/4;
int dstrow = bytewidth * 8;
unsigned int *src = (unsigned int*) psp_texture->data;
unsigned char *data = NULL;
src = (unsigned int*) psp_texture->data;
data = malloc(psp_texture->size);
@ -288,9 +293,7 @@ int TextureUnswizzle(PSP_TextureData *psp_texture)
sceKernelDcacheWritebackAll();
int j;
unsigned char *ydst = (unsigned char *)data;
ydst = (unsigned char *)data;
for(blocky = 0; blocky < heightblocks; ++blocky)
{
@ -302,7 +305,7 @@ int TextureUnswizzle(PSP_TextureData *psp_texture)
block = (unsigned int*)xdst;
for(j = 0; j < 8; ++j)
for(int j = 0; j < 8; ++j)
{
*(block++) = *(src++);
*(block++) = *(src++);
@ -623,9 +626,11 @@ PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
static int
PSP_RenderClear(SDL_Renderer * renderer)
{
int color;
/* start list */
StartDrawing(renderer);
int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
sceGuClearColor(color);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
@ -639,8 +644,9 @@ PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
{
int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
int i;
VertV* vertices = NULL;
StartDrawing(renderer);
VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
for (i = 0; i < count; ++i) {
vertices[i].x = points[i].x;
@ -663,8 +669,9 @@ PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
{
int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
int i;
VertV* vertices = NULL;
StartDrawing(renderer);
VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
for (i = 0; i < count; ++i) {
vertices[i].x = points[i].x;
@ -862,6 +869,10 @@ PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
float u0, v0, u1, v1;
unsigned char alpha;
float centerx, centery;
float c, s;
float cw, sw, ch, sh;
VertTV* vertices = NULL;
x = dstrect->x;
y = dstrect->y;
@ -896,8 +907,6 @@ PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
x += centerx;
y += centery;
float c, s;
MathSincos(degToRad(angle), &s, &c);
/* width *= 0.5f; */
@ -906,12 +915,12 @@ PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
height -= centery;
float cw = c*width;
float sw = s*width;
float ch = c*height;
float sh = s*height;
cw = c*width;
sw = s*width;
ch = c*height;
sh = s*height;
VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
vertices[0].u = u0;
vertices[0].v = v0;

View File

@ -20,7 +20,7 @@
*/
#include "../../SDL_internal.h"
#ifdef SDL_TIMERS_PSP
#ifdef SDL_TIMER_PSP
#include "SDL_thread.h"
#include "SDL_timer.h"
@ -53,13 +53,13 @@ SDL_TicksQuit(void)
Uint32 SDL_GetTicks(void)
{
struct timeval now;
Uint32 ticks;
if (!ticks_started) {
SDL_TicksInit();
}
struct timeval now;
Uint32 ticks;
gettimeofday(&now, NULL);
ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
return(ticks);
@ -85,7 +85,7 @@ void SDL_Delay(Uint32 ms)
sceKernelDelayThreadCB(ms * 1000);
}
#endif /* SDL_TIMERS_PSP */
#endif /* SDL_TIMER_PSP */
/* vim: ts=4 sw=4
*/