Skip to content

Commit

Permalink
Cross compile object creator from linux to Windows using Devcontainer (
Browse files Browse the repository at this point in the history
…CleverRaven#67601)

* Add object_creator windows build option to makefile

Added a build command to the makefile to cross-compile the
object_creator

* Modify the defcontainer dockerfile for QT5

Added the make command for QT5. The QT5 packages will be built on the
devcontainer.

* Change object creator makefile for cross-compile

Changes the makefile so cross-compilation to Windows is possible. Right
now the compilation to linux is no longer possible. Additional changes
are needed to fix this.

* Separated windows and linux builds in makefile

In the same way that the general makefile checks for cross-compilation,
I separated the linux and the windows commands. This should make it so
you can build the linux version as well

* Add object_creator plugin import file

Without this file it's still possible to compile, but when executing the
application, it complains about missing QT plugins. That's why this file
should be present in the directory.

* OBject creator makefile formatting and change dest

Did some formatting, removed 1 line that was not nessesary and changed
the target destination to the object_creator directory. Also added
object_creator.exe removal to the clean command.

* Remove unnecessary code from makefile

* turns out it was nessecary code

* change include for qt5 plugins

* This is the only plugin we need

* removed the qt_staticplugin condition

* Changed the makefile so it works again

Changed some of the code so it works again after I broke it. Now to
continue with the cleanup

* Removed unnecessary code

* Removed unneeded libraries from makefile

* Reduce QT5 installation to basic in dockerfile

* Add comments, documentation

* Add build notes to documentation

* Adjust link in documentation
  • Loading branch information
snipercup authored Aug 19, 2023
1 parent 6b15a5c commit 6300d3d
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 29 additions & 1 deletion doc/COMPILING/COMPILING-DEVCONTAINER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 47 additions & 4 deletions object_creator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions object_creator/creator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

#include <QtWidgets/qapplication.h>
#include <QtCore/QSettings>
#ifdef QT_STATICPLUGIN
#include <QtCore/QtPlugin>

#ifdef _WIN32
#include <QtCore/QtPlugin>
Q_IMPORT_PLUGIN( QWindowsIntegrationPlugin );
#endif
#endif

struct MOD_INFORMATION;
using mod_id = string_id<MOD_INFORMATION>;
Expand Down

0 comments on commit 6300d3d

Please sign in to comment.