Skip to content

Commit

Permalink
Link statically on Windows
Browse files Browse the repository at this point in the history
Try to link statically as much as possible on Windows, to reduce the
number of DLLs that have to be shipped with Windows builds.

Also document the build process on Windows.
  • Loading branch information
nunuhara committed Mar 29, 2023
1 parent ac41175 commit c3f9d93
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ Finally install it to your system (optional),

ninja -C build install

### Windows

xsystem4 can be built on Windows using MSYS2.

First install MSYS2, and then open the MINGW64 shell and run the following command,

pacman -S flex bison \
mingw-w64-x86_64-gcc \
mingw-w64-x86_64-meson \
mingw-w64-x86_64-pkg-config \
mingw-w64-x86_64-SDL2 \
mingw-w64-x86_64-freetype \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-libwebp \
mingw-w64-x86_64-libsndfile \
mingw-w64-x86_64-glew

Then build the xsystem4 executable with meson,

mkdir build
meson build
ninja -C build

To create a portable executable, it is neccessary to copy some DLLs into the same directory as xsystem4.exe.
You can determine the required DLLs with the following command,

ldd build/src/xsystem4.exe | grep mingw64

The `fonts` and `shaders` directories must also be shipped together with xsystem4.exe.

Installing
----------

Expand Down
25 changes: 15 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ project('system4', 'c',
add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
add_project_arguments('-DXSYS4_DATA_DIR="' + get_option('prefix') / get_option('datadir') / 'xsystem4"', language : 'c')

zlib = dependency('zlib')
static_libs = false
if host_machine.system() == 'windows'
static_libs = true
endif

zlib = dependency('zlib', static : static_libs)
libm = meson.get_compiler('c').find_library('m', required: false)
sdl2 = dependency('sdl2')
ft2 = dependency('freetype2')
ffi = dependency('libffi')
tj = dependency('libturbojpeg')
webp = dependency('libwebp')
png = dependency('libpng')
sdl2 = dependency('sdl2', static : static_libs)
ft2 = dependency('freetype2', static : static_libs)
ffi = dependency('libffi', static : static_libs)
tj = dependency('libturbojpeg', static : static_libs)
webp = dependency('libwebp', static : static_libs)
png = dependency('libpng', static : static_libs)
cglm = dependency('cglm', fallback : ['cglm', 'cglm_dep'])
sndfile = dependency('sndfile')
sndfile = dependency('sndfile', static : static_libs)

gles = dependency('glesv2', version : '>=3', required: get_option('opengles'))
if gles.found()
Expand All @@ -24,8 +29,8 @@ else
gl_deps = [gl, glew]
endif

chibi = dependency('chibi-scheme', required : false)
readline = dependency('readline', required : false)
chibi = dependency('chibi-scheme', required : false, static : static_libs)
readline = dependency('readline', required : false, static : static_libs)

flex = find_program('flex')
bison = find_program('bison')
Expand Down
6 changes: 6 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ if get_option('debugger').allowed()
endif
endif

static_link_args = []
if host_machine.system() == 'windows'
static_link_args = ['-static', '-lstdc++']
endif

executable('xsystem4', xsystem4,
dependencies : xsystem4_deps,
c_args : ['-Wno-unused-parameter'],
link_args : static_link_args,
include_directories : incdir,
install : true)
2 changes: 1 addition & 1 deletion subprojects/libsys4
Submodule libsys4 updated 1 files
+1 −1 src/savefile.c

0 comments on commit c3f9d93

Please sign in to comment.