Last active
June 16, 2020 22:54
-
-
Save mwpenny/00c51d3c2a45c4ec0002ef8645efc09d to your computer and use it in GitHub Desktop.
PSP CMake toolchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on PSP.cmake by @take-cheeze (https://gist.github.com/take-cheeze/1078147) | |
set(CMAKE_SYSTEM_NAME Generic) | |
set(PSP TRUE) | |
add_definitions(-D__PSP__) | |
# Prevent "relocation truncated to fit" errors | |
set(CMAKE_C_FLAGS -G0) | |
set(CMAKE_CXX_FLAGS -G0) | |
set(CMAKE_EXE_LINKER_FLAGS -G0) | |
# Find PSP SDK executables | |
foreach(i "psp-config" "mksfo" "pack-pbp" "psp-fixup-imports" "psp-strip" "psp-prxgen" "psp-build-exports" "psp-gcc" "psp-g++") | |
string(REGEX REPLACE "-" "_" EXE_NAME ${i}) | |
string(TOUPPER ${EXE_NAME} EXE_NAME) | |
find_program(${EXE_NAME} ${i}) | |
if(${${EXE_NAME}} MATCHES "-NOTFOUND") | |
message(FATAL_ERROR "${i} not found") | |
else() | |
message(STATUS "${i} found") | |
endif() | |
endforeach() | |
# Add SDK directories to find, header, and lib search paths | |
set(CMAKE_FIND_ROOT_PATH "") | |
foreach(i "--pspsdk-path" "--psp-prefix" "--pspdev-path") | |
string(REGEX REPLACE "--" "" PATH_NAME ${i}) | |
string(REGEX REPLACE "-" "_" PATH_NAME ${PATH_NAME}) | |
string(TOUPPER ${PATH_NAME} PATH_NAME) | |
execute_process( | |
COMMAND ${PSP_CONFIG} ${i} | |
OUTPUT_VARIABLE PATH_VALUE | |
OUTPUT_STRIP_TRAILING_WHITESPACE | |
) | |
set(${PATH_NAME} ${PATH_VALUE}) | |
list(APPEND CMAKE_FIND_ROOT_PATH "${PATH_VALUE}") | |
include_directories("${PATH_VALUE}/include") | |
link_directories("${PATH_VALUE}/lib") | |
list(APPEND CMAKE_EXE_LINKER_FLAGS "-L${PATH_VALUE}/lib") | |
endforeach() | |
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 install path | |
set(CMAKE_INSTALL_PREFIX ${PSP_PREFIX} CACHE PATH "") | |
# Large memory | |
if(PSP_LARGE_MEMORY) | |
find_program(MKSFOEX "mksfoex") | |
if(NOT MKSFOEX) | |
message(FATAL_ERROR "mksfoex not found") | |
else() | |
message(STATUS "mksfoex found") | |
endif() | |
set(MKSFO ${MKSFOEX} -d MEMSIZE=1) | |
endif() | |
# Set compiler | |
set(CMAKE_C_COMPILER ${PSP_GCC}) | |
set(CMAKE_CXX_COMPILER ${PSP_G++}) | |
set(CMAKE_C_STANDARD 99) | |
set(CMAKE_CXX_STANDARD 98) | |
# Bare minimum needed to link | |
set(LINK_LIBRARIES -lc -lpspuser -lpspkernel -lc) | |
if(BUILD_PRX) | |
list(APPEND CMAKE_EXE_LINKER_FLAGS | |
"-specs=${PSPSDK_PATH}/lib/prxspecs" | |
"-Wl,-q,-T${PSPSDK_PATH}/lib/linkfile.prx" | |
) | |
list(APPEND LINK_LIBRARIES ${PSPSDK_PATH}/lib/prxexports.o) | |
endif() | |
# Set ldflags | |
list(APPEND CMAKE_EXE_LINKER_FLAGS "-lc") | |
string(REPLACE ";" " " CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") | |
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} CACHE STRING "") | |
# EBOOT properties | |
if(NOT PSP_EBOOT_TITLE) | |
set(PSP_EBOOT_TITLE ${PROJECT_NAME}) | |
endif() | |
if(NOT PSP_EBOOT_SFO) | |
set(PSP_EBOOT_SFO "PARAM.SFO") | |
endif() | |
if(NOT PSP_EBOOT_ICON) | |
set(PSP_EBOOT_ICON "NULL") | |
endif() | |
if(NOT PSP_EBOOT_ICON1) | |
set(PSP_EBOOT_ICON1 "NULL") | |
endif() | |
if(NOT PSP_EBOOT_UNKPNG) | |
set(PSP_EBOOT_UNKPNG "NULL") | |
endif() | |
if(NOT PSP_EBOOT_PIC1) | |
set(PSP_EBOOT_PIC1 "NULL") | |
endif() | |
if(NOT PSP_EBOOT_SND0) | |
set(PSP_EBOOT_SND0 "NULL") | |
endif() | |
if(NOT PSP_EBOOT_PSAR) | |
set(PSP_EBOOT_PSAR "NULL") | |
endif() | |
if(NOT PSP_EBOOT) | |
set(PSP_EBOOT "EBOOT.PBP") | |
endif() | |
function(add_psp_executable elf) | |
if(BUILD_PRX) | |
add_custom_command(TARGET ${elf} POST_BUILD | |
COMMAND ${PSP_FIXUP_IMPORTS} ${elf} | |
COMMAND ${PSP_PRXGEN} ${elf} ${elf}.prx | |
COMMAND ${MKSFO} "${PSP_EBOOT_TITLE}" ${PSP_EBOOT_SFO} | |
COMMAND ${PACK_PBP} ${PSP_EBOOT} ${PSP_EBOOT_SFO} ${PSP_EBOOT_ICON} ${PSP_EBOOT_ICON1} ${PSP_EBOOT_UNKPNG} ${PSP_EBOOT_PIC1} ${PSP_EBOOT_SND0} ${elf}.prx ${PSP_EBOOT_PSAR} | |
) | |
else() | |
add_custom_command(TARGET ${elf} POST_BUILD | |
COMMAND ${PSP_FIXUP_IMPORTS} ${elf} | |
COMMAND ${MKSFO} "${PSP_EBOOT_TITLE}" ${PSP_EBOOT_SFO} | |
COMMAND ${PSP_STRIP} ${elf} -o ${elf}_stripped | |
COMMAND ${PACK_PBP} ${PSP_EBOOT} ${PSP_EBOOT_SFO} ${PSP_EBOOT_ICON} ${PSP_EBOOT_ICON1} ${PSP_EBOOT_UNKPNG} ${PSP_EBOOT_PIC1} ${PSP_EBOOT_SND0} ${elf}_stripped ${PSP_EBOOT_PSAR} | |
) | |
endif() | |
endfunction() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment