Skip to content

Commit a3587e5

Browse files
committed
Migrating to cmake
1 parent c548a67 commit a3587e5

34 files changed

+816
-8389
lines changed

.github/workflows/compilation.yml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,59 @@ 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: ps2dev/ps2sdk:latest
1314
steps:
1415
- uses: actions/checkout@v4
15-
16-
- name: Install dependencies
16+
17+
- name: Setup dependencies
1718
run: |
18-
apk add build-base git
19+
apk update
20+
apk add cmake build-base git make
1921
2022
- name: Install ps2stuff
2123
run: |
2224
git clone https://github.com/ps2dev/ps2stuff.git
23-
cd ps2stuff
24-
make -j $(getconf _NPROCESSORS_ONLN) clean
25-
make -j $(getconf _NPROCESSORS_ONLN) all
26-
make -j $(getconf _NPROCESSORS_ONLN) install
25+
cd ps2stuff
26+
git checkout cmake
27+
mkdir build
28+
cd build
29+
cmake ..
30+
make -j $(getconf _NPROCESSORS_ONLN)
31+
make install
2732
28-
- name: Compile project
33+
- name: Configure with CMake
2934
run: |
30-
make -j $(getconf _NPROCESSORS_ONLN) clean
31-
make -j $(getconf _NPROCESSORS_ONLN) all
32-
make -j $(getconf _NPROCESSORS_ONLN) install
35+
mkdir build
36+
cd build
37+
cmake -DBUILD_GLUT=ON -DBUILD_EXAMPLES=ON ..
3338
34-
- name: Compile GLUT
39+
- name: Build project with CMake
3540
run: |
36-
cd glut
37-
make -j $(getconf _NPROCESSORS_ONLN) clean
38-
make -j $(getconf _NPROCESSORS_ONLN) all
39-
make -j $(getconf _NPROCESSORS_ONLN) install
40-
41-
- name: Compile examples
41+
cd build
42+
make -j $(getconf _NPROCESSORS_ONLN)
43+
44+
- name: Install libraries
4245
run: |
43-
cd examples
44-
cd box && make clean all && cd ..
45-
cd logo && make clean all && cd ..
46-
cd performance && make clean all && cd ..
47-
cd tricked_out && make clean all && cd ..
48-
cd nehe/lesson02 && make clean all && cd ../..
49-
cd nehe/lesson03 && make clean all && cd ../..
50-
cd nehe/lesson04 && make clean all && cd ../..
51-
cd nehe/lesson05 && make clean all && cd ../..
46+
cd build
47+
make -j $(getconf _NPROCESSORS_ONLN) install
48+
5249
50+
- name: Get short SHA
51+
id: slug
52+
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT
5353

