Skip to content

Commit

Permalink
PS4
Browse files Browse the repository at this point in the history
  • Loading branch information
dmiller423 committed May 29, 2019
1 parent a83266d commit 0aba0e4
Show file tree
Hide file tree
Showing 27 changed files with 1,921 additions and 27 deletions.
81 changes: 68 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,21 @@ if(CYGWIN)
set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
endif()

add_definitions(-DUSING_GENERATED_CONFIG_H)
# General includes
include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)

######### *FIXME*

if(PS4 OR ORBIS)
set(USE_GENERATED_CONFIG Off)
else()
set(USE_GENERATED_CONFIG On)
endif()

if(USE_GENERATED_CONFIG)
add_definitions(-DUSING_GENERATED_CONFIG_H)
include_directories(${SDL2_BINARY_DIR}/include)
endif()

include_directories(${SDL2_SOURCE_DIR}/include)
if(USE_GCC OR USE_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter ${SDL2_SOURCE_DIR}/src/video/khronos")
else()
Expand All @@ -264,6 +276,15 @@ if(EMSCRIPTEN)
set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
endif()

if(PS4 OR ORBIS)
set(SDL_ATOMIC_ENABLED_BY_DEFAULT ON)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
set(SDL_THREADS_ENABLED_BY_DEFAULT ON)
set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
endif()

if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
endif()
Expand Down Expand Up @@ -971,6 +992,42 @@ if(EMSCRIPTEN)
set(SDL_VIDEO_RENDER_OGL_ES2 1)
endif()
endif()
elseif(PS4 OR ORBIS)
CheckPTHREAD()
if(SDL_AUDIO)
set(SDL_AUDIO_DRIVER_PS4 1)
file(GLOB PS4_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/ps4/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${PS4_AUDIO_SOURCES})
set(HAVE_SDL_AUDIO TRUE)
endif()
# if(SDL_FILESYSTEM)
# set(SDL_FILESYSTEM_PS4 1)
# file(GLOB PS4_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/ps4/*.c)
# set(SOURCE_FILES ${SOURCE_FILES} ${PS4_FILESYSTEM_SOURCES})
# set(HAVE_SDL_FILESYSTEM TRUE)
# endif()
if(SDL_JOYSTICK)
set(SDL_JOYSTICK_PS4 1)
file(GLOB PS4_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/ps4/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${PS4_JOYSTICK_SOURCES})
set(HAVE_SDL_JOYSTICK TRUE)
endif()
if(SDL_TIMERS)
set(SDL_TIMER_UNIX 1)
file(GLOB TIMER_SOURCES ${SDL2_SOURCE_DIR}/src/timer/unix/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${TIMER_SOURCES})
set(HAVE_SDL_TIMERS TRUE)

if(CLOCK_GETTIME)
set(HAVE_CLOCK_GETTIME 1)
endif()
endif()
if(SDL_VIDEO)
set(SDL_VIDEO_DRIVER_PS4 1)
file(GLOB PS4_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/ps4/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${PS4_VIDEO_SOURCES})
set(HAVE_SDL_VIDEO TRUE)
endif()
elseif(UNIX AND NOT APPLE AND NOT ANDROID)
if(SDL_AUDIO)
if(SYSV5 OR SOLARIS OR HPUX)
Expand Down Expand Up @@ -1628,8 +1685,10 @@ endif()
# endif()
# endif()

configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
"${SDL2_BINARY_DIR}/include/SDL_config.h")
if(USE_GENERATED_CONFIG)
configure_file("${SDL2_SOURCE_DIR}/include/SDL_config.h.cmake"
"${SDL2_BINARY_DIR}/include/SDL_config.h")
endif()

# Prepare the flags and remove duplicates
if(EXTRA_LDFLAGS)
Expand Down Expand Up @@ -1681,14 +1740,10 @@ if(NOT WINDOWS OR CYGWIN)
# MESSAGE(STATUS "SDL_LIBS: ${SDL_LIBS}")
# MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")

configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
"${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
"${SDL2_BINARY_DIR}/sdl2-config")
configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
"${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
"${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in" "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in" "${SDL2_BINARY_DIR}/sdl2-config")
configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in" "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in" "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
endif()

##### Info output #####
Expand Down
40 changes: 40 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"environments": [
{
// Could set things up here instead of the toolchain file, instead make this global env. and use a TOOLCHAIN var
//"INCLUDE": "${env.INCLUDE};",

"TOOLCHAIN_FILE": "ps4sdk.cmake",
"environment": "toolchain.generic"
}
],
"configurations": [
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
//"variables": [ { "TOOLCHAIN_FILE": "ps4sdk.cmake" } ], // This doesn't seem to override toolchain.generic:: [env.]TOOLCHAIN_FILE , or pass to the cmake cache

"name": "PS4 SDK",
"generator": "Ninja",
"description": "TemplateDescription_Localize_PS4SDK",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "toolchain.generic" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "D:\\dev\\orbis_sdk_500\\portlibs\\SDL",
"cmakeCommandArgs": "-DCMAKE_TOOLCHAIN_FILE=${projectDir}\\cmake\\ps4sdk.cmake", // ${projectDir}/cmake/${env.TOOLCHAIN_FILE}
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}
166 changes: 166 additions & 0 deletions cmake/ps4sdk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
## ps4sdk.cmake - Playstation4 cross-compile
#
set(CMAKE_SYSTEM_NAME Orbis) # this one is important
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_SYSTEM_VERSION 9) # this one not so much



