cmake: add playstation2 support

This commit is contained in:
Anonymous Maarten 2021-01-02 20:40:59 +01:00
parent 4d260a631b
commit 1275b70e9d
13 changed files with 151 additions and 34 deletions

View File

@ -3,10 +3,6 @@ project(librw C CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(PS2DEV AND EE)
include("${CMAKE_CURRENT_LIST_DIR}/cmake/ee.cmake")
endif()
if(WIN32) if(WIN32)
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9") set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
else() else()

View File

@ -1,2 +0,0 @@
include_directories(SYSTEM "${PS2SDK}/common/include")
include_directories(SYSTEM "${PS2SDK}/ee/include")

View File

@ -10,10 +10,10 @@ if(LIBRW_PLATFORM_GL3)
set(OpenGL_GL_PREFERENCE GLVND) set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
find_package(glfw3 REQUIRED) find_package(glfw3 REQUIRED)
elseif(LIBRW_GL3_GFXLIB STREQUAL "GLFW") elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
endif() endif()
endif() endif()

View File

@ -0,0 +1 @@
set(CMAKE_EXECUTABLE_SUFFIX ".elf")

View File

@ -0,0 +1,68 @@
cmake_minimum_required(VERSION 3.7)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(CMAKE_SYSTEM_NAME "PlayStation2")
set(CMAKE_SYSTEM_PROCESSOR "mipsel")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
if(NOT DEFINED ENV{PS2DEV})
message(FATAL_ERROR "Need environment variable PS2DEV set")
endif()
if(NOT DEFINED ENV{PS2SDK})
message(FATAL_ERROR "Need environment variable PS2SDK set")
endif()
set(PS2DEV "$ENV{PS2DEV}")
set(PS2SDK "$ENV{PS2SDK}")
if(NOT IS_DIRECTORY "${PS2DEV}")
message(FATAL_ERROR "PS2DEV must contain a folder path (${PS2DEV})")
endif()
if(NOT IS_DIRECTORY "${PS2SDK}")
message(FATAL_ERROR "PS2SDK must contain a folder path (${PS2SDK})")
endif()
set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm")
set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc")
set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++")
set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++")
set(CMAKE_DSM_COMPILER "${PS2DEV}/dvp/bin/dvp-as")
set(CMAKE_AR "${PS2DEV}/ee/bin/ee-ar" CACHE FILEPATH "archiver")
set(CMAKE_LINKER "${PS2DEV}/ee/bin/ee-ld")
set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib")
set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip")
set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d")
set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(PS2 1)
set(EE 1)
function(add_erl_executable OUTFILE TARGET)
get_property(output_dir TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY)
set(outfile "${output_dir}/${TARGET}.erl")
add_custom_command(OUTPUT "${outfile}"
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET}>" "${outfile}"
COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}"
DEPENDS ${TARGET}
)
add_custom_target("${TARGET}_erl" ALL
DEPENDS "${outfile}"
)
set("${OUTFILE}" "${outfile}" PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,21 @@
from conans import ConanFile
import os
import shutil
class Ps2devCMakeToolchainConan(ConanFile):
name = "ps2dev-cmaketoolchain"
description = "CMake toolchain script for ps2dev"
topics = "ps2", "sdk", "library", "sony", "playstation", "ps2"
def export_sources(self):
self.copy("*.cmake*", dst="cmake")
self.copy("Platform", dst="cmake")
def package(self):
shutil.copytree(os.path.join(self.source_folder, "cmake"),
os.path.join(self.package_folder, "cmake"))
def package_info(self):
self.user_info.cmake_dir = os.path.join(self.package_folder, "cmake").replace("\\", "/")
self.user_info.cmake_toolchain_file = os.path.join(self.package_folder, "cmake", "cmaketoolchain.cmake").replace("\\", "/")

View File

@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.7)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(CMAKE_SYSTEM_NAME "Generic") set(CMAKE_SYSTEM_NAME "PlayStation2")
set(CMAKE_SYSTEM_PROCESSOR "ee") set(CMAKE_SYSTEM_PROCESSOR "mipsel")
set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -19,13 +21,8 @@ endif()
set(PS2DEV "$ENV{PS2DEV}") set(PS2DEV "$ENV{PS2DEV}")
set(PS2SDK "$ENV{PS2SDK}") set(PS2SDK "$ENV{PS2SDK}")
#set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS "asm;dsm")
set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm") set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".erl")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc") set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc")
set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++") set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++")
set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++") set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++")
@ -35,25 +32,10 @@ set(CMAKE_LINKER "${PS2DEV}/ee/bin/ee-ld")
set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib") set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib")
set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip") set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip")
set(EE_LDFLAGS "" CACHE STRING "EE linker flags") set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(EE_ASFLAGS "-G0" CACHE STRING "EE assembler flags") set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"")
set(EE_CRT0 "${PS2SDK}/ee/startup/crt0.o" CACHE FILEPATH "EE crt0 file") set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d")
set_source_files_properties("${EE_CRT0}" PROPERTIES EXTERNAL_OBJECT ON)
set(EE_LINKSCRIPT "${PS2SDK}/ee/startup/linkfile" CACHE FILEPATH "EE link script")
#set(EE_CFLAGS " -nostdlib -fno-common -D_EE" CACHE STRING "EE C/CXX compiler flags")
set(EE_CFLAGS "-D_EE")
set(CMAKE_C_FLAGS_INIT "${EE_CFLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${EE_CFLAGS}")
#set(CMAKE_ASM_FLAGS_INIT "${EE_CFLAGS}")
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> cru <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${CMAKE_C_CREATE_STATIC_LIBRARY}")
set(CMAKE_ASM_CREATE_STATIC_LIBRARY "${CMAKE_C_CREATE_STATIC_LIBRARY}")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-mno-crt0 -T\"${PS2SDK}/ee/startup/linkfile\" \"${EE_CRT0}\" -L\"${PS2SDK}/ee/lib\"")
set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee") set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
@ -62,3 +44,17 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(PS2 1) set(PS2 1)
set(EE 1) set(EE 1)
function(add_erl_executable OUTFILE TARGET)
get_property(output_dir TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY)
set(outfile "${output_dir}/${TARGET}.erl")
add_custom_command(OUTPUT "${outfile}"
COMMAND "${CMAKE_COMMAND}" -E copy "$<TARGET_FILE:${TARGET}>" "${outfile}"
COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}"
DEPENDS ${TARGET}
)
add_custom_target("${TARGET}_erl" ALL
DEPENDS "${outfile}"
)
set("${OUTFILE}" "${outfile}" PARENT_SCOPE)
endfunction()

12
conan/playstation2 Normal file
View File

@ -0,0 +1,12 @@
[settings]
os=Playstation2
arch=mips
compiler=gcc
compiler.version=3.2
compiler.libcxx=libstdc++
build_type=Release
[options]
librw:platform=ps2
[build_requires]
ps2dev-ps2toolchain/unknown@madebr/testing
[env]

View File

@ -0,0 +1,25 @@
add_executable(ps2test
gs.h
main.cpp
mem.h
ps2.h
vu/defaultpipe.dsm
vu/skinpipe.dsm
)
target_link_libraries(ps2test
PUBLIC
librw
kernel
)
add_erl_executable(PS2TEST_ERL ps2test)
if(LIBRW_INSTALL)
install(TARGETS ps2test
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(FILES "${PS2TEST_ERL}"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
endif()