Skip to content

Commit aa91124

Browse files
committed
Migrate to cmake
1 parent d67a4b8 commit aa91124

File tree

9 files changed

+305
-936
lines changed

9 files changed

+305
-936
lines changed

.github/workflows/compilation.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,44 @@ on:
55
pull_request:
66
repository_dispatch:
77
types: [run_build]
8+
workflow_dispatch: {}
89

910
jobs:
1011
build:
1112
runs-on: ubuntu-latest
1213
container: ${{ github.repository_owner }}/ps2sdk:latest
1314
steps:
1415
- uses: actions/checkout@v4
15-
16-
- name: Install dependencies
16+
17+
- name: Setup dependencies
18+
run: |
19+
apk update
20+
apk add cmake build-base git make
21+
22+
- name: Configure with CMake
1723
run: |
18-
apk add build-base git
24+
mkdir build
25+
cd build
26+
cmake ..
1927
20-
- name: Compile project
28+
- name: Build project with CMake
2129
run: |
22-
make clean all install
30+
cd build
31+
make -j $(getconf _NPROCESSORS_ONLN)
32+
33+
- name: Install library
34+
run: |
35+
cd build
36+
make -j $(getconf _NPROCESSORS_ONLN) install
37+
38+
- name: Get short SHA
39+
id: slug
40+
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT
41+
42+
- name: Upload artifacts
43+
if: ${{ success() }}
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: libps2stuff-${{ steps.slug.outputs.sha8 }}
47+
path: |
48+
build/*.a

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ objs_*
33
prebuilddone
44
*.o
55
*.a
6+
7+
# CMake
8+
build/
9+
CMakeCache.txt
10+
CMakeFiles/
11+
cmake_install.cmake
12+
install_manifest.txt
13+
*.cmake
14+
!CMakeLists.txt

CMAKE_BUILD.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Building ps2stuff with CMake
2+
3+
This document describes how to build ps2stuff using CMake instead of the traditional Makefile.
4+
5+
## Prerequisites
6+
7+
- PS2DEV environment installed and configured
8+
- `PS2DEV` environment variable set
9+
- CMake 3.13 or later
10+
11+
## Building
12+
13+
### Basic Build
14+
15+
```bash
16+
mkdir build
17+
cd build
18+
cmake ..
19+
make
20+
```
21+
22+
### Debug Build
23+
24+
To enable debug symbols and `_DEBUG` definition:
25+
26+
```bash
27+
cmake -DDEBUG=ON ..
28+
make
29+
```
30+
31+
### Building with Tests
32+
33+
To build the test executables (when available):
34+
35+
```bash
36+
cmake -DBUILD_TESTS=ON ..
37+
make
38+
```
39+
40+
## Installing
41+
42+
To install the library and headers to `$PS2SDK/ports`:
43+
44+
```bash
45+
make install
46+
```
47+
48+
This will:
49+
- Install `libps2stuff.a` to `$PS2SDK/ports/lib/`
50+
- Install all headers from `include/ps2s/` to `$PS2SDK/ports/include/ps2s/`
51+
52+
## Configuration Options
53+
54+
The following CMake options are available:
55+
56+
| Option | Default | Description |
57+
|--------|---------|-------------|
58+
| `DEBUG` | OFF | Enable debug build with `_DEBUG` definition |
59+
| `BUILD_TESTS` | OFF | Build test executables |
60+
61+
## Build Flags
62+
63+
The CMake build automatically applies the following flags:
64+
65+
- `-DNO_VU0_VECTORS` - Disables VU0 vector code (currently broken)
66+
- `-DNO_ASM` - Disables assembly optimizations
67+
- `-Wno-strict-aliasing` - Suppresses strict aliasing warnings
68+
- `-Wno-conversion-null` - Suppresses conversion null warnings
69+
70+
## CMake Toolchain
71+
72+
The build uses the PS2DEV CMake toolchain file located at:
73+
```
74+
$PS2DEV/share/ps2dev.cmake
75+
```
76+
77+
This toolchain file is automatically detected when `PS2DEV` is set.
78+
79+
## Clean Build
80+
81+
To perform a clean build:
82+
83+
```bash
84+
rm -rf build
85+
mkdir build
86+
cd build
87+
cmake ..
88+
make
89+
```
90+
91+
## Comparison with Makefile Build
92+
93+
The CMake build produces the same output as the traditional Makefile:
94+
- Same compiler flags
95+
- Same source files
96+
- Same install locations
97+
- Compatible library format
98+
99+
## Migration Notes
100+
101+
The CMake build system was designed to be compatible with the existing Makefile build. Both build systems can coexist in the repository.
102+
103+
### Key Differences:
104+
105+
1. **Out-of-source builds**: CMake uses a separate `build/` directory
106+
2. **Dependency tracking**: CMake automatically handles dependencies
107+
3. **Cross-platform**: CMake can generate build files for different build systems
108+
109+
## Troubleshooting
110+
111+
### PS2DEV not found
112+
113+
If you get an error about PS2DEV not being set:
114+
115+
```bash
116+
export PS2DEV=/path/to/ps2dev
117+
export PS2SDK=$PS2DEV/ps2sdk
118+
```
119+
120+
### Toolchain file not found
121+
122+
Make sure the toolchain file exists at `$PS2DEV/share/ps2dev.cmake`.
123+
124+
### Build errors
125+
126+
Try a clean build:
127+
128+
```bash
129+
rm -rf build
130+
mkdir build
131+
cd build
132+
cmake ..
133+
make
134+
```

CMakeLists.txt

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
# Set the toolchain file before project()
4+
if(NOT CMAKE_TOOLCHAIN_FILE)
5+
if(DEFINED ENV{PS2DEV})
6+
set(CMAKE_TOOLCHAIN_FILE "$ENV{PS2DEV}/share/ps2dev.cmake" CACHE FILEPATH "Toolchain file")
7+
else()
8+
message(FATAL_ERROR "PS2DEV environment variable is not set. Please set it to your PS2DEV installation path.")
9+
endif()
10+
endif()
11+
12+
project(ps2stuff VERSION 1.0.0 LANGUAGES CXX C)
13+
14+
# Options
15+
option(BUILD_TESTS "Build test projects" OFF)
16+
option(DEBUG "Enable debug build" OFF)
17+
18+
# Check if PS2SDK is set (should be done by toolchain file)
19+
if(NOT DEFINED PS2SDK)
20+
message(FATAL_ERROR "PS2SDK is not defined. Make sure the toolchain file is loaded correctly.")
21+
endif()
22+
23+
# Set output library name
24+
set(EE_LIB "libps2stuff.a")
25+
26+
# Include directories
27+
include_directories(
28+
${CMAKE_SOURCE_DIR}/include
29+
${PS2SDK}/ports/include
30+
)
31+
32+
# Link directories
33+
link_directories(
34+
${PS2SDK}/ports/lib
35+
)
36+
37+
# Compiler flags
38+
if(DEBUG)
39+
add_compile_definitions(_DEBUG)
40+
endif()
41+
42+
# Warning flags (matching Makefile)
43+
set(WARNING_FLAGS
44+
-Wno-strict-aliasing
45+
-Wno-conversion-null
46+
)
47+
48+
# VU0 code is broken so disable for now
49+
add_compile_definitions(
50+
NO_VU0_VECTORS
51+
NO_ASM
52+
)
53+
54+
add_compile_options(${WARNING_FLAGS})
55+
56+
# ============================================================================
57+
# Source files
58+
# ============================================================================
59+
set(PS2STUFF_SOURCES
60+
src/core.cpp
61+
src/cpu_matrix.cpp
62+
src/displayenv.cpp
63+
src/drawenv.cpp
64+
src/eetimer.cpp
65+
src/gs.cpp
66+
src/gsmem.cpp
67+
src/imagepackets.cpp
68+
src/math.cpp
69+
src/matrix.cpp
70+
src/packet.cpp
71+
src/perfmon.cpp
72+
src/ps2stuff.cpp
73+
src/sprite.cpp
74+
src/texture.cpp
75+
src/timer.cpp
76+
src/utils.cpp
77+
)
78+
79+
# ============================================================================
80+
# Build the library
81+
# ============================================================================
82+
add_library(ps2stuff STATIC ${PS2STUFF_SOURCES})
83+
84+
set_target_properties(ps2stuff PROPERTIES
85+
OUTPUT_NAME "ps2stuff"
86+
ARCHIVE_OUTPUT_NAME "ps2stuff"
87+
)
88+
89+
target_include_directories(ps2stuff PUBLIC
90+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
91+
$<INSTALL_INTERFACE:include>
92+
)
93+
94+
# ============================================================================
95+
# Install targets
96+
# ============================================================================
97+
install(
98+
FILES ${CMAKE_CURRENT_BINARY_DIR}/${EE_LIB}
99+
DESTINATION "${PS2SDK}/ports/lib"
100+
)
101+
102+
install(
103+
DIRECTORY ${CMAKE_SOURCE_DIR}/include/ps2s
104+
DESTINATION "${PS2SDK}/ports/include"
105+
FILES_MATCHING PATTERN "*.h"
106+
)
107+
108+
# ============================================================================
109+
# Include tests if enabled
110+
# ============================================================================
111+
if(BUILD_TESTS)
112+
add_subdirectory(tests)
113+
endif()
114+
115+
# ============================================================================
116+
# Print configuration summary
117+
# ============================================================================
118+
message(STATUS "")
119+
message(STATUS "ps2stuff configuration:")
120+
message(STATUS " Version: ${PROJECT_VERSION}")
121+
message(STATUS " Debug build: ${DEBUG}")
122+
message(STATUS " Build tests: ${BUILD_TESTS}")
123+
message(STATUS " Output library: ${EE_LIB}")
124+
message(STATUS " Install prefix: ${PS2SDK}/ports")
125+
message(STATUS " VU0 vectors: DISABLED")
126+
message(STATUS " ASM optimizations: DISABLED")
127+
message(STATUS "")

Makefile

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)