2024-02-24 22:47:20 -05:00
|
|
|
# Minimum version of CMake required
|
|
|
|
|
cmake_minimum_required(VERSION 3.14)
|
|
|
|
|
|
|
|
|
|
# Project name
|
|
|
|
|
project(McRogueFace)
|
|
|
|
|
|
|
|
|
|
# Specify the C++ standard
|
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
|
|
2026-01-30 23:32:59 -05:00
|
|
|
# Headless build option (no SFML, no graphics - for server/testing/Emscripten prep)
|
|
|
|
|
option(MCRF_HEADLESS "Build without graphics dependencies (SFML, ImGui)" OFF)
|
|
|
|
|
|
2026-01-31 11:13:15 -05:00
|
|
|
# SDL2 backend option (SDL2 + OpenGL ES 2 - for Emscripten/WebGL, Android, cross-platform)
|
|
|
|
|
option(MCRF_SDL2 "Build with SDL2+OpenGL ES 2 backend instead of SFML" OFF)
|
|
|
|
|
|
2026-02-01 21:17:29 -05:00
|
|
|
# Playground mode - minimal scripts for web playground (REPL-focused)
|
|
|
|
|
option(MCRF_PLAYGROUND "Build with minimal playground scripts instead of full game" OFF)
|
|
|
|
|
|
2026-01-31 11:13:15 -05:00
|
|
|
# Emscripten builds: use SDL2 if specified, otherwise fall back to headless
|
2026-01-31 00:23:28 -05:00
|
|
|
if(EMSCRIPTEN)
|
2026-01-31 11:13:15 -05:00
|
|
|
if(MCRF_SDL2)
|
|
|
|
|
message(STATUS "Emscripten detected - using SDL2 backend")
|
|
|
|
|
set(MCRF_HEADLESS OFF)
|
|
|
|
|
else()
|
|
|
|
|
set(MCRF_HEADLESS ON)
|
|
|
|
|
message(STATUS "Emscripten detected - forcing HEADLESS mode (use -DMCRF_SDL2=ON for graphics)")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(MCRF_SDL2)
|
|
|
|
|
message(STATUS "Building with SDL2 backend - SDL2+OpenGL ES 2")
|
2026-01-31 00:23:28 -05:00
|
|
|
endif()
|
|
|
|
|
|
2026-02-01 21:17:29 -05:00
|
|
|
if(MCRF_PLAYGROUND)
|
|
|
|
|
message(STATUS "Building in PLAYGROUND mode - minimal scripts for web REPL")
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-30 23:32:59 -05:00
|
|
|
if(MCRF_HEADLESS)
|
|
|
|
|
message(STATUS "Building in HEADLESS mode - no SFML/ImGui dependencies")
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-08 10:41:24 -05:00
|
|
|
# Detect cross-compilation for Windows (MinGW)
|
|
|
|
|
if(CMAKE_CROSSCOMPILING AND WIN32)
|
|
|
|
|
set(MCRF_CROSS_WINDOWS TRUE)
|
|
|
|
|
message(STATUS "Cross-compiling for Windows using MinGW")
|
|
|
|
|
endif()
|
|
|
|
|
|
2024-02-24 22:47:20 -05:00
|
|
|
# Add include directories
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
2026-01-11 20:44:46 -05:00
|
|
|
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/deps/libtcod)
|
2026-02-04 13:33:14 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src/3d)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src/platform)
|
2026-02-06 21:43:03 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src/tiled)
|
2026-02-07 11:30:32 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/src/ldtk)
|
2026-02-06 21:43:03 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/modules/RapidXML)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/modules/json/single_include)
|
2024-02-24 22:47:20 -05:00
|
|
|
|
2026-01-31 00:23:28 -05:00
|
|
|
# Python includes: use different paths for Windows vs Linux vs Emscripten
|
|
|
|
|
if(EMSCRIPTEN)
|
|
|
|
|
# Emscripten build: use Python headers compiled for wasm32-emscripten
|
|
|
|
|
# The pyconfig.h from cross-build has correct LONG_BIT and other settings
|
|
|
|
|
set(PYTHON_WASM_BUILD "${CMAKE_SOURCE_DIR}/deps/cpython/cross-build/wasm32-emscripten/build/python")
|
2026-01-31 11:13:15 -05:00
|
|
|
# Force-include wasm pyconfig.h BEFORE anything else to set correct platform defines
|
2026-01-31 00:23:28 -05:00
|
|
|
add_compile_options(-include ${PYTHON_WASM_BUILD}/pyconfig.h)
|
2026-01-31 11:13:15 -05:00
|
|
|
# Override LONG_BIT - Emscripten's limits.h incorrectly defines it as 64 for wasm32
|
|
|
|
|
add_compile_definitions(LONG_BIT=32)
|
|
|
|
|
# Include wasm build directory FIRST so its pyconfig.h is found by #include "pyconfig.h"
|
|
|
|
|
include_directories(BEFORE ${PYTHON_WASM_BUILD})
|
2026-01-31 00:23:28 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/Include)
|
|
|
|
|
message(STATUS "Using Emscripten Python from: ${PYTHON_WASM_BUILD}")
|
|
|
|
|
elseif(MCRF_CROSS_WINDOWS)
|
2026-01-08 10:41:24 -05:00
|
|
|
# Windows cross-compilation: use cpython headers with PC/pyconfig.h
|
|
|
|
|
# Problem: Python.h uses #include "pyconfig.h" which finds Include/pyconfig.h (Linux) first
|
|
|
|
|
# Solution: Use -include to force Windows pyconfig.h to be included first
|
|
|
|
|
# This defines MS_WINDOWS before Python.h is processed, ensuring correct struct layouts
|
|
|
|
|
add_compile_options(-include ${CMAKE_SOURCE_DIR}/deps/cpython/PC/pyconfig.h)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/Include)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython/PC) # For other Windows-specific headers
|
|
|
|
|
# Also include SFML and libtcod Windows headers
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/include)
|
2026-01-11 20:44:46 -05:00
|
|
|
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/include)
|
2026-01-08 10:41:24 -05:00
|
|
|
else()
|
|
|
|
|
# Native builds (Linux/Windows): use existing Python setup
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/cpython)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/Python)
|
|
|
|
|
endif()
|
2024-02-24 22:47:20 -05:00
|
|
|
|
2026-01-31 11:13:15 -05:00
|
|
|
# ImGui and ImGui-SFML include directories (not needed in headless or SDL2 mode)
|
|
|
|
|
# SDL2 builds will use ImGui with SDL2 backend later; for now, no ImGui
|
|
|
|
|
if(NOT MCRF_HEADLESS AND NOT MCRF_SDL2)
|
2026-01-30 23:32:59 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/modules/imgui)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/modules/imgui-sfml)
|
|
|
|
|
|
|
|
|
|
# ImGui source files
|
|
|
|
|
set(IMGUI_SOURCES
|
|
|
|
|
${CMAKE_SOURCE_DIR}/modules/imgui/imgui.cpp
|
|
|
|
|
${CMAKE_SOURCE_DIR}/modules/imgui/imgui_draw.cpp
|
|
|
|
|
${CMAKE_SOURCE_DIR}/modules/imgui/imgui_tables.cpp
|
|
|
|
|
${CMAKE_SOURCE_DIR}/modules/imgui/imgui_widgets.cpp
|
|
|
|
|
${CMAKE_SOURCE_DIR}/modules/imgui-sfml/imgui-SFML.cpp
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2025-11-26 20:03:58 -05:00
|
|
|
|
2024-02-24 22:47:20 -05:00
|
|
|
# Collect all the source files
|
|
|
|
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
|
|
|
|
|
2026-01-31 11:13:15 -05:00
|
|
|
# Add ImGui sources to the build (only if using SFML)
|
|
|
|
|
if(NOT MCRF_HEADLESS AND NOT MCRF_SDL2)
|
2026-01-30 23:32:59 -05:00
|
|
|
list(APPEND SOURCES ${IMGUI_SOURCES})
|
2026-02-04 13:33:14 -05:00
|
|
|
# Add GLAD for OpenGL function loading (needed for 3D rendering on SFML)
|
|
|
|
|
list(APPEND SOURCES "${CMAKE_SOURCE_DIR}/src/3d/glad.c")
|
2026-01-30 23:32:59 -05:00
|
|
|
endif()
|
2025-11-26 20:03:58 -05:00
|
|
|
|
2026-01-30 23:32:59 -05:00
|
|
|
# Find OpenGL (required by ImGui-SFML) - not needed in headless mode
|
2026-01-31 11:13:15 -05:00
|
|
|
# SDL2 builds handle OpenGL ES 2 differently (via SDL2 or Emscripten)
|
|
|
|
|
if(NOT MCRF_HEADLESS AND NOT MCRF_SDL2)
|
2026-01-30 23:32:59 -05:00
|
|
|
if(MCRF_CROSS_WINDOWS)
|
|
|
|
|
# For cross-compilation, OpenGL is provided by MinGW
|
|
|
|
|
set(OPENGL_LIBRARIES opengl32)
|
|
|
|
|
else()
|
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
|
set(OPENGL_LIBRARIES OpenGL::GL)
|
|
|
|
|
endif()
|
2026-01-08 10:41:24 -05:00
|
|
|
endif()
|
2025-11-26 20:03:58 -05:00
|
|
|
|
2024-02-24 22:47:20 -05:00
|
|
|
# Create a list of libraries to link against
|
2026-01-31 00:23:28 -05:00
|
|
|
if(EMSCRIPTEN)
|
2026-01-31 00:34:11 -05:00
|
|
|
# Emscripten build: link against WASM-compiled Python and libtcod
|
2026-01-31 00:23:28 -05:00
|
|
|
set(PYTHON_WASM_BUILD "${CMAKE_SOURCE_DIR}/deps/cpython/cross-build/wasm32-emscripten/build/python")
|
2026-01-31 00:34:11 -05:00
|
|
|
set(PYTHON_WASM_PREFIX "${CMAKE_SOURCE_DIR}/deps/cpython/cross-build/wasm32-emscripten/prefix")
|
|
|
|
|
set(LIBTCOD_WASM_BUILD "${CMAKE_SOURCE_DIR}/modules/libtcod-headless/build-emscripten")
|
|
|
|
|
# Collect HACL crypto object files (not included in libpython3.14.a)
|
|
|
|
|
file(GLOB PYTHON_HACL_OBJECTS "${PYTHON_WASM_BUILD}/Modules/_hacl/*.o")
|
2026-01-31 00:23:28 -05:00
|
|
|
set(LINK_LIBS
|
|
|
|
|
${PYTHON_WASM_BUILD}/libpython3.14.a
|
2026-01-31 00:34:11 -05:00
|
|
|
${PYTHON_HACL_OBJECTS}
|
|
|
|
|
${PYTHON_WASM_BUILD}/Modules/expat/libexpat.a
|
|
|
|
|
${PYTHON_WASM_PREFIX}/lib/libmpdec.a
|
|
|
|
|
${PYTHON_WASM_PREFIX}/lib/libffi.a
|
|
|
|
|
${LIBTCOD_WASM_BUILD}/libtcod.a
|
|
|
|
|
${LIBTCOD_WASM_BUILD}/_deps/lodepng-c-build/liblodepng-c.a
|
|
|
|
|
${LIBTCOD_WASM_BUILD}/_deps/utf8proc-build/libutf8proc.a)
|
2026-01-31 00:23:28 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux) # Use Linux platform stubs for now
|
2026-01-31 11:13:15 -05:00
|
|
|
# For SDL2 builds, add stb headers for image/font loading
|
|
|
|
|
if(MCRF_SDL2)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/stb)
|
|
|
|
|
endif()
|
2026-01-31 00:23:28 -05:00
|
|
|
message(STATUS "Linking Emscripten Python: ${PYTHON_WASM_BUILD}/libpython3.14.a")
|
2026-01-31 00:34:11 -05:00
|
|
|
message(STATUS "Linking Emscripten libtcod: ${LIBTCOD_WASM_BUILD}/libtcod.a")
|
2026-01-31 11:13:15 -05:00
|
|
|
elseif(MCRF_SDL2)
|
|
|
|
|
# SDL2 build (non-Emscripten): link against SDL2 and system libraries
|
|
|
|
|
# Note: For desktop SDL2 builds in the future
|
|
|
|
|
find_package(SDL2 REQUIRED)
|
|
|
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
SDL2::SDL2
|
|
|
|
|
OpenGL::GL
|
|
|
|
|
tcod
|
|
|
|
|
python3.14
|
|
|
|
|
m dl util pthread)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/stb) # stb_image.h, stb_truetype.h
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
|
|
|
|
message(STATUS "Building with SDL2 backend (desktop)")
|
2026-01-31 00:23:28 -05:00
|
|
|
elseif(MCRF_HEADLESS)
|
2026-01-30 23:32:59 -05:00
|
|
|
# Headless build: no SFML, no OpenGL
|
|
|
|
|
if(WIN32 OR MCRF_CROSS_WINDOWS)
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
libtcod
|
|
|
|
|
python314)
|
|
|
|
|
if(MCRF_CROSS_WINDOWS)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/lib)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows)
|
|
|
|
|
else()
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
# Unix/Linux headless build
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
tcod
|
|
|
|
|
python3.14
|
|
|
|
|
m dl util pthread)
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
|
|
|
|
endif()
|
|
|
|
|
elseif(MCRF_CROSS_WINDOWS)
|
2026-01-08 10:41:24 -05:00
|
|
|
# MinGW cross-compilation: use full library names
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
sfml-graphics
|
|
|
|
|
sfml-window
|
|
|
|
|
sfml-system
|
|
|
|
|
sfml-audio
|
|
|
|
|
libtcod
|
|
|
|
|
python314
|
|
|
|
|
${OPENGL_LIBRARIES})
|
|
|
|
|
|
|
|
|
|
# Add Windows system libraries needed by SFML and MinGW
|
|
|
|
|
list(APPEND LINK_LIBS
|
|
|
|
|
winmm # Windows multimedia (for audio)
|
|
|
|
|
gdi32 # Graphics Device Interface
|
|
|
|
|
ws2_32 # Winsock (networking, used by some deps)
|
|
|
|
|
ole32 # OLE support
|
|
|
|
|
oleaut32 # OLE automation
|
|
|
|
|
uuid # UUID library
|
|
|
|
|
comdlg32 # Common dialogs
|
|
|
|
|
imm32 # Input Method Manager
|
|
|
|
|
version # Version info
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
|
|
|
|
|
|
|
|
|
# Link directories for cross-compiled Windows libs
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows/sfml/lib)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/lib)
|
|
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib_windows)
|
|
|
|
|
elseif(WIN32)
|
|
|
|
|
# Native Windows build (MSVC)
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
sfml-graphics
|
|
|
|
|
sfml-window
|
|
|
|
|
sfml-system
|
|
|
|
|
sfml-audio
|
|
|
|
|
tcod
|
|
|
|
|
python314
|
|
|
|
|
${OPENGL_LIBRARIES})
|
2024-02-25 15:38:38 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/windows)
|
2026-01-08 10:41:24 -05:00
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
2024-02-25 15:38:38 -05:00
|
|
|
else()
|
2026-01-08 10:41:24 -05:00
|
|
|
# Unix/Linux build
|
|
|
|
|
set(LINK_LIBS
|
|
|
|
|
sfml-graphics
|
|
|
|
|
sfml-window
|
|
|
|
|
sfml-system
|
|
|
|
|
sfml-audio
|
|
|
|
|
tcod
|
|
|
|
|
python3.14
|
|
|
|
|
m dl util pthread
|
|
|
|
|
${OPENGL_LIBRARIES})
|
2024-02-25 15:38:38 -05:00
|
|
|
include_directories(${CMAKE_SOURCE_DIR}/deps/platform/linux)
|
2026-01-08 10:41:24 -05:00
|
|
|
link_directories(${CMAKE_SOURCE_DIR}/__lib)
|
2024-02-24 22:47:20 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Define the executable target before linking libraries
|
|
|
|
|
add_executable(mcrogueface ${SOURCES})
|
|
|
|
|
|
2025-11-26 11:22:48 -05:00
|
|
|
# Define NO_SDL for libtcod-headless headers (excludes SDL-dependent code)
|
2026-01-31 11:13:15 -05:00
|
|
|
# We ALWAYS need this because libtcod headers expect SDL3, not SDL2
|
|
|
|
|
# Our SDL2 backend is separate from libtcod's SDL3 renderer
|
2025-11-26 11:22:48 -05:00
|
|
|
target_compile_definitions(mcrogueface PRIVATE NO_SDL)
|
|
|
|
|
|
2026-01-30 23:32:59 -05:00
|
|
|
# Define MCRF_HEADLESS for headless builds (excludes SFML/ImGui code)
|
|
|
|
|
if(MCRF_HEADLESS)
|
|
|
|
|
target_compile_definitions(mcrogueface PRIVATE MCRF_HEADLESS)
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-31 11:13:15 -05:00
|
|
|
# Define MCRF_SDL2 for SDL2 builds (uses SDL2+OpenGL ES 2 instead of SFML)
|
|
|
|
|
if(MCRF_SDL2)
|
|
|
|
|
target_compile_definitions(mcrogueface PRIVATE MCRF_SDL2)
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-31 00:34:11 -05:00
|
|
|
# Emscripten-specific link options (use ports for zlib, bzip2, sqlite3)
|
|
|
|
|
if(EMSCRIPTEN)
|
2026-01-31 11:13:15 -05:00
|
|
|
# Base Emscripten options
|
|
|
|
|
set(EMSCRIPTEN_LINK_OPTIONS
|
2026-01-31 00:34:11 -05:00
|
|
|
-sUSE_ZLIB=1
|
|
|
|
|
-sUSE_BZIP2=1
|
|
|
|
|
-sUSE_SQLITE3=1
|
2026-01-31 05:15:11 -05:00
|
|
|
-sALLOW_MEMORY_GROWTH=1
|
|
|
|
|
-sSTACK_SIZE=2097152
|
2026-01-31 15:31:18 -05:00
|
|
|
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap,FS
|
|
|
|
|
-sEXPORTED_FUNCTIONS=_main,_run_python_string,_run_python_string_with_output,_reset_python_environment
|
2026-01-31 05:15:11 -05:00
|
|
|
-sASSERTIONS=2
|
|
|
|
|
-sSTACK_OVERFLOW_CHECK=2
|
|
|
|
|
-fexceptions
|
|
|
|
|
-sNO_DISABLE_EXCEPTION_CATCHING
|
2026-01-31 11:13:15 -05:00
|
|
|
# Disable features that require dynamic linking support
|
|
|
|
|
-sERROR_ON_UNDEFINED_SYMBOLS=0
|
|
|
|
|
-sALLOW_UNIMPLEMENTED_SYSCALLS=1
|
2026-01-31 05:15:11 -05:00
|
|
|
# Preload Python stdlib into virtual filesystem at /lib/python3.14
|
|
|
|
|
--preload-file=${CMAKE_SOURCE_DIR}/wasm_stdlib/lib@/lib
|
2026-02-01 21:17:29 -05:00
|
|
|
# Preload game scripts into /scripts (use playground scripts if MCRF_PLAYGROUND is set)
|
|
|
|
|
--preload-file=${CMAKE_SOURCE_DIR}/src/$<IF:$<BOOL:${MCRF_PLAYGROUND}>,scripts_playground,scripts>@/scripts
|
2026-01-31 05:15:11 -05:00
|
|
|
# Preload assets
|
|
|
|
|
--preload-file=${CMAKE_SOURCE_DIR}/assets@/assets
|
2026-01-31 14:36:22 -05:00
|
|
|
# Use custom HTML shell for crisp pixel rendering
|
|
|
|
|
--shell-file=${CMAKE_SOURCE_DIR}/src/shell.html
|
|
|
|
|
# Pre-JS to fix browser zoom causing undefined values in events
|
|
|
|
|
--pre-js=${CMAKE_SOURCE_DIR}/src/emscripten_pre.js
|
2026-01-31 05:15:11 -05:00
|
|
|
)
|
2026-01-31 11:13:15 -05:00
|
|
|
|
|
|
|
|
# Add SDL2 options if using SDL2 backend
|
|
|
|
|
if(MCRF_SDL2)
|
|
|
|
|
list(APPEND EMSCRIPTEN_LINK_OPTIONS
|
|
|
|
|
-sUSE_SDL=2
|
|
|
|
|
-sFULL_ES2=1
|
|
|
|
|
-sMIN_WEBGL_VERSION=2
|
|
|
|
|
-sMAX_WEBGL_VERSION=2
|
2026-01-31 16:45:10 -05:00
|
|
|
-sUSE_FREETYPE=1
|
2026-01-31 11:13:15 -05:00
|
|
|
)
|
2026-01-31 16:45:10 -05:00
|
|
|
# SDL2 and FreeType flags are also needed at compile time for headers
|
2026-01-31 11:13:15 -05:00
|
|
|
target_compile_options(mcrogueface PRIVATE
|
|
|
|
|
-sUSE_SDL=2
|
2026-01-31 16:45:10 -05:00
|
|
|
-sUSE_FREETYPE=1
|
2026-01-31 11:13:15 -05:00
|
|
|
)
|
2026-01-31 16:45:10 -05:00
|
|
|
message(STATUS "Emscripten SDL2 options enabled: -sUSE_SDL=2 -sFULL_ES2=1 -sUSE_FREETYPE=1")
|
2026-01-31 11:13:15 -05:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
target_link_options(mcrogueface PRIVATE ${EMSCRIPTEN_LINK_OPTIONS})
|
|
|
|
|
|
2026-01-31 14:36:22 -05:00
|
|
|
# Output as HTML to use the shell file
|
|
|
|
|
set_target_properties(mcrogueface PROPERTIES SUFFIX ".html")
|
|
|
|
|
|
2026-01-31 05:15:11 -05:00
|
|
|
# Set Python home for the embedded interpreter
|
|
|
|
|
target_compile_definitions(mcrogueface PRIVATE
|
|
|
|
|
MCRF_WASM_PYTHON_HOME="/lib/python3.14"
|
2026-01-31 00:34:11 -05:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-08 10:41:24 -05:00
|
|
|
# On Windows, define Py_ENABLE_SHARED for proper Python DLL imports
|
|
|
|
|
# Py_PYCONFIG_H prevents Include/pyconfig.h (Linux config) from being included
|
|
|
|
|
# (PC/pyconfig.h already defines HAVE_DECLSPEC_DLL and MS_WINDOWS)
|
|
|
|
|
if(WIN32 OR MCRF_CROSS_WINDOWS)
|
|
|
|
|
target_compile_definitions(mcrogueface PRIVATE Py_ENABLE_SHARED Py_PYCONFIG_H)
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-01-08 21:16:27 -05:00
|
|
|
# On Windows, set subsystem to WINDOWS to hide console (release builds only)
|
|
|
|
|
# Use -DMCRF_WINDOWS_CONSOLE=ON for debug builds with console output
|
|
|
|
|
option(MCRF_WINDOWS_CONSOLE "Keep console window visible for debugging" OFF)
|
|
|
|
|
|
2026-01-08 10:41:24 -05:00
|
|
|
if(WIN32 AND NOT MCRF_CROSS_WINDOWS)
|
|
|
|
|
# MSVC-specific flags
|
2026-01-08 21:16:27 -05:00
|
|
|
if(NOT MCRF_WINDOWS_CONSOLE)
|
|
|
|
|
set_target_properties(mcrogueface PROPERTIES
|
|
|
|
|
WIN32_EXECUTABLE TRUE
|
|
|
|
|
LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
|
|
|
|
endif()
|
2026-01-08 10:41:24 -05:00
|
|
|
elseif(MCRF_CROSS_WINDOWS)
|
2026-01-08 21:16:27 -05:00
|
|
|
# MinGW cross-compilation
|
|
|
|
|
if(NOT MCRF_WINDOWS_CONSOLE)
|
|
|
|
|
# Release: use -mwindows to hide console
|
|
|
|
|
set_target_properties(mcrogueface PROPERTIES
|
|
|
|
|
WIN32_EXECUTABLE TRUE
|
|
|
|
|
LINK_FLAGS "-mwindows")
|
|
|
|
|
else()
|
|
|
|
|
# Debug: keep console for stdout/stderr output
|
|
|
|
|
message(STATUS "Windows console enabled for debugging")
|
|
|
|
|
endif()
|
2025-07-10 17:01:03 -04:00
|
|
|
endif()
|
|
|
|
|
|
2024-02-24 22:47:20 -05:00
|
|
|
# Now the linker will find the libraries in the specified directory
|
|
|
|
|
target_link_libraries(mcrogueface ${LINK_LIBS})
|
|
|
|
|
|
|
|
|
|
# Copy assets to build directory post-build
|
|
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
|
${CMAKE_SOURCE_DIR}/assets $<TARGET_FILE_DIR:mcrogueface>/assets)
|
|
|
|
|
|
|
|
|
|
# Copy Python scripts to build directory post-build
|
|
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
|
${CMAKE_SOURCE_DIR}/src/scripts $<TARGET_FILE_DIR:mcrogueface>/scripts)
|
|
|
|
|
|
|
|
|
|
# Copy Python standard library to build directory
|
|
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
Iterators, other Python C API improvements
closes #72
ref #69 - this resolves the "UICollection" (not "UIEntityCollection", perhaps renamed since the issue opened) and "UIEntityCollection" portion. The Grid point based iterators were not updated.
**RPATH updates**
Will this RPATH setting allow McRogueFace to execute using its included "lib" subdirectory after being unzipped on a new computer?
The change from "./lib" to "$ORIGIN/./lib" improves portability. The $ORIGIN token is a special Linux/Unix convention that refers to the directory containing the executable itself. This makes the path relative to the executable's location rather than the current working directory, which means McRogueFace will correctly find its libraries in the lib subdirectory regardless of where it's run from after being unzipped on a new computer.
**New standard object initialization**
PyColor, PyVector
- Fixed all 15 PyTypeObject definitions to use proper designated initializer syntax
- Replaced PyType_GenericAlloc usage in PyColor.cpp and PyVector.cpp
- Updated PyObject_New usage in UIEntity.cpp
- All object creation now uses module-based type lookups instead of static references
- Created centralized utilities in PyObjectUtils.h
**RAII Wrappers**
automatic reference counting via C++ object lifecycle
- Created PyRAII.h with PyObjectRef and PyTypeRef classes
- These provide automatic reference counting management
- Updated PyColor::from_arg() to demonstrate RAII usage
- Prevents memory leaks and reference counting errors
**Python object base in type defs:**
`.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0}`
PyColor, PyTexture, PyVector, UICaption, UICollection, UIEntity, UIFrame, UIGrid
**convertDrawableToPython**
replace crazy macro to detect the correct Python type of a UIDrawable instance
- Removed the problematic macro from UIDrawable.h
- Created template-based functions in PyObjectUtils.h
- Updated UICollection.cpp to use local helper function
- The new approach is cleaner, more debuggable, and avoids static type references
**Iterator fixes**
tp_iter on UICollection, UIGrid, UIGridPoint, UISprite
UIGrid logic improved, standard
**List vs Vector usage analysis**
there are different use cases that weren't standardized:
- UICollection (for Frame children) uses std::vector<std::shared_ptr<UIDrawable>>
- UIEntityCollection (for Grid entities) uses std::list<std::shared_ptr<UIEntity>>
The rationale is currently connected to frequency of expected changes.
* A "UICollection" is likely either all visible or not; it's also likely to be created once and have a static set of contents. They should be contiguous in memory in hopes that this helps rendering speed.
* A "UIEntityCollection" is expected to be rendered as a subset within the visible rectangle of the UIGrid. Scrolling the grid or gameplay logic is likely to frequently create and destroy entities. In general I expect Entity collections to have a much higher common size than UICollections. For these reasons I've made them Lists in hopes that they never have to be reallocated or moved during a frame.
2025-05-31 08:58:52 -04:00
|
|
|
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>/lib)
|
2024-02-24 22:47:20 -05:00
|
|
|
|
2025-07-10 17:01:03 -04:00
|
|
|
# On Windows, copy DLLs to executable directory
|
2026-01-08 10:41:24 -05:00
|
|
|
if(MCRF_CROSS_WINDOWS)
|
|
|
|
|
# Cross-compilation: copy DLLs from __lib_windows
|
|
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/sfml/bin $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/libtcod/bin $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/python314.dll $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/python3.dll $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/vcruntime140.dll $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/vcruntime140_1.dll $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
/usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied Windows DLLs to executable directory")
|
|
|
|
|
|
|
|
|
|
# Copy Python standard library zip
|
|
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib_windows/python314.zip $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied Python stdlib")
|
|
|
|
|
elseif(WIN32)
|
|
|
|
|
# Native Windows build: copy DLLs from __lib
|
2025-07-10 17:01:03 -04:00
|
|
|
add_custom_command(TARGET mcrogueface POST_BUILD
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
|
${CMAKE_SOURCE_DIR}/__lib $<TARGET_FILE_DIR:mcrogueface>
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Copied DLLs to executable directory")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# rpath for including shared libraries (Linux/Unix only)
|
|
|
|
|
if(NOT WIN32)
|
|
|
|
|
set_target_properties(mcrogueface PROPERTIES
|
|
|
|
|
INSTALL_RPATH "$ORIGIN/./lib")
|
|
|
|
|
endif()
|
2024-02-24 22:47:20 -05:00
|
|
|
|