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