From 1275b70e9dabe9bb329bcea547d5c9b4539b183b Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:40:59 +0100 Subject: [PATCH] cmake: add playstation2 support --- CMakeLists.txt | 4 -- cmake/ee.cmake | 2 - cmake/librw-config.cmake.in | 4 +- .../CMakeDSMCompiler.cmake.in | 0 .../CMakeDSMInformation.cmake | 0 .../CMakeDetermineDSMCompiler.cmake | 0 .../CMakeTestDSMCompiler.cmake | 0 .../ps2toolchain/Platform/PlayStation2.cmake | 1 + cmake/ps2toolchain/cmaketoolchain.cmake | 68 +++++++++++++++++++ cmake/ps2toolchain/conanfile.py | 21 ++++++ .../{ => ps2toolchain}/toolchain_ps2_ee.cmake | 48 ++++++------- conan/playstation2 | 12 ++++ tools/ps2test/CMakeLists.txt | 25 +++++++ 13 files changed, 151 insertions(+), 34 deletions(-) delete mode 100644 cmake/ee.cmake rename cmake/{ => ps2toolchain}/CMakeDSMCompiler.cmake.in (100%) rename cmake/{ => ps2toolchain}/CMakeDSMInformation.cmake (100%) rename cmake/{ => ps2toolchain}/CMakeDetermineDSMCompiler.cmake (100%) rename cmake/{ => ps2toolchain}/CMakeTestDSMCompiler.cmake (100%) create mode 100644 cmake/ps2toolchain/Platform/PlayStation2.cmake create mode 100644 cmake/ps2toolchain/cmaketoolchain.cmake create mode 100644 cmake/ps2toolchain/conanfile.py rename cmake/{ => ps2toolchain}/toolchain_ps2_ee.cmake (51%) create mode 100644 conan/playstation2 create mode 100644 tools/ps2test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd3a10..9985d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,6 @@ project(librw C CXX) 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) set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9") else() diff --git a/cmake/ee.cmake b/cmake/ee.cmake deleted file mode 100644 index 4a75ab2..0000000 --- a/cmake/ee.cmake +++ /dev/null @@ -1,2 +0,0 @@ -include_directories(SYSTEM "${PS2SDK}/common/include") -include_directories(SYSTEM "${PS2SDK}/ee/include") diff --git a/cmake/librw-config.cmake.in b/cmake/librw-config.cmake.in index 2cae87f..8fb8868 100644 --- a/cmake/librw-config.cmake.in +++ b/cmake/librw-config.cmake.in @@ -10,10 +10,10 @@ if(LIBRW_PLATFORM_GL3) set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) + find_package(GLEW REQUIRED) if(LIBRW_GL3_GFXLIB STREQUAL "GLFW") - find_package(GLEW REQUIRED) find_package(glfw3 REQUIRED) - elseif(LIBRW_GL3_GFXLIB STREQUAL "GLFW") + elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2") find_package(SDL2 REQUIRED) endif() endif() diff --git a/cmake/CMakeDSMCompiler.cmake.in b/cmake/ps2toolchain/CMakeDSMCompiler.cmake.in similarity index 100% rename from cmake/CMakeDSMCompiler.cmake.in rename to cmake/ps2toolchain/CMakeDSMCompiler.cmake.in diff --git a/cmake/CMakeDSMInformation.cmake b/cmake/ps2toolchain/CMakeDSMInformation.cmake similarity index 100% rename from cmake/CMakeDSMInformation.cmake rename to cmake/ps2toolchain/CMakeDSMInformation.cmake diff --git a/cmake/CMakeDetermineDSMCompiler.cmake b/cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake similarity index 100% rename from cmake/CMakeDetermineDSMCompiler.cmake rename to cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake diff --git a/cmake/CMakeTestDSMCompiler.cmake b/cmake/ps2toolchain/CMakeTestDSMCompiler.cmake similarity index 100% rename from cmake/CMakeTestDSMCompiler.cmake rename to cmake/ps2toolchain/CMakeTestDSMCompiler.cmake diff --git a/cmake/ps2toolchain/Platform/PlayStation2.cmake b/cmake/ps2toolchain/Platform/PlayStation2.cmake new file mode 100644 index 0000000..bd2995e --- /dev/null +++ b/cmake/ps2toolchain/Platform/PlayStation2.cmake @@ -0,0 +1 @@ +set(CMAKE_EXECUTABLE_SUFFIX ".elf") diff --git a/cmake/ps2toolchain/cmaketoolchain.cmake b/cmake/ps2toolchain/cmaketoolchain.cmake new file mode 100644 index 0000000..6f83c96 --- /dev/null +++ b/cmake/ps2toolchain/cmaketoolchain.cmake @@ -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 "$" "${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() diff --git a/cmake/ps2toolchain/conanfile.py b/cmake/ps2toolchain/conanfile.py new file mode 100644 index 0000000..11c8628 --- /dev/null +++ b/cmake/ps2toolchain/conanfile.py @@ -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("\\", "/") diff --git a/cmake/toolchain_ps2_ee.cmake b/cmake/ps2toolchain/toolchain_ps2_ee.cmake similarity index 51% rename from cmake/toolchain_ps2_ee.cmake rename to cmake/ps2toolchain/toolchain_ps2_ee.cmake index 1f28073..95517d0 100644 --- a/cmake/toolchain_ps2_ee.cmake +++ b/cmake/ps2toolchain/toolchain_ps2_ee.cmake @@ -1,7 +1,9 @@ +cmake_minimum_required(VERSION 3.7) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") -set(CMAKE_SYSTEM_NAME "Generic") -set(CMAKE_SYSTEM_PROCESSOR "ee") +set(CMAKE_SYSTEM_NAME "PlayStation2") +set(CMAKE_SYSTEM_PROCESSOR "mipsel") set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -19,13 +21,8 @@ endif() set(PS2DEV "$ENV{PS2DEV}") set(PS2SDK "$ENV{PS2SDK}") -#set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS "asm;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_CXX_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_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip") -set(EE_LDFLAGS "" CACHE STRING "EE linker flags") -set(EE_ASFLAGS "-G0" CACHE STRING "EE assembler flags") - -set(EE_CRT0 "${PS2SDK}/ee/startup/crt0.o" CACHE FILEPATH "EE crt0 file") -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 " cru ") -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_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) @@ -62,3 +44,17 @@ 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 "$" "${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() diff --git a/conan/playstation2 b/conan/playstation2 new file mode 100644 index 0000000..ddad52b --- /dev/null +++ b/conan/playstation2 @@ -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] diff --git a/tools/ps2test/CMakeLists.txt b/tools/ps2test/CMakeLists.txt new file mode 100644 index 0000000..9ed4260 --- /dev/null +++ b/tools/ps2test/CMakeLists.txt @@ -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()