From 6111ff1cadb8908834881ec1baa12f3ebda132f2 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Sun, 29 Oct 2023 18:23:56 -0400 Subject: [PATCH 1/6] Fix case-sensitivity for cross-compile --- scgl/GLSupport.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scgl/GLSupport.h b/scgl/GLSupport.h index 7c4a72d..b661b23 100644 --- a/scgl/GLSupport.h +++ b/scgl/GLSupport.h @@ -1,7 +1,7 @@ #pragma once #define WIN32_LEAN_AND_MEAN -#include -#include +#include +#include // ---------------------- Begin GLext subset ---------------------- #ifndef APIENTRY From 519965906f085ea42b48c15c02432a90cfdd89e6 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Sun, 29 Oct 2023 18:24:37 -0400 Subject: [PATCH 2/6] Explicitly cast to void* to mitigate gcc error --- scgl/cGDriver_Viewport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scgl/cGDriver_Viewport.cpp b/scgl/cGDriver_Viewport.cpp index eda254d..ef8b98c 100644 --- a/scgl/cGDriver_Viewport.cpp +++ b/scgl/cGDriver_Viewport.cpp @@ -60,7 +60,7 @@ namespace nSCGL windowHeight = newMode.height; if (hwndProc == nullptr) { - hwndProc = DefWindowProcA; + hwndProc = (void *)DefWindowProcA; } DestroyOpenGLContext(); From 96b1bbae0fba741600ef0e8f49e0c7b747c5444d Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Sun, 29 Oct 2023 18:34:31 -0400 Subject: [PATCH 3/6] Crudely implement cross-compiling CMake build system Wrote this in an afternoon so I could cross-compile from Linux, because I felt like it. The resulting SCGL.dll is untested at the time of commit, but it will compile if you have mingw installed. At this time, you must explicitly specify the compiler if you're not using vscode (or codium) with the CMake extension, which detects toolchains automagically. Will look into CMake presets if I come back to this. --- CMakeLists.txt | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7e0b61a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +# Can only cross-compile on non-Windows for obvious reasons, so enforce. +if(CMAKE_HOST_UNIX) + set(CMAKE_SYSTEM_NAME "Windows") + set(CMAKE_SYSTEM_VERSION "10.0") + set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) + + # Use host binaries but target libraries and headers. + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif() + +set(CMAKE_SYSTEM_PROCESSOR "x86") + +cmake_minimum_required(VERSION 3.22) +project(SCGL LANGUAGES C CXX) + +if(NOT CMAKE_HOST_WIN32 AND NOT CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "SCGL targets SimCity 4, a 32-bit Windows application, and must be cross-compiled.") +endif() + +if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + message(FATAL_ERROR "You're using a compiler that generates 64-bit code. SCGL must be 32-bit.") +endif() + +add_library(SCGL SHARED + scgl/cGDriver.cpp + scgl/cGDriversCOMDirector.cpp + scgl/cGDriver_Info.cpp + scgl/cGDriver_Init.cpp + scgl/cGDriver_Textures.cpp + scgl/cGDriver_Unknown.cpp + scgl/cGDriver_Viewport.cpp + scgl/ext/cGDriver_BufferRegions.cpp + scgl/ext/cGDriver_Lighting.cpp + scgl/ext/cGDriver_Snapshot.cpp + scgl/ext/cGDriver_VertexBuffers.cpp + scgl/GLStateManager.cpp + scgl/GLSupport.cpp + scgl/GLTextureUnit.cpp + scgl/VertexFormatUtils.cpp + vendor/framework/src/cRZCOMDllDirector.cpp + vendor/framework/src/cRZRefCount.cpp +) + +set_target_properties(SCGL PROPERTIES PREFIX "") + +target_include_directories(SCGL PRIVATE "${CMAKE_SOURCE_DIR}/vendor/framework/include;${CMAKE_SOURCE_DIR}/scgl;${CMAKE_SOURCE_DIR}/scgl/ext") + +# Flags for debug builds. +target_compile_options(SCGL PRIVATE + $<$,$>:/W3 /utf-8 /MP> + $<$,$>,$>:-Wall> +) + +# For release +target_compile_options(SCGL PRIVATE + $<$,$>:/W3 /utf-8 /Gw /Zc:threadSafeInit- /O2> + $<$,$>,$>:-Wall -O3 -flto> +) + +# Definitions +target_compile_definitions(SCGL PRIVATE + $<$:WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;scgl_EXPORTS;_WINDOWS;_USRDLL;__FUNCSIG__=__PRETTY_FUNCTION__> + $<$:WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;scgl_EXPORTS;_WINDOWS;_USRDLL;__FUNCSIG__=__PRETTY_FUNCTION__> +) + +# Should come with MinGW +target_link_libraries(SCGL opengl32.lib) From 9643824f1b75c3334850f49d30745dd2617e65c2 Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Mon, 30 Oct 2023 17:40:11 -0400 Subject: [PATCH 4/6] Revert void* cast and add -fpermissive, to minimize code changes --- CMakeLists.txt | 4 ++-- scgl/cGDriver_Viewport.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e0b61a..fbfccdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,13 +51,13 @@ target_include_directories(SCGL PRIVATE "${CMAKE_SOURCE_DIR}/vendor/framework/in # Flags for debug builds. target_compile_options(SCGL PRIVATE $<$,$>:/W3 /utf-8 /MP> - $<$,$>,$>:-Wall> + $<$,$>,$>:-Wall -fpermissive> ) # For release target_compile_options(SCGL PRIVATE $<$,$>:/W3 /utf-8 /Gw /Zc:threadSafeInit- /O2> - $<$,$>,$>:-Wall -O3 -flto> + $<$,$>,$>:-Wall -fpermissive -O3 -flto> ) # Definitions diff --git a/scgl/cGDriver_Viewport.cpp b/scgl/cGDriver_Viewport.cpp index ef8b98c..eda254d 100644 --- a/scgl/cGDriver_Viewport.cpp +++ b/scgl/cGDriver_Viewport.cpp @@ -60,7 +60,7 @@ namespace nSCGL windowHeight = newMode.height; if (hwndProc == nullptr) { - hwndProc = (void *)DefWindowProcA; + hwndProc = DefWindowProcA; } DestroyOpenGLContext(); From c776e84be915aa048a18218316be38eda4da045e Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Mon, 30 Oct 2023 17:40:54 -0400 Subject: [PATCH 5/6] Update .gitignore to ignore typical cmake build directory --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index be467ea..4aa8d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ *.pdb *.user Debug/ -Release/ \ No newline at end of file +Release/ +build/ \ No newline at end of file From 17616981a4c7add85de5b2aa6d3c60294e23c85f Mon Sep 17 00:00:00 2001 From: Cloudwalk Date: Mon, 30 Oct 2023 17:44:03 -0400 Subject: [PATCH 6/6] Fix generator expression spaghetti by only mapping __FUNCSIG__ in Debug builds and with GCC/Clang --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbfccdb..9cb62be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,8 +62,7 @@ target_compile_options(SCGL PRIVATE # Definitions target_compile_definitions(SCGL PRIVATE - $<$:WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;scgl_EXPORTS;_WINDOWS;_USRDLL;__FUNCSIG__=__PRETTY_FUNCTION__> - $<$:WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;scgl_EXPORTS;_WINDOWS;_USRDLL;__FUNCSIG__=__PRETTY_FUNCTION__> + $<$,$>,$>:__FUNCSIG__=__PRETTY_FUNCTION__> ) # Should come with MinGW