diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 627bb0a9df0c5..4052a7013a08c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -53,3 +53,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # RUN wget https://github.com/Qrox/libbacktrace/releases/download/2020-01-03/libbacktrace-i686-w64-mingw32.tar.gz # RUN tar -xzf libbacktrace-x86_64-w64-mingw32.tar.gz --exclude=LICENSE -C /opt/mxe/usr/x86_64-w64-mingw32.static # RUN tar -xzf libbacktrace-i686-w64-mingw32.tar.gz --exclude=LICENSE -C /opt/mxe/usr/i686-w64-mingw32.static + +# #Additional steps to cross compile object_creator. Uncomment this if you want to cross-compile the object cretor +# WORKDIR /opt/mxe +# RUN make MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' qtbase +# RUN export PATH=/opt/mxe/usr/bin:$PATH diff --git a/Makefile b/Makefile index 35cafb414dede..d524aefa6c9e2 100644 --- a/Makefile +++ b/Makefile @@ -1302,6 +1302,9 @@ clean-tests: object_creator: version $(BUILD_PREFIX)cataclysm.a $(MAKE) -C object_creator +object_creator.exe: version $(BUILD_PREFIX)cataclysm.a + $(MAKE) -C object_creator object_creator.exe + clean-object_creator: $(MAKE) -C object_creator clean diff --git a/doc/COMPILING/COMPILING-DEVCONTAINER.md b/doc/COMPILING/COMPILING-DEVCONTAINER.md index c8fe8f2940749..539d5fcc08ea2 100644 --- a/doc/COMPILING/COMPILING-DEVCONTAINER.md +++ b/doc/COMPILING/COMPILING-DEVCONTAINER.md @@ -73,4 +73,32 @@ You can then test your build using this command in the terminal: Next, press the play button to build the game. After it is build, you should see the cataclysm-tiles.exe file in the folder where you cloned your fork to (e.g. /workspaces/Cataclysm-DDA) - + + +# Cross-compiling object creator from Linux to Windows +These steps allow you to cross-compile the object creator from Linux to Windows + +1. Follow all of the steps written earlier in this guide + +2. Open the Dockerfile in the VSCode file browser and scroll down to find this section: + + ![Image showing the commented part of the dockerfile](../img/Devcontainer-Find-Commented-QT5-Commands-In-Dockerfile.png) + + Uncomment that part (select it and press ctrl+/ in vscode) so it looks like this: + + ![Image showing the uncommented part of the dockerfile](../img/Devcontainer-Uncomment-QT5-Part-In-Dockerfile.png) + +3. Save the Dockerfile and re-open VSCode. Allow the Devcontainer to rebuild. This is going to take a while (45 minutes depending on the performance of your computer) + + ![Image showing prompt to rebuild the devcontainer](../img/Devcontainer-Dockerfile-Changed-Prompt-Click-Rebuild.png) + +4. After the devcontainer is build, enter the following command into the terminal in vscode (you may need to click the + sign to open a new terminal): `make object_creator.exe CROSS="/opt/mxe/usr/bin/x86_64-w64-mingw32.static-" TILES=1 SOUND=1 RELEASE=1 LOCALIZE=1 PREFIX=output PCH=0 MXE_TARGETS='x86_64-w64-mingw32.static'` + + ![Image showing prompt to rebuild the devcontainer](../img/Devcontainer-Enter-Build-Command-Object-Creator-Terminal.png) + + Note: This will only work if you first build the windows version of cataclysm-tiles as described in [Cross-compiling from Linux to Windows](https://github.com/CleverRaven/Cataclysm-DDA/blob/master/doc/COMPILING/COMPILING-DEVCONTAINER.md#cross-compiling-from-linux-to-windows). + + Note 2: If you want to make a clean built, enter `make clean-object_creator` in the terminal before you run the build command. + + This will build the object creator. After it is build, you should see the object_creator.exe file object_creator folder inside the folder where you cloned your fork to (e.g. /workspaces/Cataclysm-DDA/object_creator). Copy /object_creator/object_creator.exe to your windows machine in the same folder as cataclysm-tiles.exe + diff --git a/doc/img/Devcontainer-Enter-Build-Command-Object-Creator-Terminal.png b/doc/img/Devcontainer-Enter-Build-Command-Object-Creator-Terminal.png new file mode 100644 index 0000000000000..9cf0293b684e9 Binary files /dev/null and b/doc/img/Devcontainer-Enter-Build-Command-Object-Creator-Terminal.png differ diff --git a/doc/img/Devcontainer-Find-Commented-QT5-Commands-In-Dockerfile.png b/doc/img/Devcontainer-Find-Commented-QT5-Commands-In-Dockerfile.png new file mode 100644 index 0000000000000..802acdaecba5c Binary files /dev/null and b/doc/img/Devcontainer-Find-Commented-QT5-Commands-In-Dockerfile.png differ diff --git a/doc/img/Devcontainer-Uncomment-QT5-Part-In-Dockerfile.png b/doc/img/Devcontainer-Uncomment-QT5-Part-In-Dockerfile.png new file mode 100644 index 0000000000000..1963c92a01081 Binary files /dev/null and b/doc/img/Devcontainer-Uncomment-QT5-Part-In-Dockerfile.png differ diff --git a/object_creator/Makefile b/object_creator/Makefile index bdff3c0415ff5..a51aafe3cace6 100644 --- a/object_creator/Makefile +++ b/object_creator/Makefile @@ -11,21 +11,64 @@ CATA_LIB=../$(BUILD_PREFIX)cataclysm.a ODIR ?= obj -CXXFLAGS += $(QT5_CFLAGS) -I../src -I../tools/format -isystem ../src/third-party -fPIC -LDFLAGS += $(QT5_LIBS) +# MXE cross-compile to win32 +ifneq (,$(findstring mingw32,$(CROSS))) + TARGETSYSTEM=WINDOWS +endif + DEFINES += -DQT_NO_KEYWORDS +# Settings for either WINDOWS or Linux +ifeq ($(TARGETSYSTEM),WINDOWS) + CXXFLAGS += -I../src -I../tools/format -isystem ../src/third-party -fPIC + INCPATH = -I. -I/opt/mxe/usr/x86_64-w64-mingw32.static/qt5/include + LINKER = /opt/mxe/usr/bin/x86_64-w64-mingw32.static-g++ + + QT5DIR = /opt/mxe/usr/x86_64-w64-mingw32.static/qt5 + LIBS = $(QT5DIR)/plugins/platforms/libqwindows.a \ + $(QT5DIR)/lib/libQt5EventDispatcherSupport.a \ + $(QT5DIR)/lib/libQt5FontDatabaseSupport.a \ + $(QT5DIR)/lib/libQt5ThemeSupport.a \ + $(QT5DIR)/lib/libQt5WindowsUIAutomationSupport.a \ + $(QT5DIR)/lib/libQt5Widgets.a \ + $(QT5DIR)/lib/libQt5Gui.a \ + $(QT5DIR)/lib/libQt5Core.a \ + -lwtsapi32 -luserenv -lpcre2-16 -lzstd -lnetapi32 -ldwmapi + + DESTDIR_TARGET = object_creator.exe + # Without this the resulting file size is about 8x larger + LFLAGS = -Wl,-s -Wl,-subsystem,windows -mthreads + + else + CXXFLAGS += $(QT5_CFLAGS) -I../src -I../tools/format -isystem ../src/third-party -fPIC + LDFLAGS += $(QT5_LIBS) +endif + + + object_creator: $(OBJS) $(CATA_LIB) +$(CXX) -o $@ $(OBJS) $(CATA_LIB) $(CXXFLAGS) $(LDFLAGS) +object_creator.exe: $(OBJS) $(CATA_LIB) + $(LINKER) $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJS) $(CATA_LIB) $(LIBS) $(INCPATH) $(LDFLAGS) $(CXXFLAGS) + clean: - rm -f object_creator - rm -rf $(ODIR) + rm -f object_creator object_creator.exe + rm -rf *obj *objwin $(shell mkdir -p $(ODIR)) + + +# Build the windows version if the terget system is windows +# Otherwise, build the linux version +ifeq ($(TARGETSYSTEM),WINDOWS) +$(ODIR)/%.o: %.cpp + $(LINKER) $(LFLAGS) $(LDFLAGS) $(CXXFLAGS) $(DEFINES) $(INCPATH) -c ../object_creator/$< -o $@ +else $(ODIR)/%.o: %.cpp $(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) -c ../object_creator/$< -o $@ +endif .PHONY: clean object_creator diff --git a/object_creator/creator_main.cpp b/object_creator/creator_main.cpp index cf443a15ef708..3fa3224db107c 100644 --- a/object_creator/creator_main.cpp +++ b/object_creator/creator_main.cpp @@ -20,12 +20,11 @@ #include #include -#ifdef QT_STATICPLUGIN -#include + #ifdef _WIN32 +#include Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin ); #endif -#endif struct MOD_INFORMATION; using mod_id = string_id;