Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CMake, mostly for cross-compiling from non-Windows #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*.pdb
*.user
Debug/
Release/
Release/
build/
69 changes: 69 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Debug>>:/W3 /utf-8 /MP>
$<$<AND:$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>,$<CONFIG:Debug>>:-Wall -fpermissive>
)

# For release
target_compile_options(SCGL PRIVATE
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/W3 /utf-8 /Gw /Zc:threadSafeInit- /O2>
$<$<AND:$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:GNU>>,$<CONFIG:Release>>:-Wall -fpermissive -O3 -flto>
)

# Definitions
target_compile_definitions(SCGL PRIVATE
$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>,$<CONFIG:Debug>>:__FUNCSIG__=__PRETTY_FUNCTION__>
)

# Should come with MinGW
target_link_libraries(SCGL opengl32.lib)
4 changes: 2 additions & 2 deletions scgl/GLSupport.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <GL/GL.h>
#include <windows.h>
#include <GL/gl.h>

// ---------------------- Begin GLext subset ----------------------
#ifndef APIENTRY
Expand Down