Building on Windows - tupini07/raylib-cpp-cmake-template GitHub Wiki
Building for Desktop
Building with VSCode
While developing you'll likely be working with the Desktop build. The easiest way to do this is to build directly from VSCode which doesn't require any special action on your part. In the screenshot below, you can click on 2
to build the project (it will compile everything but it won't execute it), or 3
to compile and run (this is what you'll be using when testing your changes).
Building from the command line
If you want to feel cooler then you can also build directly from the command line. Note however that this doesn't offer any benefit when compared to the VSCode approach above.
To build from the command line, you need to run the following command, replacing where it says C:/Workspace/Personal/raylib-cpp-cmake-template
with the path where you saved the template's code.
~\scoop\shims\cmake.exe --no-warn-unused-cli `
-DBOX2D_BUILD_UNIT_TESTS=OFF `
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE `
-DCMAKE_BUILD_TYPE:STRING=Debug `
-DCMAKE_C_COMPILER:FILEPATH=~\scoop\shims\gcc.exe `
-DCMAKE_CXX_COMPILER:FILEPATH=~\scoop\shims\g++.exe `
-SC:/Workspace/Personal/raylib-cpp-cmake-template `
-Bc:/Workspace/Personal/raylib-cpp-cmake-template/build `
-G Ninja
The command above will generate some files but won't actually build anything. To build, you'll the need to:
# go to the build folder
cd C:/Workspace/Personal/raylib-cpp-cmake-template/build
# this will actually build the project
ninja
Once that's done, you should have a raylib-cpp-cmake-template.exe
file under the raylib-cpp-cmake-template/build
directory which is your compiled game. Congratulations!
Building for Web
Desktop builds are great for testing locally but they're not the best when it comes to distributing your game. Few people will want to download a random exe files from a stranger and willingly run it on their PCs. The best way to distribute is as a web build that can be played directly from within your browser.
TODO: clean this up
- install
emscripten
(the C to "webassembly" compiler):- you can also install this by following the official instructions https://emscripten.org/docs/getting_started/downloads.html
- There's also an option to install it through scoop but when I tried it it didn't work for me 😞
- use the
emsdk
manager (installed withemscripten
in the step above) to install the latest compiler (might take a while):emsdk install latest
- activate the emscripten tools:
emsdk activate latest
. .\emsdk_env.ps1
(assuming you're in a powershell terminal)
- you can also install this by following the official instructions https://emscripten.org/docs/getting_started/downloads.html
- build (from the root of the project)
- Create build folder for html:
mkdir -p build-emc
- Copy images and other assets to build output dir:
Copy-Item -Recurse .\assets\ .\build-emc\
cd build-emc
- Write the actual make config using the emscripten tool:
emcmake cmake .. -DPLATFORM=Web -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-s USE_GLFW=3" -DCMAKE_EXECUTABLE_SUFFIX=".html"
- Make the webassembly and html page:
emmake make
- Create build folder for html:
- Open in the browser and play!
- Start up a server in the
build-emc
folder to server the html page. This is necessary so that the browser cna find all the assets and other files (if you open the html directly then the browser won't be able to load other files from the file system)- If you have python3 installed then you can do
python -m http.server
- If you have python3 installed then you can do
- Open game in browser! http://localhost:8000/raylib-cpp-cmake-template.html
- Start up a server in the