5454
- name: Upload artifacts
55+
if: ${{ success() }}
5556
uses: actions/upload-artifact@v4
5657
with:
57-
name: examples
58+
name: ps2gl-examples-${{ steps.slug.outputs.sha8 }}
5859
path: |
59-
examples/**/*.elf
60-
examples/**/*.gl
61-
examples/**/*.rtx
62-
examples/**/*.bin
60+
build/examples/*.elf
61+
build/examples/*.gl
62+
build/examples/*.rtx
63+
build/examples/*.bin

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ prebuilddone
1111
*.a
1212
*.elf
1313
*.orig
14+
15+
# CMake
16+
build/

CMAKE_BUILD.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Building ps2gl with CMake
2+
3+
This document describes how to build ps2gl 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+
- VU1 development tools (optional - see note below):
11+
- **Open-source tools (recommended):** `openvcl`, `masp`, `dvp-as`
12+
- **Proprietary tools (legacy):** `vcl`, `gasp`, `dvp-as`
13+
14+
**Note:**
15+
- VU1 tools are only required for building VU1 renderers from source
16+
- The build automatically detects and prefers open-source tools (`openvcl` + `masp`) over proprietary ones (`vcl` + `gasp`)
17+
- If VU1 tools are not available (e.g., on macOS), the build will automatically use pre-built `.vo` object files from the `vu1/` directory
18+
- Pre-built objects can be generated by running the build once with VU1 tools available
19+
- **OpenVCL compatibility**: 11 out of 13 renderers compile successfully with openvcl. The `indexed` and `scei` renderers require proprietary `vcl` or use pre-built objects as they are incompatible with openvcl
20+
21+
## Building
22+
23+
### Basic Build
24+
25+
```bash
26+
mkdir build
27+
cd build
28+
cmake ..
29+
make
30+
```
31+
32+
### Debug Build
33+
34+
To enable debug symbols and `_DEBUG` definition:
35+
36+
```bash
37+
cmake -DDEBUG=ON ..
38+
make
39+
```
40+
41+
### Building with Tests
42+
43+
To build the test executables (when available):
44+
45+
```bash
46+
cmake -DBUILD_TESTS=ON ..
47+
make
48+
```
49+
50+
## Installing
51+
52+
To install the library and headers to `$PS2SDK/ports`:
53+
54+
```bash
55+
make install
56+
```
57+
58+
This will:
59+
- Install `libps2gl.a` to `$PS2SDK/ports/lib/`
60+
- Install GL headers to `$PS2SDK/ports/include/GL/`
61+
- Install ps2gl headers to `$PS2SDK/ports/include/ps2gl/`
62+
63+
## Configuration Options
64+
65+
The following CMake options are available:
66+
67+
| Option | Default | Description |
68+
|--------|---------|-------------|
69+
| `DEBUG` | OFF | Enable debug build with `_DEBUG` definition |
70+
| `BUILD_TESTS` | OFF | Build test executables |
71+
72+
## Build Flags
73+
74+
The CMake build automatically applies the following flags:
75+
76+
- `-DNO_VU0_VECTORS` - Disables VU0 vector code (currently broken)
77+
- `-DNO_ASM` - Disables assembly optimizations
78+
- `-Wno-strict-aliasing` - Suppresses strict aliasing warnings
79+
- `-Wno-conversion-null` - Suppresses conversion null warnings
80+
81+
## VU1 Renderer Pipeline
82+
83+
ps2gl includes VU1 assembly renderers that go through a complex preprocessing pipeline:
84+
85+
1. **Step 1**: Remove C preprocessor directives and fix include paths
86+
2. **Step 2**: `gasp`/`masp` assembler preprocessing
87+
3. **Step 3**: Array notation conversion
88+
4. **Step 4**: C preprocessor with memory layout headers
89+
5. **Step 5**: `vcl`/`openvcl` compiler generates `.vsm` files
90+
6. **Step 6**: `dvp-as` assembler generates `.vo` object files
91+
92+
The CMake build handles all these steps automatically for the following renderers:
93+
94+
### OpenVCL Compatible (11 renderers):
95+
- fast_nolights, fast
96+
- general, general_quad, general_tri
97+
- general_nospec, general_nospec_quad, general_nospec_tri
98+
- general_pv_diff, general_pv_diff_quad, general_pv_diff_tri
99+
100+
### Require proprietary VCL or use pre-built (2 renderers):
101+
- indexed (uses variable naming incompatible with openvcl)
102+
- scei
103+
104+
## CMake Toolchain
105+
106+
The build uses the PS2DEV CMake toolchain file located at:
107+
```
108+
$PS2DEV/share/ps2dev.cmake
109+
```
110+
111+
This toolchain file is automatically detected when `PS2DEV` is set.
112+
113+
## Clean Build
114+
115+
To perform a clean build:
116+
117+
```bash
118+
rm -rf build
119+
mkdir build
120+
cd build
121+
cmake ..
122+
make
123+
```
124+
125+
## Comparison with Makefile Build
126+
127+
The CMake build produces the same output as the traditional Makefile:
128+
- Same compiler flags
129+
- Same source files
130+
- Same VU1 preprocessing pipeline
131+
- Same install locations
132+
- Compatible library format
133+
134+
## Migration Notes
135+
136+
The CMake build system was designed to be compatible with the existing Makefile build. Both build systems can coexist in the repository.
137+
138+
### Key Differences:
139+
140+
1. **Out-of-source builds**: CMake uses a separate `build/` directory
141+
2. **Dependency tracking**: CMake automatically handles dependencies
142+
3. **Parallel VU1 processing**: CMake can process multiple VU1 renderers in parallel
143+
4. **Cross-platform**: CMake can generate build files for different build systems
144+
145+
## Troubleshooting
146+
147+
### PS2DEV not found
148+
149+
If you get an error about PS2DEV not being set:
150+
151+
```bash
152+
export PS2DEV=/path/to/ps2dev
153+
export PS2SDK=$PS2DEV/ps2sdk
154+
```
155+
156+
### Toolchain file not found
157+
158+
Make sure the toolchain file exists at `$PS2DEV/share/ps2dev.cmake`.
159+
160+
### VU1 tools not found
161+
162+
Make sure the VU1 tools are in your PATH. For open-source tools:
163+
164+
```bash
165+
which openvcl masp dvp-as
166+
```
167+
168+
Or for proprietary tools:
169+
170+
```bash
171+
which vcl gasp dvp-as
172+
```
173+
174+
The `dvp-as` tool should be installed as part of PS2DEV. For `openvcl` and `masp`:
175+
- openvcl: https://github.com/ps2dev/openvcl
176+
- masp: https://github.com/AzagraMac/masp
177+
178+
### Build errors
179+
180+
Try a clean build:
181+
182+
```bash
183+
rm -rf build
184+
mkdir build
185+
cd build
186+
cmake ..
187+
make
188+
```
189+
190+
### VU1 preprocessing errors
191+
192+
If VU1 preprocessing fails, check that:
193+
1. All `.vcl` source files exist in `vu1/`
194+
2. Memory layout headers exist: `vu1/vu1_mem_linear.h` and `vu1/vu1_mem_indexed.h`
195+
3. VU1 tools are properly installed

0 commit comments

Comments
 (0)