Skip to content

Commit

Permalink
Building with CMake on Windows is mostly complete now
Browse files Browse the repository at this point in the history
  • Loading branch information
rollerozxa committed Sep 4, 2023
1 parent 789b709 commit 9a33311
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 39,607 deletions.
12 changes: 6 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Exclude vendored libraries from GitHub language detection
src/lua linguist-vendored
src/luasocket linguist-vendored
src/SDL_image linguist-vendored
src/SDL_mixer linguist-vendored
src/SDL_ttf linguist-vendored
src/SDL-mobile linguist-vendored
src/lua/* linguist-vendored
src/luasocket/* linguist-vendored
src/SDL_image/* linguist-vendored
src/SDL_mixer/* linguist-vendored
src/SDL_ttf/* linguist-vendored
src/SDL-mobile/* linguist-vendored
51 changes: 42 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,32 @@ if(NOT SCREENSHOT_BUILD)
find_package(CURL REQUIRED)
find_package(GLEW REQUIRED)

# Luasocket
SET(LUASOCKET_FLAGS "-DBUILD_LUASOCKET -DLUASOCKET_INET_PTON")

include_directories(
src/luasocket/
${CURL_INCLUDE_DIR}
${GLEW_INCLUDE_DIRS}
${GTK3_INCLUDE_DIRS})

if(WIN32) # TODO: Fix Luasocket building on Windows
set(USE_LUASOCKET false)
else()
option(USE_LUASOCKET "Build with Luasocket support" TRUE)
endif()
else()
set(USE_LUASOCKET false)
endif()

# Luasocket
if(USE_LUASOCKET)
set(LUASOCKET_FLAGS "-DBUILD_LUASOCKET")

if(WIN32)
set(LUAROCKS_PLAT_SRC src/luasocket/wsocket.c)
else()
set(LUASOCKET_FLAGS "${LUASOCKET_FLAGS} -DLUASOCKET_INET_PTON")
set(LUAROCKS_PLAT_SRC
src/luasocket/usocket.c
src/luasocket/unix.c)
endif()
set(SRCS ${SRCS}
src/luasocket/auxiliar.c
src/luasocket/buffer.c
Expand All @@ -100,16 +117,30 @@ if(NOT SCREENSHOT_BUILD)
src/luasocket/select.c
src/luasocket/tcp.c
src/luasocket/timeout.c
src/luasocket/udp.c
src/luasocket/usocket.c
src/luasocket/unix.c)
src/luasocket/udp.c)
endif()

include_directories(src/tms/backends/${TMS_BACKEND}/)

set(SRCS ${SRCS}
src/tms/backends/${TMS_BACKEND}/main.cc)

if(WIN32)
set(WINRESOURCE_FILE "packaging/principia.rc")
set(WINMANIFEST_FILE "packaging/principia.manifest")

if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER "windres.exe")
endif()
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/winresource.o
COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_BINARY_DIR}
-i${WINRESOURCE_FILE}
-o ${CMAKE_CURRENT_BINARY_DIR}/winresource.o
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${WINRESOURCE_FILE} ${WINMANIFEST_FILE})
SET(SRCS ${SRCS} ${CMAKE_CURRENT_BINARY_DIR}/winresource.o)
endif()

add_executable(${PROJECT_NAME} ${SRCS})
target_link_libraries(
${PROJECT_NAME}
Expand All @@ -131,10 +162,12 @@ if(NOT SCREENSHOT_BUILD)
${GTK3_LIBRARIES})
endif()

set(COMMON_FLAGS "${LUASOCKET_FLAGS} -DGL_GLEXT_PROTOTYPES -DTMS_BACKEND_PC -DTMS_FAST_MATH -DLUA_COMPAT_MODULE -D__STDC_FORMAT_MACROS=1")
set(COMMON_FLAGS "${LUASOCKET_FLAGS} -DGL_GLEXT_PROTOTYPES -DTMS_BACKEND_PC -DTMS_FAST_MATH -DLUA_COMPAT_MODULE -D__STDC_FORMAT_MACROS=1 -DUNICODE")

if(WIN32)
set(COMMON_FLAGS "${COMMON_FLAGS} -DTMS_BACKEND_WINDOWS")
target_link_libraries(${PROJECT_NAME} ws2_32.lib version.lib shlwapi.lib winmm.lib)

set(COMMON_FLAGS "${COMMON_FLAGS} -DTMS_BACKEND_WINDOWS -D_WIN32_WINNT=0x0501 -mwindows -Dsrandom=srand -Drandom=rand")
else()
if(SCREENSHOT_BUILD)
set(COMMON_FLAGS "${COMMON_FLAGS} -DNO_UI -DTMS_BACKEND_LINUX_SS")
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ pacman -Syu
The terminal will then ask you to close it when done. Proceed with doing so, and then go to the start menu and run MSYS Mingw32 64-bit. It is important that you run the "MINGW64 64-Bit" version and not the "MSYS2 MSYS" or "MINGW64 32-Bit". Run the commands below to install the necessary dependencies.

```bash
pacman -S base-devel autotools mingw-w64-x86_64-{toolchain,curl,gtk3,gtksourceview4,libpng,libjpeg-turbo,freetype,SDL2,SDL2_image,SDL2_mixer,SDL2_ttf}
pacman -S base-devel mingw-w64-x86_64-{toolchain,cmake,ninja,curl,gtk3,glew,gtksourceview4,libpng,libjpeg-turbo,freetype,SDL2,SDL2_image,SDL2_mixer,SDL2_ttf}
```

Then navigate to the `build-windows` folder inside of where you cloned Principia, for example:
Then navigate to the folder where you cloned Principia, for example:

```bash
cd /c/Users/<username>/Documents/Principia/build-windows
cd /c/Users/<username>/Documents/Principia
```

And start the building process:

```bash
./autogen.sh
./configure
./go
mkdir build; cd build
cmake .. -G Ninja
ninja
```

Principia will launch if the compilation was successful. Keep in mind that the built executable can only be run inside of the MINGW terminal, to make a release build see below to build the installer:
When finished there will be a `principia.exe` file in the build folder. Keep in mind that the built executable can only be run inside of the MINGW terminal, to make a release build see below to build the installer:

#### Windows installer
The Windows installer uses NSIS, which must be installed first before building:
Expand All @@ -77,7 +77,7 @@ The Windows installer uses NSIS, which must be installed first before building:
pacman -S mingw-w64-x86_64-nsis
```

For making Windows release builds you would run the `make_release.sh` script, which will bundle necessary DLLs and other files to make the game run, and builds the installer.
For making Windows release builds you would run the `packaging/windows_release.sh` script, which will bundle necessary DLLs and other files to make the game run, and builds the installer.

### Linux
If you just want to play Principia on Linux, there are packages available for Arch-based and Debian-based distros as well as NixOS. See the [principia-web downloads page](https://principia-web.se/download) for more info.
Expand Down
11 changes: 4 additions & 7 deletions build-windows/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ GLOBAL_FLAGS := -DGL_GLEXT_PROTOTYPES \
-DUNICODE \
-DTMS_FAST_MATH \
-DTMS_BACKEND_WINDOWS \
-DTMS_BACKEND_PC
-DTMS_BACKEND_PC -DBUILD_LUASOCKET

TMS_PATH = ../src/tms
ROOT = ../

GLOBAL_FLAGS += -I../src/tms/backends/windows/ \
-I../src/src/ -I../src/ -I/usr/include/ \
-I../src/src/ -I../src/ \
-mwindows -Dsrandom=srand -Drandom=rand -Dmain=SDL_main \
-static-libgcc -static-libstdc++ \
-DGLEW_STATIC \
-I/mingw64/include/ \
-I/mingw64/include/freetype2 \
-I/mingw64/include/SDL2/ \
Expand All @@ -37,8 +36,7 @@ GLOBAL_FLAGS += -I../src/tms/backends/windows/ \
-I/mingw64/include/gdk-pixbuf-2.0 \
-I/mingw64/include/webp \
-I/mingw64/include/atk-1.0 \
-I../src/lua/ -I../src/include/ \
-DLIBDEFLATE_DLL
-I../src/lua/

principia_CFLAGS = ${GLOBAL_FLAGS} -std=gnu99

Expand All @@ -48,7 +46,7 @@ principia_LDADD = -L`pwd` -lopengl32 -lz \
-lmingw32 -lws2_32 -lwinmm -luuid -loleaut32 -limm32 -lversion \
-lole32 -luser32 \
-lgtk-3 -lgdk-3 -lz -lgdi32 -limm32 -lshell32 -lole32 -luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lhid -lwinspool -lcomctl32 -lcomdlg32 -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl \
-lcurl -lShlwapi -lpng -ljpeg -lfreetype -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
-lcurl -lShlwapi -lpng -ljpeg -lfreetype -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lglew32

principia_SOURCES = \
principia.rc \
Expand Down Expand Up @@ -131,7 +129,6 @@ principia.rc \
../src/tms/util/hash.c \
\
../src/tms/backends/windows/main.cc \
../src/GLEW/glew.c \
../src/tms/bindings/cpp/cpp.cc \
../src/tms/modules/3ds.c \
\
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!include "MUI2.nsh"

!define MUI_ICON "icon.ico"
!define MUI_ICON "..\packaging\icon.ico"
!define /ifndef VER_MAJOR 1
!define /ifndef VER_MINOR 5
!define /ifndef VER_BUILD 2
Expand Down Expand Up @@ -32,8 +32,8 @@ FunctionEnd
!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING

!define MUI_WELCOMEFINISHPAGE_BITMAP "installer\welcome.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "installer\unwelcome.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP "..\packaging\installer\welcome.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "..\packaging\installer\unwelcome.bmp"

!define MUI_FINISHPAGE_RUN "$INSTDIR/principia.exe"
!define MUI_FINISHPAGE_RUN_TEXT "Run Principia"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ cp /mingw64/$SCHEMAS_DIR/{gschema.dtd,gschemas.compiled} $SCHEMAS_DIR/

cd ..

./mingw-bundledlls release/principia.exe --copy
../packaging/mingw-bundledlls release/principia.exe --copy

cp ../packaging/principia_install.nsi .
cp -r ../packaging/installer/ .

makensis principia_install
Loading

0 comments on commit 9a33311

Please sign in to comment.