Skip to content

Commit

Permalink
Merge pull request #19 from chances/windows
Browse files Browse the repository at this point in the history
Fix compilation on Windows
  • Loading branch information
chances authored Feb 27, 2024
2 parents 615e14d + 7bc9fb2 commit ba3563d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ subprojects/wgpu: subprojects/wgpu.Makefile
ifneq ($(OS),Windows_NT)
file subprojects/wgpu/$(LIB_WGPU)
else
IF EXIST subprojects/wgpu/$(LIB_WGPU) ECHO subprojects/wgpu/$(LIB_WGPU) exists.
@IF EXIST subprojects/wgpu/$(LIB_WGPU) ECHO subprojects/wgpu/$(LIB_WGPU) exists.
endif
subprojects/wgpu/$(LIB_WGPU): subprojects/wgpu
wgpu: subprojects/wgpu/$(LIB_WGPU)
Expand Down
2 changes: 1 addition & 1 deletion examples/utils/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"libs-linux": [
"X11"
],
"libs-windows": ["glfw3", "gdi32"],
"libs-windows": ["glfw3", "gdi32", "opengl32", "msvcrt"],
"lflags-posix": ["$UTILS_PACKAGE_DIR/subprojects/glfw/src/libglfw3.a"],
"lflags-windows": ["/LIBPATH:$UTILS_PACKAGE_DIR/subprojects/glfw/src"]
}
2 changes: 1 addition & 1 deletion examples/utils/source/examples/window.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ abstract class Window {
);
version (Windows) {
import core.sys.windows.windows : GetModuleHandleA;
surface = Surface.fromWindowsHwnd(instance, GetModuleHandleA(null), glfwGetWin32Window(window));
surface = Surface.fromWindowsHwnd(this.gpu, GetModuleHandleA(null), glfwGetWin32Window(_window));
}
assert(surface.valid, "Could not create native surface");

Expand Down
47 changes: 37 additions & 10 deletions examples/utils/subprojects/glfw.Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
VERSION := 3.3.6
OS ?= $(shell uname -s)

.DEFAULT_GOAL := glfw/src/libglfw3.a
ifeq ($(OS),Windows_NT)
TARGET := glfw/src/glfw3.lib
else
TARGET := glfw/src/libglfw3.a
endif

glfw/src/libglfw3.a:
@echo "Downloading GLFW sources…"
@curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output /tmp/glfw-$(VERSION).zip
@echo "Unzipping GLFW sources…"
.DEFAULT_GOAL := $(TARGET)

ifeq ($(OS),Windows_NT)
ARCHIVE_ZIP := $(shell echo %USERPROFILE%/AppData/Local/Temp/glfw-$(VERSION).zip)
else
ARCHIVE_ZIP := /tmp/glfw-$(VERSION).zip
endif

DEFINES := GLFW_BUILD_TESTS=OFF GLFW_BUILD_EXAMPLES=OFF GLFW_BUILD_DOCS=OFF
ifeq ($(OS),Windows_NT)
DEFINES += USE_MSVC_RUNTIME_LIBRARY_DLL=ON
endif

$(TARGET):
@echo Downloading GLFW sources...
ifeq ($(OS),Windows_NT)
@if exist $(ARCHIVE_ZIP) echo Using cached download.
@if not exist $(ARCHIVE_ZIP) curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output $(ARCHIVE_ZIP)
else
@curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output $(ARCHIVE_ZIP)
endif
@echo Unzipping GLFW sources...
ifeq ($(OS),Windows_NT)
@if not exist glfw tar -xf $(ARCHIVE_ZIP)
@if not exist glfw rdmd --eval "std.file.rename(\"glfw-$(VERSION)\", \"glfw\");"
else
@unzip -q /tmp/glfw-$(VERSION).zip
@mv glfw-3.3.6 glfw
@echo "Building GLFW…"
@cd glfw && \
cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_DOCS=OFF && \
make
@mv glfw-$(VERSION) glfw
endif
@echo Building GLFW...
cmake -B glfw glfw -G "Unix Makefiles" $(patsubst %, -D%, $(DEFINES))
make -C glfw

0 comments on commit ba3563d

Please sign in to comment.