Skip to content

Commit adc93bd

Browse files
committed
Migrating to cmake
1 parent c548a67 commit adc93bd

File tree

21 files changed

+724
-1157
lines changed

21 files changed

+724
-1157
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ prebuilddone
1111
*.a
1212
*.elf
1313
*.orig
14+
15+
# CMake
16+
build/
17+
CMakeCache.txt
18+
CMakeFiles/
19+
cmake_install.cmake
20+
install_manifest.txt
21+
*.cmake
22+
!CMakeLists.txt

CMAKE_BUILD.md

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

0 commit comments

Comments
 (0)