1# Guidance for porting to new platform 2 3Where differences existed between the initial POSIX platform for lws and other 4supported platforms like Windows, `lws_plat_...()` apis were added to move 5handling to platform-specific code in `./lib/plat/`. 6 7Depending o which platform is built, different platform-specific implementations 8of these `lws_plat...()` apis get built. 9 10## 1) Prepare the cmake cross-build file if necessary 11 12CMake isolates its settings for cross-build into a separate file, which can be 13used to different cmake projects for the same platform as well. 14 15Find a similar examples already in `./contrib/cross-*` and copy and adapt it 16as needed, 17 18All settings related to toolchain should go in there. For cross-toolchain, 19the convention is to pass the path to its installed directory in `CROSS_PATH` 20environment variable. 21 22## 2) Copy the closest platform dir in ./lib/plat 23 24Wholesale copy the closest existing platform dir to `/lib/plat/myplatform` and 25rename the files. 26 27Remove stuff specific to the original platform. 28 29## 3) Add a flag in CMakeLists.txt 30 31Cut and paste a flag to select your platform, preferably `LWS_PLAT_MYPLATFORM` or so 32 33## 4) Add a section to force-select and deselect other cmake options based on platform flag 34 35Some options on by default may not make sense on your platform, and others off 36by default may be mandatory. After the options() section in CMakeLists.txt, you 37can use this kind of structure 38 39``` 40 if (LWS_PLAT_MYPLATFORM) 41 set(LWS_WITH_XXXX 0) 42 endif() 43``` 44 45to enforce implicit requirements of your platform. Optional stuff should be set by 46running cmake commandline as usual. 47 48## 5) Add building your platform files into CMakeLists.txt 49 50Add entries in CMakeLists.txt for building stuff in `./lib/plat/myplatform` when 51`LWS_PLAT_MYPLATFORM` is enabled. 52 53## 6) Adapt your copied ./lib/plat/myplatform/ files 54 55You can now do test builds using the cross-build file, your platform flag in 56cmake, and your copied ./lib/plat content... this last part since it was 57copied from another platform will initially be a plentiful source of errors. 58 59You can iteratively build and adapt the platform files. 60 61