Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.10)

# Load the PSP platform configuration BEFORE project()
set(CMAKE_SYSTEM_CMAKE_PLATFORM_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(${CMAKE_SYSTEM_CMAKE_PLATFORM_PATH}/PSP.cmake)

project(OSLib C CXX ASM)

# Set C and C++ standards
Expand All @@ -9,10 +14,6 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# Load the PSP platform configuration
set(CMAKE_SYSTEM_CMAKE_PLATFORM_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(${CMAKE_SYSTEM_CMAKE_PLATFORM_PATH}/PSP.cmake)

# Set the output library
set(TARGET_LIB osl)
add_library(${TARGET_LIB} STATIC)
Expand Down
49 changes: 43 additions & 6 deletions cmake/IMG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,30 @@ endforeach()
list(APPEND OSL_IMAGE_FORMATS_AVAILABLE ${OSL_IMAGE_FORMAT_LOADERS} ${OSL_IMAGE_FORMAT_WRITERS})
list(REMOVE_DUPLICATES OSL_IMAGE_FORMATS_AVAILABLE)

# Formats that should always use the repository's local implementation
# (skip external find_package). Add names here (e.g. GIF) when the project
# includes a bundled implementation that should take priority.
if(NOT DEFINED FORCE_LOCAL_IMAGE_FORMATS)
set(FORCE_LOCAL_IMAGE_FORMATS GIF)
endif()

foreach(IMAGE_FORMAT ${OSL_IMAGE_FORMATS_AVAILABLE})
find_package(${IMAGE_FORMAT})
if(${IMAGE_FORMAT}_FOUND)
# If this format is forced to use the local implementation, skip find_package
list(FIND FORCE_LOCAL_IMAGE_FORMATS ${IMAGE_FORMAT} _is_forced)
if(NOT _is_forced EQUAL -1)
# Use local implementation (mark supported if loader/writer exists)
if(${IMAGE_FORMAT} IN_LIST OSL_IMAGE_FORMAT_LOADERS)
list(APPEND OSL_IMAGE_FORMATS_SUPPORTED ${IMAGE_FORMAT})
add_compile_definitions(-DOSL_IMAGE_LOADER_${IMAGE_FORMAT})
endif()
if(${IMAGE_FORMAT} IN_LIST OSL_IMAGE_FORMAT_WRITERS)
list(APPEND OSL_IMAGE_FORMATS_SUPPORTED ${IMAGE_FORMAT})
add_compile_definitions(-DOSL_IMAGE_WRITER_${IMAGE_FORMAT})
endif()
else()
find_package(${IMAGE_FORMAT})
if(${IMAGE_FORMAT}_FOUND)
# External package found (SDK or system) -> use it
list(APPEND OSL_IMAGE_FORMATS_SUPPORTED ${IMAGE_FORMAT})
if(${IMAGE_FORMAT} IN_LIST OSL_IMAGE_FORMAT_LOADERS)
add_compile_definitions(-DOSL_IMAGE_LOADER_${IMAGE_FORMAT})
Expand All @@ -50,9 +71,26 @@ foreach(IMAGE_FORMAT ${OSL_IMAGE_FORMATS_AVAILABLE})
add_compile_definitions(-DOSL_IMAGE_WRITER_${IMAGE_FORMAT})
include_directories(${${IMAGE_FORMAT}_INCLUDE_DIRS})
endif()
else()
list(REMOVE_ITEM OSL_IMAGE_FORMAT_WRITERS ${IMAGE_FORMAT})
list(REMOVE_ITEM OSL_IMAGE_FORMAT_LOADERS ${IMAGE_FORMAT})
else()
# No external package found. If we have a local implementation (source
# files under src/image/format), keep the loader/writer and mark the
# format as supported using the local code. Otherwise remove it.
set(_has_local_impl FALSE)
if(${IMAGE_FORMAT} IN_LIST OSL_IMAGE_FORMAT_LOADERS)
list(APPEND OSL_IMAGE_FORMATS_SUPPORTED ${IMAGE_FORMAT})
add_compile_definitions(-DOSL_IMAGE_LOADER_${IMAGE_FORMAT})
set(_has_local_impl TRUE)
endif()
if(${IMAGE_FORMAT} IN_LIST OSL_IMAGE_FORMAT_WRITERS)
list(APPEND OSL_IMAGE_FORMATS_SUPPORTED ${IMAGE_FORMAT})
add_compile_definitions(-DOSL_IMAGE_WRITER_${IMAGE_FORMAT})
set(_has_local_impl TRUE)
endif()
if(NOT _has_local_impl)
list(REMOVE_ITEM OSL_IMAGE_FORMAT_WRITERS ${IMAGE_FORMAT})
list(REMOVE_ITEM OSL_IMAGE_FORMAT_LOADERS ${IMAGE_FORMAT})
endif()
endif()
endif()
endforeach()

Expand All @@ -64,4 +102,3 @@ foreach(IMAGE_FORMAT ${OSL_IMAGE_FORMAT_LOADERS})
endforeach()

message("-- Using ${OSL_IMAGE_FORMATS_SUPPORTED}")

61 changes: 51 additions & 10 deletions cmake/PSP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Determine PSP root for includes/libs. Prefer psp-config output, fall back to PSPDEV env.
if(PSPDIR)
set(PSPDEV_ROOT "${PSPDIR}")
elseif(DEFINED ENV{PSPDEV})
set(PSPDEV_ROOT "$ENV{PSPDEV}/psp")
endif()

# When cross-compiling we want find_package/find_library to search the PSP SDK
# first. Configure CMake search roots and modes so find_* will look into the
# PSPDEV root for includes and libraries rather than the host system paths.
if(PSPDEV_ROOT)
set(CMAKE_FIND_ROOT_PATH "${PSPDEV_ROOT};${PSPDEV_ROOT}/sdk" CACHE PATH "Search root for PSP cross build" FORCE)
set(CMAKE_SYSROOT "${PSPDEV_ROOT}" CACHE PATH "Sysroot for PSP cross-compilation" FORCE)
# Never search programs in the root path (we want host tools for executables)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# For libraries and includes, prefer only the root path when cross-compiling
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
else()
message(WARNING "PSPDEV not set: find_package may locate host system libraries instead of PSP SDK ones")
endif()

# Add PSP SDK to prefix path so find_package can locate CMake configs or modules under the SDK
if(PSPDEV_ROOT)
list(APPEND CMAKE_PREFIX_PATH "${PSPDEV_ROOT}" "${PSPDEV_ROOT}/sdk")
# If the SDK provides pkgconfig files, prefer them for pkg-config based finders
if(EXISTS "${PSPDEV_ROOT}/lib/pkgconfig")
set(ENV{PKG_CONFIG_LIBDIR} "${PSPDEV_ROOT}/lib/pkgconfig")
endif()
endif()

# Set PSP compile flags
add_compile_options(-G0 -Wall -Wextra -Wno-unused -Wno-strict-prototypes -Wno-missing-prototypes
-fno-strict-aliasing)
Expand Down Expand Up @@ -62,13 +93,23 @@ link_libraries(
-lpng -ljpeg -lz -lm
)

# Set the path to the PSP SDK includes and libraries
include_directories(
$ENV{PSPDEV}/psp/include
$ENV{PSPDEV}/psp/sdk/include
)
link_directories(
$ENV{PSPDEV}/psp/lib
$ENV{PSPDEV}/psp/sdk/lib
)

# Set the path to the PSP SDK includes and libraries (use PSPDEV_ROOT if available)
if(PSPDEV_ROOT)
include_directories(
${PSPDEV_ROOT}/include
${PSPDEV_ROOT}/sdk/include
)
link_directories(
${PSPDEV_ROOT}/lib
${PSPDEV_ROOT}/sdk/lib
)
else()
include_directories(
$ENV{PSPDEV}/psp/include
$ENV{PSPDEV}/psp/sdk/include
)
link_directories(
$ENV{PSPDEV}/psp/lib
$ENV{PSPDEV}/psp/sdk/lib
)
endif()