### This shit is very WIP ###
#
## TODO: Check for





#SCE_ORBIS_SDK_DIR=D:\Dev\PS4\SCE\PS4SDK
#SCE_ROOT_DIR=D:\Dev\PS4\SCE


if (NOT "" STREQUAL "$ENV{SCE_ORBIS_SDK_DIR}")

file(TO_CMAKE_PATH $ENV{SCE_ORBIS_SDK_DIR} SCESDK)
#set(SCESDK $ENV{SCE_ORBIS_SDK_DIR}) # SCE_ORBIS_SDK_DIR - requires change below ./SCE/PS4SDK : ./
endif()


if (NOT "" STREQUAL "${SCESDK}") # defaults to sce sdk if available
set(USE_SCE ON)
set(PS4SDK ${SCESDK})
endif()



if ("" STREQUAL "${PS4SDK}") # Not found or passed in

if(NOT "" STREQUAL "$ENV{PS4SDK}") # Try env var
set(PS4SDK $ENV{PS4SDK})
else() # else defaults
if ("Windows" STREQUAL "${CMAKE_HOST_SYSTEM_NAME}")
set(PS4SDK "D:/Dev/ps4sdk")
else()
set(PS4SDK "/opt/ps4/sdk")
endif()
endif()

endif()


set(TAUON_SDK ${PS4SDK}/tauon)



if(USE_SCE)
#
set(PS4HOST ${PS4SDK}/host_tools)
set(PS4TARGET ${PS4SDK}/target)

set(CMAKE_FIND_ROOT_PATH ${PS4TARGET}) # where is the target environment


set(toolPrefix "orbis-")
set(toolSuffix ".exe")


file(TO_CMAKE_PATH ${PS4HOST}/bin/${toolPrefix}clang${toolSuffix} CMAKE_C_COMPILER)
file(TO_CMAKE_PATH ${PS4HOST}/bin/${toolPrefix}clang++${toolSuffix} CMAKE_CXX_COMPILER)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -masm=intel -fms-extensions -fasm-blocks ")

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nobuiltininc ")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc -nostdinc++ ")

# -nobuiltininc Disable builtin #include directories
# -nostdinc++ Disable standard #include directories for the C++ standard library


set (PS4_inc_dirs
# ${TAUON_SDK}/include
${PS4TARGET}/include
${PS4TARGET}/include_common
)

# set (PS4_link_dirs
# "${PS4TARGET}/lib"
# "${PS4TARGET}/tauon/lib"
# )


#LDFLAGS += -L $(TAUON_SDK_DIR)/lib -L $(SCE_ORBIS_SDK_DIR)/target/lib
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s -Wl,--addressing=non-aslr,--strip-unused-data ")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L ${TAUON_SDK}/lib")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L ${PS4TARGET}/lib")

message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}")
#
else()
#
set(triple "x86_64-scei-ps4")

set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)


set (PS4_inc_dirs
${TAUON_SDK}/include

# ${PS4SDK}/include
# ${PS4SDK}/tauon/include
)

# set (PS4_link_dirs
# "${PS4SDK}/lib"
# "${PS4SDK}/tauon/lib"
# )


set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s -Wl,--addressing=non-aslr,--strip-unused-data -L${TAUON_SDK}/lib")
#
endif()
### IF NOT SCE SDK
#



set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) # for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)


include_directories(${PS4_inc_dirs})




set(PS4 ON)
set(ORBIS ON)

add_definitions(-DPS4)

if(PS4)
set(binSuffix ".elf")
link_libraries(SceSystemService_stub_weak SceUserService_stub_weak ScePosix_stub_weak
ScePad_stub_weak SceAudioOut_stub_weak SceSysmodule_stub_weak
libc_stub_weak.a
#${PS4TARGET}/lib/libc_stub_weak.a
#SceLibcInternal_tau_stub
# SceSysmodule_tau_stub_weak
# kernel_tau_stub_weak SceSysmodule_tau_stub_weak SceSystemService_stub_weak SceSystemService_tau_stub_weak SceShellCoreUtil_tau_stub_weak ScePigletv2VSH_tau_stub_weak kernel_util
)
endif()


#set(LINK_DIRECTORIES ${PS4_link_dirs})
#link_directories(${PS4_link_dirs})








2 changes: 2 additions & 0 deletions include/SDL_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "SDL_config_android.h"
#elif defined(__PSP__)
#include "SDL_config_psp.h"
#elif defined(__ORBIS__) || defined(PS4)
#include "SDL_config_ps4.h"
#elif defined(__OS2__)
#include "SDL_config_os2.h"
#else
Expand Down
Loading

0 comments on commit 0aba0e4

Please sign in to comment.