AppImage
A possible cross-distro solution is to use AppImage format, which allows to easily bundle all your resources and dependencies into a single directly executable file needing no installation.
While it's a good idea to consult the official guide for packaging native binaries, the overall process can be summarized as follows:
- Install dependencies using package manager of distro you're using as a build machine (e.g. apt), including header files.
- Build your game as you normally would, taking care to specify
/usr
as installation prefix. In with CMake it might be (inside build directory)
cmake PATH_TO_SOURCE_DIR -GNinja -DCMAKE_INSTALL_PREFIX=/usr
You'll also want to make use of standard path specifications, i.e. installing binaries in bin/
, data in share/
, etc.. Something else you'll probably want to do is to install desktop file together with an icon for your app to ensure that AppImage desktop integration works properly.
- Compile and install your application into a temporary directory by setting DESTDIR variable. Continuing the example above:
DESTDIR=/tmp/myappdir ninja -j4 install
- Call
linuxdeploy
tool to produce AppImage in your current directory:
linuxdeploy --appdir /tmp/myappdir --output appimage
This will automatically include in all shared libraries that your game depends on into resulting appimage.
Steam
If you plan to use Steam for distribution of native build of your game on Linux you should look into documentation for steam runtime, which already includes many libraries commonly used by games (which, relevantly for your question, includes SDL2 but not GLFW). I'm not very familiar with it, but the linked repository should get you started. Another official guide specifically for game developers is also available.
As for libraries that do not happen to be provided by steam runtime, GLFW3 in your case, you'll have to ship those with your game, e.g. in lib
subfolder and point LD_LIBRARY_PATH
at it. The latter is often done with a simple script like the following, which you configure as game's main executable:
#!/bin/bashsh
export LD_LIBRARY_PATH="${PWD}/lib"
exec bin/mygame "$@"