Skip to content
Open
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
36 changes: 31 additions & 5 deletions .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,44 @@ on:
pull_request:
repository_dispatch:
types: [run_build]
workflow_dispatch: {}

jobs:
build:
runs-on: ubuntu-latest
container: ${{ github.repository_owner }}/ps2sdk:latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies

- name: Setup dependencies
run: |
apk update
apk add cmake build-base git make

- name: Configure with CMake
run: |
apk add build-base git
mkdir build
cd build
cmake ..

- name: Compile project
- name: Build project with CMake
run: |
make clean all install
cd build
make -j $(getconf _NPROCESSORS_ONLN)

- name: Install library
run: |
cd build
make -j $(getconf _NPROCESSORS_ONLN) install

- name: Get short SHA
id: slug
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT

- name: Upload artifacts
if: ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: libps2stuff-${{ steps.slug.outputs.sha8 }}
path: |
build/*.a
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ objs_*
prebuilddone
*.o
*.a

# CMake
build/
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
install_manifest.txt
*.cmake
!CMakeLists.txt
134 changes: 134 additions & 0 deletions CMAKE_BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Building ps2stuff with CMake

This document describes how to build ps2stuff using CMake instead of the traditional Makefile.

## Prerequisites

- PS2DEV environment installed and configured
- `PS2DEV` environment variable set
- CMake 3.13 or later

## Building

### Basic Build

```bash
mkdir build
cd build
cmake ..
make
```

### Debug Build

To enable debug symbols and `_DEBUG` definition:

```bash
cmake -DDEBUG=ON ..
make
```

### Building with Tests

To build the test executables (when available):

```bash
cmake -DBUILD_TESTS=ON ..
make
```

## Installing

To install the library and headers to `$PS2SDK/ports`:

```bash
make install
```

This will:
- Install `libps2stuff.a` to `$PS2SDK/ports/lib/`
- Install all headers from `include/ps2s/` to `$PS2SDK/ports/include/ps2s/`

## Configuration Options

The following CMake options are available:

| Option | Default | Description |
|--------|---------|-------------|
| `DEBUG` | OFF | Enable debug build with `_DEBUG` definition |
| `BUILD_TESTS` | OFF | Build test executables |

## Build Flags

The CMake build automatically applies the following flags:

- `-DNO_VU0_VECTORS` - Disables VU0 vector code (currently broken)
- `-DNO_ASM` - Disables assembly optimizations
- `-Wno-strict-aliasing` - Suppresses strict aliasing warnings
- `-Wno-conversion-null` - Suppresses conversion null warnings

## CMake Toolchain

The build uses the PS2DEV CMake toolchain file located at:
```
$PS2DEV/share/ps2dev.cmake
```

This toolchain file is automatically detected when `PS2DEV` is set.

## Clean Build

To perform a clean build:

```bash
rm -rf build
mkdir build
cd build
cmake ..
make
```

## Comparison with Makefile Build

The CMake build produces the same output as the traditional Makefile:
- Same compiler flags
- Same source files
- Same install locations
- Compatible library format

## Migration Notes

The CMake build system was designed to be compatible with the existing Makefile build. Both build systems can coexist in the repository.

### Key Differences:

1. **Out-of-source builds**: CMake uses a separate `build/` directory
2. **Dependency tracking**: CMake automatically handles dependencies
3. **Cross-platform**: CMake can generate build files for different build systems

## Troubleshooting

### PS2DEV not found

If you get an error about PS2DEV not being set:

```bash
export PS2DEV=/path/to/ps2dev
export PS2SDK=$PS2DEV/ps2sdk
```

### Toolchain file not found

Make sure the toolchain file exists at `$PS2DEV/share/ps2dev.cmake`.

### Build errors

Try a clean build:

```bash
rm -rf build
mkdir build
cd build
cmake ..
make
```
127 changes: 127 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
cmake_minimum_required(VERSION 3.13)

# Set the toolchain file before project()
if(NOT CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{PS2DEV})
set(CMAKE_TOOLCHAIN_FILE "$ENV{PS2DEV}/share/ps2dev.cmake" CACHE FILEPATH "Toolchain file")
else()
message(FATAL_ERROR "PS2DEV environment variable is not set. Please set it to your PS2DEV installation path.")
endif()
endif()

project(ps2stuff VERSION 1.0.0 LANGUAGES CXX C)

# Options
option(BUILD_TESTS "Build test projects" OFF)
option(DEBUG "Enable debug build" OFF)

# Check if PS2SDK is set (should be done by toolchain file)
if(NOT DEFINED PS2SDK)
message(FATAL_ERROR "PS2SDK is not defined. Make sure the toolchain file is loaded correctly.")
endif()

# Set output library name
set(EE_LIB "libps2stuff.a")

# Include directories
include_directories(
${CMAKE_SOURCE_DIR}/include
${PS2SDK}/ports/include
)

# Link directories
link_directories(
${PS2SDK}/ports/lib
)

# Compiler flags
if(DEBUG)
add_compile_definitions(_DEBUG)
endif()

# Warning flags (matching Makefile)
set(WARNING_FLAGS
-Wno-strict-aliasing
-Wno-conversion-null
)

# VU0 code is broken so disable for now
add_compile_definitions(
NO_VU0_VECTORS
NO_ASM
)

add_compile_options(${WARNING_FLAGS})

# ============================================================================
# Source files
# ============================================================================
set(PS2STUFF_SOURCES
src/core.cpp
src/cpu_matrix.cpp
src/displayenv.cpp
src/drawenv.cpp
src/eetimer.cpp
src/gs.cpp
src/gsmem.cpp
src/imagepackets.cpp
src/math.cpp
src/matrix.cpp
src/packet.cpp
src/perfmon.cpp
src/ps2stuff.cpp
src/sprite.cpp
src/texture.cpp
src/timer.cpp
src/utils.cpp
)

# ============================================================================
# Build the library
# ============================================================================
add_library(ps2stuff STATIC ${PS2STUFF_SOURCES})

set_target_properties(ps2stuff PROPERTIES
OUTPUT_NAME "ps2stuff"
ARCHIVE_OUTPUT_NAME "ps2stuff"
)

target_include_directories(ps2stuff PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

# ============================================================================
# Install targets
# ============================================================================
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${EE_LIB}
DESTINATION "${PS2SDK}/ports/lib"
)

install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ps2s
DESTINATION "${PS2SDK}/ports/include"
FILES_MATCHING PATTERN "*.h"
)

# ============================================================================
# Include tests if enabled
# ============================================================================
if(BUILD_TESTS)
add_subdirectory(tests)
endif()

# ============================================================================
# Print configuration summary
# ============================================================================
message(STATUS "")
message(STATUS "ps2stuff configuration:")
message(STATUS " Version: ${PROJECT_VERSION}")
message(STATUS " Debug build: ${DEBUG}")
message(STATUS " Build tests: ${BUILD_TESTS}")
message(STATUS " Output library: ${EE_LIB}")
message(STATUS " Install prefix: ${PS2SDK}/ports")
message(STATUS " VU0 vectors: DISABLED")
message(STATUS " ASM optimizations: DISABLED")
message(STATUS "")
53 changes: 0 additions & 53 deletions Makefile

This file was deleted.

Loading