pspdev / psplibraries

A script to automatically build open-source libraries for PSP homebrew development.
47 stars 45 forks source link

Add SDL2 port from Joel16 #45

Closed sharkwouter closed 4 years ago

sharkwouter commented 4 years ago

I'll leave this as a draft for now. This should probably include a patch file. I'm still not quite sure what the m4 files do, so I didn't include them.

sharkwouter commented 4 years ago

This is much more incomplete than I though. The build script will need to be changed to make cmake able to detect SDL2.

sharkwouter commented 4 years ago

This PR is probably good enough for use right now. It's not ideal because it doesn't package the files which can help build systems like cmake to find SDL2, but my attempts at using other build systems like autotools and cmake have been unsuccessful.

dbeef commented 4 years ago

As you are building with a custom PSP Makefile it's understandable that there is no cmake config script exported, the very same situation is with SDL 1.25, as it utilizes autogen to build artifacts.

Workaround for this situation in cmake is to just pass linking flags manually, as imported SDL target is unavailable:

    target_link_libraries(Dependencies INTERFACE
            -L${PSPDEV}/psp/lib
            -lSDLmain
            -lSDL
            -lg
     ...

For me it's a good tradeoff to have SDL2, writing custom CMakeLists.txt just to build SDL2 is not worth it when we have this makefile already. You have my approve, good job, just address my comment above.

EDIT: I just realized that with no SDL2main target there will be no sceModuleInfo implicitly defined, and .PBP won't be created successfully. I am not satisfied with this - will provide you some help with actually adding this target.

dbeef commented 4 years ago

Hey @sharkwouter, I see the MR for SDL2main target has been merged:

https://github.com/joel16/SDL2/pull/1#event-3308529115

Could you please resolve the discussions above (copying libSDL2main.a)?

sharkwouter commented 4 years ago

Done, I've added SDL2main

dbeef commented 4 years ago

I rebuilt the toolchain from scratch for testing. Used the following sources as a sample:

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
add_executable(test-cmake main.cpp)

target_link_libraries(test-cmake PRIVATE SDL2main SDL2  ${PSP_LIBRARIES})

create_pbp_file(TARGET test-cmake)

main.cpp

#include <SDL2/SDL.h>
extern "C"
{
    int SDL_main(int argc, char *argv[])
    {
        while(true){}
    }
}

Builds, links and runs on PPSSPP - merging.