Link statically on Windows

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.
This commit is contained in:
Nunuhara Cabbage
2023-03-29 03:09:20 -07:00
parent ac411754a0
commit 63348ac21e
4 changed files with 52 additions and 11 deletions
+30
View File
@@ -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
----------
+15 -10
View File
@@ -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()
@@ -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')
+6
View File
@@ -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)