Skip to content

Instantly share code, notes, and snippets.

@KorigamiK
Last active October 22, 2022 19:44
Show Gist options
  • Save KorigamiK/97fb9536ce9ae29aff29f7d719483f29 to your computer and use it in GitHub Desktop.
Save KorigamiK/97fb9536ce9ae29aff29f7d719483f29 to your computer and use it in GitHub Desktop.
Eigen3 PSP working example
#!/bin/bash
mkdir -p build/psp
cd build/psp || exit
cmake -DCMAKE_TOOLCHAIN_FILE="$PSPDEV/psp/share/pspdev.cmake" ../../ &&
make -j2
cmake_minimum_required(VERSION 3.10)
project(eigen-example)
add_executable(${PROJECT_NAME} main.cpp)
IF(PLATFORM_PSP)
find_package(PkgConfig REQUIRED)
pkg_check_modules(EIGEN3 REQUIRED eigen3)
message(STATUS "EIGEN3_INCLUDE_DIRS: ${EIGEN3_INCLUDE_DIRS}")
message(STATUS "EIGEN3_LIBRARIES: ${EIGEN3_LIBRARIES}")
target_include_directories(${PROJECT_NAME} PRIVATE ${EIGEN3_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${EIGEN3_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE
pspdisplay
pspge
pspdebug
stdc++
)
create_pbp_file(
TARGET ${PROJECT_NAME}
ICON_PATH NULL
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
TITLE ${PROJECT_NAME}
BUILD_PRX
)
ELSE()
find_package(Eigen3 REQUIRED)
link_directories(${Eigen_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${Eigen_LIBRARIES})
ENDIF()
if (PLATFORM_PSP)
target_compile_definitions(${PROJECT_NAME} PRIVATE IS_PSP)
endif()
#ifdef IS_PSP
#include <pspkernel.h>
#include <pspdebug.h>
#endif
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#ifdef IS_PSP
PSP_MODULE_INFO("Hello World", 0, 1, 1);
#define printf pspDebugScreenPrintf
#else
#include <stdio.h>
#endif
int print_eigen(Eigen::MatrixX3d m)
{
for (int i = 0; i < m.rows(); i++)
{
for (int j = 0; j < m.cols(); j++)
printf("%.1f ", m(i, j));
printf("\n");
}
return 0;
}
auto main() -> int
{
#ifdef IS_PSP
pspDebugScreenInit();
#endif
Eigen::Matrix3d test; // 3 by 3 double precision matrix initialization
printf("Hello World!\n");
// Let's make it a symmetric matrix
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
test(i, j) = (i + 1) * (1 + j);
print_eigen(test);
#ifdef IS_PSP
while (1)
;
sceKernelExitGame();
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment