From a38f163db90cf51e5e8d24b53d12882303edb99a Mon Sep 17 00:00:00 2001 From: Deve Date: Tue, 23 May 2023 23:36:06 +0200 Subject: [PATCH] Add build scripts for Windows using MSYS2 (#130) --- .github/workflows/build.yml | 40 ++++++++++++++++ Windows/.gitignore | 9 ++++ Windows/Manual.md | 33 ++++++++++++++ Windows/Start.sh | 73 ++++++++++++++++++++++++++++++ Windows/deps/SDL2.sh | 37 +++++++++++++++ Windows/deps/freetype.sh | 39 ++++++++++++++++ Windows/deps/gettext.sh | 29 ++++++++++++ Windows/deps/irrlicht.sh | 32 +++++++++++++ Windows/deps/libcurl.sh | 41 +++++++++++++++++ Windows/deps/libjpeg.sh | 33 ++++++++++++++ Windows/deps/libogg.sh | 30 ++++++++++++ Windows/deps/libpng.sh | 39 ++++++++++++++++ Windows/deps/libraries.sh | 20 ++++++++ Windows/deps/luajit.sh | 27 +++++++++++ Windows/deps/openal.sh | 35 ++++++++++++++ Windows/deps/sdk.sh | 6 +++ Windows/deps/sqlite.sh | 32 +++++++++++++ Windows/deps/vorbis.sh | 31 +++++++++++++ Windows/deps/zlib.sh | 34 ++++++++++++++ cmake/Modules/FindGettextLib.cmake | 8 +++- src/CMakeLists.txt | 42 +++++++++++++++++ src/client/renderingengine.cpp | 6 --- src/gettext.cpp | 4 +- src/main.cpp | 8 ++++ 24 files changed, 678 insertions(+), 10 deletions(-) create mode 100644 Windows/.gitignore create mode 100644 Windows/Manual.md create mode 100755 Windows/Start.sh create mode 100755 Windows/deps/SDL2.sh create mode 100755 Windows/deps/freetype.sh create mode 100755 Windows/deps/gettext.sh create mode 100755 Windows/deps/irrlicht.sh create mode 100755 Windows/deps/libcurl.sh create mode 100755 Windows/deps/libjpeg.sh create mode 100755 Windows/deps/libogg.sh create mode 100755 Windows/deps/libpng.sh create mode 100755 Windows/deps/libraries.sh create mode 100755 Windows/deps/luajit.sh create mode 100755 Windows/deps/openal.sh create mode 100755 Windows/deps/sdk.sh create mode 100755 Windows/deps/sqlite.sh create mode 100755 Windows/deps/vorbis.sh create mode 100755 Windows/deps/zlib.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9990a1061..d9d5c7b75 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -214,6 +214,46 @@ jobs: NO_MINETEST_GAME: 1 NO_PACKAGE: 1 + msys2-mingw64: + name: "MSYS2-MinGW (64-bit)" + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@v3 + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-autotools git zip + + - name: Build + run: | + cd ./Windows + ./Start.sh + cmake --build . -j + cd - + strip -s ./bin/multicraft.exe + + - name: Create ZIP + run: | + mkdir MultiCraft + cp -r ./bin MultiCraft/ + cp -r ./builtin MultiCraft/ + cp -r ./client MultiCraft/ + cp -r ./fonts MultiCraft/ + cp -r ./games MultiCraft/ + cp -r ./locale MultiCraft/ + cp -r ./textures MultiCraft/ + zip -r MultiCraft.zip MultiCraft + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: MultiCraft-msys2-mingw64 + path: ./MultiCraft.zip + msvc: name: VS 2022 ${{ matrix.config.arch }}-${{ matrix.type }} runs-on: windows-2022 diff --git a/Windows/.gitignore b/Windows/.gitignore new file mode 100644 index 000000000..b09b607bb --- /dev/null +++ b/Windows/.gitignore @@ -0,0 +1,9 @@ +CMakeFiles +deps/* +!deps/*.sh +lib +locale +src +*.ninja* +*.cmake +CMakeCache.txt diff --git a/Windows/Manual.md b/Windows/Manual.md new file mode 100644 index 000000000..72dbb69a3 --- /dev/null +++ b/Windows/Manual.md @@ -0,0 +1,33 @@ +1. Download MSYS2 from https://www.msys2.org/ + + https://github.com/msys2/msys2-installer/releases/download/2023-03-18/msys2-x86_64-20230318.exe + +2. After installation open "MSYS2 MINGW64" from Menu Start + +3. Install required packages with + + pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-autotools git + +4. Browse to MultiCraft directory, for example + + cd /c/Users/username/Documents/MultiCraft + +5. Build inside build/windows directory with + + ./Start + cmake --build . -j + +6. Check libraries linked with multicraft.exe using command below. It should + show only system libraries. + + objdump -x ../../bin/multicraft.exe | grep dll + + +-------------- + +The "make -j" and even "make -j`nproc`" eats a lot of memory (when building libcurl). +If it's a problem, then change NPROC to 1 or so. + +Also, don't install any other packages that are not for mingw because then some +libraries search headers in /usr/include rather than /mingw64/include and fail +to compile. diff --git a/Windows/Start.sh b/Windows/Start.sh new file mode 100755 index 000000000..fb521da75 --- /dev/null +++ b/Windows/Start.sh @@ -0,0 +1,73 @@ +#!/bin/bash -e + +echo +echo "Starting build MultiCraft for Windows..." + +echo +echo "Build Libraries:" + +cd deps +sh libraries.sh +cd .. + +export DEPS_ROOT=$(pwd)/deps + +cmake ../ \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_SQLITE=1 \ + -DENABLE_POSTGRESQL=0 \ + -DENABLE_LEVELDB=0 \ + -DENABLE_REDIS=0 \ + -DENABLE_SPATIAL=0 \ + -DENABLE_PROMETHEUS=0 \ + -DENABLE_CURSES=0 \ + -DENABLE_SYSTEM_GMP=0 \ + -DUSE_SDL=1 \ + -DUSE_STATIC_BUILD=1 \ + -DCMAKE_C_FLAGS="-static \ + -DNO_IRR_COMPILE_WITH_SDL_TEXTINPUT_ \ + -DNO_IRR_COMPILE_WITH_OGLES2_ \ + -DNO_IRR_COMPILE_WITH_DIRECT3D_9_ \ + -DNO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ \ + -D_IRR_STATIC_LIB_ \ + -DAL_LIBTYPE_STATIC \ + -DCURL_STATICLIB" \ + -DCMAKE_CXX_FLAGS="-static \ + -DNO_IRR_COMPILE_WITH_SDL_TEXTINPUT_ \ + -DNO_IRR_COMPILE_WITH_OGLES2_ \ + -DNO_IRR_COMPILE_WITH_DIRECT3D_9_ \ + -DNO_IRR_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ \ + -D_IRR_STATIC_LIB_ \ + -DAL_LIBTYPE_STATIC \ + -DCURL_STATICLIB" \ + -DIRRLICHT_LIBRARY="$DEPS_ROOT/irrlicht/lib/libIrrlicht.a" \ + -DIRRLICHT_INCLUDE_DIR="$DEPS_ROOT/irrlicht/include" \ + -DSDL2_LIBRARIES="$DEPS_ROOT/sdl2/lib/libSDL2.a" \ + -DSDL2_INCLUDE_DIR="$DEPS_ROOT/sdl2/include" \ + -DCURL_LIBRARY="$DEPS_ROOT/libcurl/lib/libcurl.a" \ + -DCURL_INCLUDE_DIR="$DEPS_ROOT/libcurl/include" \ + -DLUA_LIBRARY="$DEPS_ROOT/luajit/lib/libluajit.a" \ + -DLUA_INCLUDE_DIR="$DEPS_ROOT/luajit/include" \ + -DZLIB_LIBRARIES="$DEPS_ROOT/zlib/lib/libzlibstatic.a" \ + -DZLIB_INCLUDE_DIR="$DEPS_ROOT/zlib/include" \ + -DPNG_LIBRARIES="$DEPS_ROOT/libpng/lib/libpng16.a" \ + -DPNG_INCLUDE_DIR="$DEPS_ROOT/libpng/include" \ + -DJPEG_LIBRARIES="$DEPS_ROOT/libjpeg/lib/libjpeg.a" \ + -DJPEG_INCLUDE_DIR="$DEPS_ROOT/libjpeg/include" \ + -DFREETYPE_LIBRARY="$DEPS_ROOT/freetype/lib/libfreetype.a" \ + -DFREETYPE_INCLUDE_DIRS="$DEPS_ROOT/freetype/include" \ + -DSQLITE3_LIBRARY="$DEPS_ROOT/sqlite/lib/libsqlite3.a" \ + -DSQLITE3_INCLUDE_DIR="$DEPS_ROOT/sqlite/include" \ + -DOGG_LIBRARY="$DEPS_ROOT/libogg/lib/libogg.a" \ + -DOGG_INCLUDE_DIR="$DEPS_ROOT/libogg/include" \ + -DVORBIS_LIBRARY="$DEPS_ROOT/libvorbis/lib/libvorbis.a" \ + -DVORBISFILE_LIBRARY="$DEPS_ROOT/libvorbis/lib/libvorbisfile.a" \ + -DVORBIS_INCLUDE_DIR="$DEPS_ROOT/libvorbis/include" \ + -DGETTEXT_LIBRARY="$DEPS_ROOT/gettext/lib/libintl.a" \ + -DGETTEXT_ICONV_LIBRARY="/mingw64/lib/libiconv.a" \ + -DGETTEXT_INCLUDE_DIR="$DEPS_ROOT/gettext/include" \ + -DOPENAL_LIBRARY="$DEPS_ROOT/openal/lib/libOpenAL32.a" \ + -DOPENAL_INCLUDE_DIR="$DEPS_ROOT/openal/include/AL" + +echo +echo "Build with 'cmake --build . -j'" diff --git a/Windows/deps/SDL2.sh b/Windows/deps/SDL2.sh new file mode 100755 index 000000000..ae14b4d8e --- /dev/null +++ b/Windows/deps/SDL2.sh @@ -0,0 +1,37 @@ +#!/bin/bash -e + +SDL2_VERSION=2.26.5 + +. ./sdk.sh + +if [ ! -d SDL2-src ]; then + wget https://github.com/libsdl-org/SDL/archive/release-$SDL2_VERSION.tar.gz + tar -xzvf release-$SDL2_VERSION.tar.gz + mv SDL-release-$SDL2_VERSION sdl2-src + rm release-$SDL2_VERSION.tar.gz +fi + +cd sdl2-src + +mkdir -p build; cd build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_FLAGS="$CFLAGS" \ + -DCMAKE_CXX_FLAGS="$CXXFLAGS -fPIC" \ + -DSDL_SHARED=0 \ + -DSDL_STATIC=1 + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../sdl2/include +mkdir -p ../../sdl2/include +cp -a ./include ../../sdl2 +cp -a ./include-config-release/* ../../sdl2/include +# update lib +rm -rf ../../sdl2/lib +mkdir -p ../../sdl2/lib +cp -a *.a ../../sdl2/lib + +echo "SDL2 build successful" diff --git a/Windows/deps/freetype.sh b/Windows/deps/freetype.sh new file mode 100755 index 000000000..746f744bc --- /dev/null +++ b/Windows/deps/freetype.sh @@ -0,0 +1,39 @@ +#!/bin/bash -e + +FREETYPE_VERSION=2.13.0 + +. ./sdk.sh + +if [ ! -d freetype-src ]; then + wget https://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.gz + tar -xzvf freetype-$FREETYPE_VERSION.tar.gz + mv freetype-$FREETYPE_VERSION freetype-src + rm freetype-$FREETYPE_VERSION.tar.gz + mkdir freetype-src/build +fi + +cd freetype-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=FALSE \ + -DFT_DISABLE_BZIP2=TRUE \ + -DFT_DISABLE_PNG=TRUE \ + -DFT_DISABLE_HARFBUZZ=TRUE \ + -DFT_DISABLE_BROTLI=TRUE \ + -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../freetype/include +mkdir -p ../../freetype/include +cp -a ../include ../../freetype +cp -a ./include ../../freetype +rm -rf ../../freetype/include/dlg +# update lib +rm -rf ../../freetype/lib +mkdir -p ../../freetype/lib +cp libfreetype.a ../../freetype/lib + +echo "Freetype build successful" diff --git a/Windows/deps/gettext.sh b/Windows/deps/gettext.sh new file mode 100755 index 000000000..bc8436411 --- /dev/null +++ b/Windows/deps/gettext.sh @@ -0,0 +1,29 @@ +#!/bin/bash -e + +. ./sdk.sh +GETTEXT_VERSION=0.21.1 + +if [ ! -d gettext-src ]; then + wget https://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz + tar -xzvf gettext-$GETTEXT_VERSION.tar.gz + mv gettext-$GETTEXT_VERSION gettext-src + rm gettext-$GETTEXT_VERSION.tar.gz +fi + +cd gettext-src/gettext-runtime + +./configure CFLAGS="$CFLAGS" CPPFLAGS="$CXXFLAGS" \ + --disable-shared --enable-static --disable-libasprintf + +make -j$NPROC + +# update `include` folder +rm -rf ../../gettext/include +mkdir -p ../../gettext/include +cp intl/libintl.h ../../gettext/include +# update lib +rm -rf ../../gettext/lib +mkdir -p ../../gettext/lib +cp intl/.libs/libintl.a ../../gettext/lib + +echo "Gettext build successful" diff --git a/Windows/deps/irrlicht.sh b/Windows/deps/irrlicht.sh new file mode 100755 index 000000000..ba5f1bfdf --- /dev/null +++ b/Windows/deps/irrlicht.sh @@ -0,0 +1,32 @@ +#!/bin/bash -e + +. ./sdk.sh + +export DEPS_ROOT=$(pwd) + +[ ! -d irrlicht-src ] && \ + git clone --depth 1 -b SDL2 https://github.com/MoNTE48/Irrlicht irrlicht-src + +cd irrlicht-src/source/Irrlicht + +CPPFLAGS="$CPPFLAGS \ + -DNO_IRR_COMPILE_WITH_SDL_TEXTINPUT_ \ + -DNO_IRR_COMPILE_WITH_OGLES2_ \ + -DNO_IRR_COMPILE_WITH_DIRECT3D_9_ \ + -I$DEPS_ROOT/sdl2/include \ + -I$DEPS_ROOT/zlib/include \ + -I$DEPS_ROOT/libjpeg/include \ + -I$DEPS_ROOT/libpng/include" \ +CXXFLAGS="$CXXFLAGS -std=gnu++17" \ +make staticlib_win32 -j$NPROC NDEBUG=1 + +# update `include` folder +rm -rf ../../../irrlicht/include +mkdir -p ../../../irrlicht/include +cp -a ../../include ../../../irrlicht +# update lib +rm -rf ../../../irrlicht/lib +mkdir -p ../../../irrlicht/lib +cp ../../lib/Win32-gcc/libIrrlicht.a ../../../irrlicht/lib + +echo "Irrlicht build successful" diff --git a/Windows/deps/libcurl.sh b/Windows/deps/libcurl.sh new file mode 100755 index 000000000..a2e8f1e86 --- /dev/null +++ b/Windows/deps/libcurl.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e + +. ./sdk.sh +CURL_VERSION=8.1.1 + +export DEPS_ROOT=$(pwd) + +if [ ! -d libcurl-src ]; then + wget https://curl.haxx.se/download/curl-$CURL_VERSION.tar.gz + tar -xzvf curl-$CURL_VERSION.tar.gz + mv curl-$CURL_VERSION libcurl-src + rm curl-$CURL_VERSION.tar.gz +fi + +cd libcurl-src + +./configure \ + --with-schannel \ + --disable-shared --enable-static \ + --disable-debug --disable-verbose --disable-versioned-symbols \ + --disable-dependency-tracking --disable-libcurl-option \ + --disable-ares --disable-cookies --disable-crypto-auth --disable-manual \ + --disable-proxy --disable-unix-sockets --without-librtmp \ + --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp \ + --disable-dict --disable-telnet --disable-tftp --disable-pop3 \ + --disable-imap --disable-smtp --disable-gopher \ + --without-zstd --without-brotli --without-nghttp2 --without-libidn2 \ + --without-libpsl + +make -j$NPROC + +# update `include` folder +rm -rf ../libcurl/include +mkdir -p ../libcurl/include +cp -a ./include ../libcurl +# update lib +rm -rf ../libcurl/lib +mkdir -p ../libcurl/lib +cp lib/.libs/libcurl.a ../libcurl/lib + +echo "libcurl build successful" diff --git a/Windows/deps/libjpeg.sh b/Windows/deps/libjpeg.sh new file mode 100755 index 000000000..e6f6083b9 --- /dev/null +++ b/Windows/deps/libjpeg.sh @@ -0,0 +1,33 @@ +#!/bin/bash -e + +. ./sdk.sh +JPEG_VERSION=2.1.5.1 + +if [ ! -d libjpeg-src ]; then + wget https://download.sourceforge.net/libjpeg-turbo/libjpeg-turbo-$JPEG_VERSION.tar.gz + tar -xzvf libjpeg-turbo-$JPEG_VERSION.tar.gz + mv libjpeg-turbo-$JPEG_VERSION libjpeg-src + rm libjpeg-turbo-$JPEG_VERSION.tar.gz + mkdir libjpeg-src/build +fi + +cd libjpeg-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_SHARED=OFF \ + -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../libjpeg/include +mkdir -p ../../libjpeg/include +cp -a ../*.h ../../libjpeg/include +cp -a *.h ../../libjpeg/include +# update lib +rm -rf ../../libjpeg/lib +mkdir -p ../../libjpeg/lib +cp libjpeg.a ../../libjpeg/lib + +echo "libjpeg build successful" diff --git a/Windows/deps/libogg.sh b/Windows/deps/libogg.sh new file mode 100755 index 000000000..25f8f95fd --- /dev/null +++ b/Windows/deps/libogg.sh @@ -0,0 +1,30 @@ +#!/bin/bash -e + +. ./sdk.sh +OGG_VERSION=1.3.5 + +if [ ! -d libogg-src ]; then + git clone -b v$OGG_VERSION --depth 1 https://github.com/xiph/ogg libogg-src + mkdir libogg-src/build +fi + +cd libogg-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" \ + -DCMAKE_CXX_FLAGS="$CXXFLAGS -fPIC" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../libogg/include +mkdir -p ../../libogg/include +cp -a ../include ../../libogg +cp -a ./include ../../libogg +# update lib +rm -rf ../../libogg/lib +mkdir -p ../../libogg/lib +cp libogg.a ../../libogg/lib + +echo "Ogg build successful" diff --git a/Windows/deps/libpng.sh b/Windows/deps/libpng.sh new file mode 100755 index 000000000..16f8c72d6 --- /dev/null +++ b/Windows/deps/libpng.sh @@ -0,0 +1,39 @@ +#!/bin/bash -e + +. ./sdk.sh +PNG_VERSION=1.6.39 + +export DEPS_ROOT=$(pwd) + +if [ ! -d libpng-src ]; then + wget https://download.sourceforge.net/libpng/libpng-$PNG_VERSION.tar.gz + tar -xzvf libpng-$PNG_VERSION.tar.gz + mv libpng-$PNG_VERSION libpng-src + rm libpng-$PNG_VERSION.tar.gz + mkdir libpng-src/build +fi + +cd libpng-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DPNG_SHARED=OFF \ + -DPNG_TESTS=OFF \ + -DPNG_EXECUTABLES=OFF \ + -DPNG_BUILD_ZLIB=ON \ + -DZLIB_INCLUDE_DIRS="$DEPS_ROOT/zlib/include" \ + -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../libpng/include +mkdir -p ../../libpng/include +cp -a ../*.h ../../libpng/include +cp -a *.h ../../libpng/include +# update lib +rm -rf ../../libpng/lib +mkdir -p ../../libpng/lib +cp libpng16.a ../../libpng/lib + +echo "libpng build successful" diff --git a/Windows/deps/libraries.sh b/Windows/deps/libraries.sh new file mode 100755 index 000000000..54a7d44d2 --- /dev/null +++ b/Windows/deps/libraries.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +# Build libs + +sh ./freetype.sh +sh ./gettext.sh +sh ./sqlite.sh +sh ./luajit.sh +sh ./libjpeg.sh +sh ./zlib.sh +sh ./libpng.sh +sh ./SDL2.sh +sh ./irrlicht.sh +sh ./openal.sh +sh ./libcurl.sh +sh ./libogg.sh +sh ./vorbis.sh + +echo +echo "All libraries were built!" diff --git a/Windows/deps/luajit.sh b/Windows/deps/luajit.sh new file mode 100755 index 000000000..80e7db248 --- /dev/null +++ b/Windows/deps/luajit.sh @@ -0,0 +1,27 @@ +#!/bin/bash -e + +LUAJIT_VERSION=2.1 + +. ./sdk.sh + +if [ ! -d luajit-src ]; then + wget https://github.com/LuaJIT/LuaJIT/archive/v$LUAJIT_VERSION.tar.gz + tar -xzvf v$LUAJIT_VERSION.tar.gz + mv LuaJIT-$LUAJIT_VERSION luajit-src + rm v$LUAJIT_VERSION.tar.gz +fi + +cd luajit-src + +make amalg -j$NPROC BUILDMODE=static + +# update `include` folder +rm -rf ../luajit/include +mkdir -p ../luajit/include +cp -a ./src/*.h ../luajit/include +# update lib +rm -rf ../luajit/lib +mkdir -p ../luajit/lib +cp src/libluajit.a ../luajit/lib + +echo "LuaJIT build successful" diff --git a/Windows/deps/openal.sh b/Windows/deps/openal.sh new file mode 100755 index 000000000..82be18721 --- /dev/null +++ b/Windows/deps/openal.sh @@ -0,0 +1,35 @@ +#!/bin/bash -e + +. ./sdk.sh +OPENAL_VERSION=1.23.1 + +if [ ! -d openal-src ]; then + git clone -b $OPENAL_VERSION --depth 1 https://github.com/kcat/openal-soft openal-src +fi + +cd openal-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DLIBTYPE=STATIC \ + -DALSOFT_EMBED_HRTF_DATA=ON \ + -DALSOFT_UTILS=OFF \ + -DALSOFT_EXAMPLES=OFF \ + -DALSOFT_BACKEND_WAVE=OFF \ + -DALSOFT_BACKEND_SNDIO=OFF \ + -DCMAKE_C_FLAGS="$CFLAGS" \ + -DCMAKE_CXX_FLAGS="$CXXFLAGS -fPIC" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../openal/include +mkdir -p ../../openal/include +cp -a ../include ../../openal +cp -a *.h ../../openal/include +# update lib +rm -rf ../../openal/lib +mkdir -p ../../openal/lib +cp libOpenAL32.a ../../openal/lib + +echo "OpenAL-Soft build successful" diff --git a/Windows/deps/sdk.sh b/Windows/deps/sdk.sh new file mode 100755 index 000000000..00d7043d2 --- /dev/null +++ b/Windows/deps/sdk.sh @@ -0,0 +1,6 @@ +#!/bin/bash -e + +export CFLAGS="-fvisibility=hidden -fexceptions -O3" +export CXXFLAGS="$CFLAGS -frtti -O3" + +export NPROC=`nproc` diff --git a/Windows/deps/sqlite.sh b/Windows/deps/sqlite.sh new file mode 100755 index 000000000..c5e3ecb20 --- /dev/null +++ b/Windows/deps/sqlite.sh @@ -0,0 +1,32 @@ +#!/bin/bash -e + +SQLITE_VERSION=3.42.0 + +. ./sdk.sh + +if [ ! -d sqlite-src ]; then + wget https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=version-$SQLITE_VERSION + tar -xzvf sqlite.tar.gz?r=version-$SQLITE_VERSION + mv sqlite sqlite-src + rm sqlite.tar.gz?r=version-$SQLITE_VERSION + mkdir sqlite-src/build +fi + +cd sqlite-src/build + +../configure \ + --enable-shared \ + --enable-static + +make -j$NPROC + +# update `include` folder +rm -rf ../../sqlite/include +mkdir -p ../../sqlite/include +cp -a ./sqlite3*.h ../../sqlite/include +# update lib +rm -rf ../../sqlite/lib +mkdir -p ../../sqlite/lib +cp .libs/libsqlite3.a ../../sqlite/lib + +echo "SQLite build successful" diff --git a/Windows/deps/vorbis.sh b/Windows/deps/vorbis.sh new file mode 100755 index 000000000..f841ffff9 --- /dev/null +++ b/Windows/deps/vorbis.sh @@ -0,0 +1,31 @@ +#!/bin/bash -e + +. ./sdk.sh +VORBIS_VERSION=1.3.7 + +if [ ! -d libvorbis-src ]; then + git clone -b v$VORBIS_VERSION --depth 1 https://github.com/xiph/vorbis libvorbis-src + mkdir libvorbis-src/build +fi + +cd libvorbis-src/build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DOGG_LIBRARY="../../libogg/libogg.a" \ + -DOGG_INCLUDE_DIR="../../libogg/include" \ + -DCMAKE_C_FLAGS_RELEASE="$CFLAGS" \ + -DCMAKE_CXX_FLAGS="$CXXFLAGS -fPIC" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../libvorbis/include +mkdir -p ../../libvorbis/include +cp -a ../include ../../libvorbis +# update lib +rm -rf ../../libvorbis/lib +mkdir -p ../../libvorbis/lib +cp -a lib/*.a ../../libvorbis/lib + +echo "Vorbis build successful" diff --git a/Windows/deps/zlib.sh b/Windows/deps/zlib.sh new file mode 100755 index 000000000..4d9392342 --- /dev/null +++ b/Windows/deps/zlib.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +ZLIB_VERSION=1.2.13 + +. ./sdk.sh + +if [ ! -d zlib-src ]; then + wget https://github.com/madler/zlib/archive/v$ZLIB_VERSION.tar.gz + tar -xzvf v$ZLIB_VERSION.tar.gz + mv zlib-$ZLIB_VERSION zlib-src + rm v$ZLIB_VERSION.tar.gz +fi + +cd zlib-src + +mkdir -p build; cd build + +cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_FLAGS="$CFLAGS" + +cmake --build . -j$NPROC + +# update `include` folder +rm -rf ../../zlib/include +mkdir -p ../../zlib/include +cp -a ../*.h ../../zlib/include +cp -a *.h ../../zlib/include +# update lib +rm -rf ../../zlib/lib +mkdir -p ../../zlib/lib +cp libzlibstatic.a ../../zlib/lib + +echo "zlib build successful" diff --git a/cmake/Modules/FindGettextLib.cmake b/cmake/Modules/FindGettextLib.cmake index 529452a4a..a09a7e699 100644 --- a/cmake/Modules/FindGettextLib.cmake +++ b/cmake/Modules/FindGettextLib.cmake @@ -50,7 +50,7 @@ if(WIN32) NAMES libiconv2.dll PATHS "${CUSTOM_GETTEXT_PATH}/bin" "${CUSTOM_GETTEXT_PATH}/lib" DOC "gettext *iconv*.lib") - set(GETTEXT_REQUIRED_VARS ${GETTEXT_REQUIRED_VARS} GETTEXT_DLL GETTEXT_ICONV_DLL) + set(GETTEXT_REQUIRED_VARS ${GETTEXT_REQUIRED_VARS} GETTEXT_LIBRARY) endif(WIN32) @@ -65,7 +65,11 @@ if(GETTEXTLIB_FOUND) endif() set(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po) - set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale//LC_MESSAGES) + if(WIN32) + set(GETTEXT_MO_BUILD_PATH ${CMAKE_SOURCE_DIR}/locale//LC_MESSAGES) + else() + set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale//LC_MESSAGES) + endif() set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}//LC_MESSAGES) file(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*") list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES minetest.pot) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67c74f253..24ff14c88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,22 @@ if(NOT (BUILD_CLIENT OR BUILD_SERVER)) set(BUILD_SERVER TRUE) endif() +option(USE_SDL "Use SDL2 for window management" FALSE) +option(USE_STATIC_BUILD "Link additional libraries needed for static build" FALSE) + +if(USE_SDL) + if(NOT USE_STATIC_BUILD) + find_package(SDL2) + else() + set(SDL2_FOUND TRUE) + endif() + if (SDL2_FOUND) + message(STATUS "SDL2 found.") + include_directories(${SDL2_INCLUDE_DIR}) + else() + message(FATAL_ERROR "SDL2 not found.") + endif() +endif() option(ENABLE_CURL "Enable cURL support for fetching media" TRUE) set(USE_CURL FALSE) @@ -566,6 +582,21 @@ if(BUILD_CLIENT) ) endif() + if(USE_SDL) + target_link_libraries( + ${PROJECT_NAME} + ${SDL2_LIBRARIES} + ) + if(USE_STATIC_BUILD AND WIN32) + target_link_libraries( + ${PROJECT_NAME} + winmm + imm32 + setupapi + opengl32 + ) + endif() + endif() if(ENABLE_GLES) target_link_libraries( ${PROJECT_NAME} @@ -583,12 +614,23 @@ if(BUILD_CLIENT) ${PROJECT_NAME} ${GETTEXT_LIBRARY} ) + if(USE_STATIC_BUILD) + target_link_libraries( + ${PROJECT_NAME} + ${GETTEXT_ICONV_LIBRARY} + ) + endif() endif() if(USE_CURL) target_link_libraries( ${PROJECT_NAME} ${CURL_LIBRARY} ) + if(USE_STATIC_BUILD) + if(WIN32) + target_link_libraries(${PROJECT_NAME} bcrypt crypt32 ws2_32) + endif() + endif() endif() if(USE_FREETYPE) if(FREETYPE_PKGCONFIG_FOUND) diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 1884a1a58..0bee0a044 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -335,12 +335,6 @@ static bool getWindowHandle(irr::video::IVideoDriver *driver, HWND &hWnd) const video::SExposedVideoData exposedData = driver->getExposedVideoData(); switch (driver->getDriverType()) { - case video::EDT_DIRECT3D8: - hWnd = reinterpret_cast(exposedData.D3D8.HWnd); - break; - case video::EDT_DIRECT3D9: - hWnd = reinterpret_cast(exposedData.D3D9.HWnd); - break; case video::EDT_OPENGL: hWnd = reinterpret_cast(exposedData.OpenGLWin32.HWnd); break; diff --git a/src/gettext.cpp b/src/gettext.cpp index 4a3f41590..63ba6cb1f 100644 --- a/src/gettext.cpp +++ b/src/gettext.cpp @@ -219,8 +219,8 @@ void init_gettext(const char *path, const std::string &configured_language, if (locale[0].language) { char lang[3] = {0}; strncpy(lang, locale[0].language, 2); - setenv("LANG", lang, 1); - setenv("LANGUAGE", lang, 1); + SDL_setenv("LANG", lang, 1); + SDL_setenv("LANGUAGE", lang, 1); } SDL_free(locale); diff --git a/src/main.cpp b/src/main.cpp index f7e06afba..76d19fc8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -250,6 +250,14 @@ int main(int argc, char *argv[]) return retval; } +#ifdef WIN32 +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + LPSTR lpCmdLine, int nCmdShow) +{ + return main(__argc, __argv); +} +#endif + /***************************************************************************** * Startup / Init