From c3f9d939175695a0b4a58492538cb2a0688ee06b Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Wed, 29 Mar 2023 03:09:20 -0700 Subject: [PATCH] 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. --- README.md | 30 ++++++++++++++++++++++++++++++ meson.build | 25 +++++++++++++++---------- src/meson.build | 6 ++++++ subprojects/libsys4 | 2 +- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d5491b0..4b9b433 100644 --- a/README.md +++ b/README.md @@ -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 ---------- diff --git a/meson.build b/meson.build index 95974c1..15c4dd7 100644 --- a/meson.build +++ b/meson.build @@ -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') diff --git a/src/meson.build b/src/meson.build index 95af875..f81ac25 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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) diff --git a/subprojects/libsys4 b/subprojects/libsys4 index b869f6c..b5aaaff 160000 --- a/subprojects/libsys4 +++ b/subprojects/libsys4 @@ -1 +1 @@ -Subproject commit b869f6cc8d6f417272de6a2f01ef66473cb06e22 +Subproject commit b5aaaff8fe9dcc8e5c7179b37725c0607a8931da