port(2A): port/common Win32 layer, port_logic target and header gate
- Win32Types.h: fixed-width Win32 scalars, pointer-sized handles, static_asserts
- Win32Crt.{h,cpp}: MSVC _snprintf truncation contract, stricmp, timeGetTime wrap
- port_logic static lib linked into libmtgodot; standalone MTGODOT_BUILD_PORT build
- port_header_gate: every port/**.h compiles alone (twice) with its lib's
40250 Distribute|Win32 defines (NDEBUG, USE_LOD, _DISTRIBUTE)
- script/port_gate.sh: macOS/Android/iOS/Windows(mingw) PASS, Linux BLOCKED
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# port_logic — mirror of the 40250 client logic (extension/src/port/<Lib>/<File>.{h,cpp}).
|
||||
# No godot-cpp dependency: libmtgodot links it, and it also builds on its own (top-level
|
||||
# -DMTGODOT_BUILD_EXTENSION=OFF -DMTGODOT_BUILD_PORT=ON) for targets without an extension build.
|
||||
# See docs/PORT-PLAN.md batch 2A.
|
||||
|
||||
file(GLOB_RECURSE MT_PORT_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
file(GLOB_RECURSE MT_PORT_HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
|
||||
|
||||
add_library(port_logic STATIC ${MT_PORT_SOURCES})
|
||||
target_include_directories(port_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_compile_features(port_logic PUBLIC cxx_std_20)
|
||||
if(WIN32)
|
||||
target_link_libraries(port_logic PUBLIC winmm)
|
||||
endif()
|
||||
|
||||
# 40250 Distribute|Win32 preprocessor definitions per library (vs_files/<Lib>/<Lib>.vcxproj),
|
||||
# minus WIN32/_WINDOWS/_LIB/_CRT_SECURE_NO_WARNINGS: Windows-only branches go through platform/,
|
||||
# never through ported logic. UserInterface/Locale_inc.h feature macros come with that header.
|
||||
set(MT_PORT_DEFINES_default NDEBUG)
|
||||
set(MT_PORT_DEFINES_GameLib NDEBUG USE_LOD)
|
||||
set(MT_PORT_DEFINES_UserInterface NDEBUG USE_LOD _DISTRIBUTE)
|
||||
|
||||
function(mt_port_apply_defines file)
|
||||
file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${file})
|
||||
string(REGEX REPLACE "/.*" "" lib "${rel}")
|
||||
if(DEFINED MT_PORT_DEFINES_${lib})
|
||||
set(defs ${MT_PORT_DEFINES_${lib}})
|
||||
else()
|
||||
set(defs ${MT_PORT_DEFINES_default})
|
||||
endif()
|
||||
set_property(SOURCE ${file} APPEND PROPERTY COMPILE_DEFINITIONS ${defs})
|
||||
endfunction()
|
||||
|
||||
foreach(src IN LISTS MT_PORT_SOURCES)
|
||||
mt_port_apply_defines(${src})
|
||||
endforeach()
|
||||
|
||||
# Gate: every header under port/ compiles on its own (and twice, for its include guard), with its
|
||||
# library's definitions. Built by default, so every platform build enforces it.
|
||||
set(MT_PORT_GATE_SOURCES)
|
||||
foreach(hdr IN LISTS MT_PORT_HEADERS)
|
||||
file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${hdr})
|
||||
string(MAKE_C_IDENTIFIER "${rel}" id)
|
||||
set(tu ${CMAKE_CURRENT_BINARY_DIR}/header_gate/${id}.cpp)
|
||||
file(CONFIGURE OUTPUT ${tu} CONTENT "#include \"${rel}\"\n#include \"${rel}\"\n")
|
||||
set_property(SOURCE ${tu} APPEND PROPERTY OBJECT_DEPENDS ${hdr})
|
||||
list(APPEND MT_PORT_GATE_SOURCES ${tu})
|
||||
# Definitions follow the header's library, not the generated file's location.
|
||||
string(REGEX REPLACE "/.*" "" lib "${rel}")
|
||||
if(DEFINED MT_PORT_DEFINES_${lib})
|
||||
set_property(SOURCE ${tu} APPEND PROPERTY COMPILE_DEFINITIONS ${MT_PORT_DEFINES_${lib}})
|
||||
else()
|
||||
set_property(SOURCE ${tu} APPEND PROPERTY COMPILE_DEFINITIONS ${MT_PORT_DEFINES_default})
|
||||
endif()
|
||||
endforeach()
|
||||
add_library(port_header_gate OBJECT ${MT_PORT_GATE_SOURCES})
|
||||
target_include_directories(port_header_gate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_compile_features(port_header_gate PRIVATE cxx_std_20)
|
||||
add_dependencies(port_logic port_header_gate)
|
||||
|
||||
if(BUILD_TESTING AND CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
|
||||
add_executable(port_common_test ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/port_common_test.cpp)
|
||||
target_link_libraries(port_common_test PRIVATE port_logic)
|
||||
add_test(NAME port.common COMMAND $<TARGET_FILE:port_common_test>)
|
||||
endif()
|
||||
Reference in New Issue
Block a user