99 lines
3.0 KiB
CMake
99 lines
3.0 KiB
CMake
# Copyright (c) 2025 Dominic Masters
|
|
#
|
|
# This software is released under the MIT License.
|
|
# https://opensource.org/licenses/MIT
|
|
|
|
if(NOT TARGET pspsdk)
|
|
message(STATUS "Looking for PSPSDK...")
|
|
|
|
set(PSPSDK_FOUND FALSE CACHE INTERNAL "PSPSDK found")
|
|
set(PSPSDK_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/_pspsdk")
|
|
set(PSPSDK_SEARCH_ROOTS
|
|
"${PSPSDK_ROOT}"
|
|
"$ENV{PSPDEV}"
|
|
"$ENV{HOME}/pspdev"
|
|
"/usr/local/pspdev"
|
|
"/opt/pspdev"
|
|
"/usr/pspdev"
|
|
"${PSPSDK_DOWNLOAD_DIR}/pspdev"
|
|
)
|
|
|
|
foreach(root IN LISTS PSPSDK_SEARCH_ROOTS)
|
|
list(APPEND PSPSDK_BIN_HINTS "${root}/bin")
|
|
list(APPEND PSPSDK_INCLUDE_HINTS "${root}/include")
|
|
list(APPEND PSPSDK_LIB_HINTS "${root}/lib")
|
|
endforeach()
|
|
|
|
# Find PSP GCC
|
|
find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS})
|
|
|
|
# If we did not find it, download it.
|
|
if(NOT PSPSDK_PSP_GCC)
|
|
message(STATUS "psp-gcc not found in system paths. Downloading PSPSDK tarball...")
|
|
file(DOWNLOAD
|
|
"https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz"
|
|
"${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
|
EXPECTED_HASH SHA256=afe338e92f6eeec21c56a64eeb65201e6b95ecbae938ae38688bbf0f17b69ead
|
|
SHOW_PROGRESS
|
|
)
|
|
|
|
# Make output dir
|
|
file(MAKE_DIRECTORY "${PSPSDK_DOWNLOAD_DIR}")
|
|
|
|
# Extract the tarball
|
|
execute_process(
|
|
COMMAND
|
|
${CMAKE_COMMAND} -E tar xzf "${CMAKE_BINARY_DIR}/pspsdk.tar.gz"
|
|
WORKING_DIRECTORY
|
|
"${PSPSDK_DOWNLOAD_DIR}"
|
|
RESULT_VARIABLE
|
|
tar_result
|
|
)
|
|
if(NOT tar_result EQUAL 0)
|
|
message(FATAL_ERROR "Failed to extract PSPSDK tarball")
|
|
endif()
|
|
|
|
# Retry discovery with extracted fallback
|
|
find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS})
|
|
endif()
|
|
|
|
if(PSPSDK_PSP_GCC)
|
|
get_filename_component(PSPSDK_BIN_ROOT "${PSPSDK_PSP_GCC}" DIRECTORY)
|
|
get_filename_component(PSPSDK_ROOT "${PSPSDK_BIN_ROOT}" DIRECTORY)
|
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
|
set(ENV{PSPDEV} "${PSPSDK_ROOT}")
|
|
set(CMAKE_TOOLCHAIN_FILE "${PSPSDK_ROOT}/psp/share/pspdev.cmake")
|
|
set(BUILD_PRX ON CACHE BOOL "Build PRX modules")
|
|
|
|
include("${PSPSDK_ROOT}/psp/share/pspdev.cmake")
|
|
set(CMAKE_C_COMPILER ${PSPSDK_BIN_ROOT}/psp-gcc)
|
|
set(CMAKE_CXX_COMPILER ${PSPSDK_BIN_ROOT}/psp-g++)
|
|
|
|
if(NOT DEFINED PSP)
|
|
message(FATAL_ERROR "PSP environment variable is not set correctly.")
|
|
endif()
|
|
|
|
add_library(pspsdk INTERFACE IMPORTED)
|
|
set_target_properties(pspsdk PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES "${PSPSDK_INCLUDE_DIR}"
|
|
INTERFACE_LINK_DIRECTORIES "${PSPSDK_LIB_DIR}"
|
|
)
|
|
target_include_directories(pspsdk
|
|
INTERFACE
|
|
${PSPDEV}/psp/include
|
|
${PSPDEV}/psp/sdk/include
|
|
)
|
|
target_link_directories(pspsdk
|
|
INTERFACE
|
|
${PSPDEV}/lib
|
|
${PSPDEV}/psp/lib
|
|
${PSPDEV}/psp/sdk/lib
|
|
)
|
|
target_link_libraries(pspsdk INTERFACE
|
|
pspdebug
|
|
pspdisplay
|
|
pspge
|
|
pspctrl
|
|
)
|
|
endif()
|
|
endif() |