|
| 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