Browse Source

Got SDL2 and ImGui working on Windows

The SDL build uses MSBuild and has some nasty hardcoded options. It's
all pretty hacky and fragile.
windows-imgui
Macoy Madson 9 months ago
parent
commit
5e9208b525
  1. 6
      src/ImGui.cake
  2. 61
      src/SDL.cake

6
src/ImGui.cake

@ -116,7 +116,11 @@
"ImGuiSDLOpenGL.cpp" "imgui_impl_opengl3.cpp"
"gl3w.c")
(add-library-dependency "GL" "dl") ;; dl for gl3w
(comptime-cond
('Unix
(add-library-dependency "GL" "dl")) ;; dl for gl3w
('Windows
(add-linker-options "opengl32.lib")))
(add-build-options "-DIMGUI_IMPL_OPENGL_LOADER_GL3W")

61
src/SDL.cake

@ -227,8 +227,30 @@ Note that you can also build SDL manually. This can be useful if you are porting
(defun-comptime build-sdl (manager (& ModuleManager) module (* Module) &return bool)
(comptime-cond
('Windows
(comptime-error "SDL build needs to be ported to Windows.
See http://wiki.libsdl.org/Installation"))
(when (and (fileExists "Dependencies/SDL/include/SDL.h")
(fileExists "Dependencies/SDL/VisualC/x64/Debug/SDL2.dll"))
(return true))
;; TODO: This shouldn't need a full path
(run-process-sequential-or
("C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/amd64/MSBuild.exe"
"Dependencies/SDL/VisualC/SDL.sln"
;; TODO: Debug vs release
;; TODO: Auto detect? Environment variables: WindowsSDKVersion
"/p:PlatformToolset=v141"
"/p:WindowsTargetPlatformVersion=10.0.17763.0")
(build-sdl-on-failure
"failed at SDL build step. This requires Microsoft Visual Studio to execute.\nYou may also
need to edit SDL.cake and update the PlatformToolset and SDK versions for your environment.")
(return false))
(unless (and (fileExists "Dependencies/SDL/include/SDL.h")
(fileExists "Dependencies/SDL/VisualC/x64/Debug/SDL2.dll"))
(build-sdl-on-failure
"error: SDL build sequence completed, but files are not where expected. Is there an issue
with the configuration?")
(return false)))
('Unix
;; Already built?
;; We could enhance this by checking for modifications, but that's pretty rare
@ -282,7 +304,8 @@ Note that you can also build SDL manually. This can be useful if you are porting
\n\tDependencies/SDL/buildSDLBuild/lib")
(return false)))
(true
(comptime-error "need to define platform, e.g. (comptime-define-symbol 'Unix)")))
(comptime-error "need to define platform, e.g. (comptime-define-symbol 'Unix), or your platform
has not been implemented yet. See http://wiki.libsdl.org/Installation to add your platform.")))
(Log "SDL: Successfully built\n")
(return true))
@ -293,13 +316,35 @@ Note that you can also build SDL manually. This can be useful if you are porting
;; For now, an easy way to build files which include SDL headers
(defmacro module-use-sdl-build-options ()
(tokenize-push output
(add-c-search-directory-module "Dependencies/SDL/buildSDLBuild/include/SDL2"))
(comptime-cond
('Windows
(add-c-search-directory-module "Dependencies/SDL/include"))
('Unix
(add-c-search-directory-module "Dependencies/SDL/buildSDLBuild/include/SDL2"))))
(return true))
(module-use-sdl-build-options)
;; TODO: Add debug version
(add-library-search-directory "Dependencies/SDL/buildSDLBuild/lib")
(add-library-dependency "SDL2")
;; TODO: Relative path is going to break for sure
(add-library-runtime-search-directory "Dependencies/SDL/buildSDLBuild/lib" ".")
(comptime-cond
('Windows
(add-library-search-directory "Dependencies/SDL/VisualC/x64/Debug")
(add-linker-options "SDL2main.lib" "SDL2.lib"))
;; (add-library-runtime-search-directory "Dependencies/SDL/VisualC/x64/Debug" "."))
('Unix
(add-library-search-directory "Dependencies/SDL/buildSDLBuild/lib")
(add-library-dependency "SDL2")
;; TODO: Relative path is going to break for sure
(add-library-runtime-search-directory "Dependencies/SDL/buildSDLBuild/lib" ".")))
(comptime-cond
('Windows ;; DLLs need to be in the same directory as the executable
(defun-comptime copy-sdl2-dlls (manager (& ModuleManager) module (* Module) &return bool)
(unless (fileIsMoreRecentlyModified "Dependencies/SDL/VisualC/x64/Debug/SDL2.dll" "SDL2.dll")
(return true))
(Log "SDL: Copying DLLs to working directory\n")
(unless (copyBinaryFileTo "Dependencies/SDL/VisualC/x64/Debug/SDL2.dll" "SDL2.dll")
(Log "SDL: Failed to copy SDL2 dlls to working directory\n")
(return false))
(return true))
(add-compile-time-hook-module pre-build copy-sdl2-dlls)))

Loading…
Cancel
Save