mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
squashed into a single commit because doing it in steps that all
compiled involved a lot of boilerplate that is pointless to commit to
the repository. GH still has the PR for reference.
g_lang, MAX_MESSAGES_ON_MAP_BOTTOM, and GetLanguagePrefix() were
compile-time constants selected by the ENGLISH/GERMAN/... build
define. They're now runtime, defaulting to the same per-exe value the
define used to pick, and overridable at startup from [Ja2 Settings]
LANGUAGE in Ja2.ini.
-
XMLTacticalMessages is filled at runtime from NewTacticalMessages.xml,
never from compiled-in per-language data: all 8 per-language definitions
were the identical all-zero { L"" }. Delete them and define one shared
buffer in Utils/XML_Language.cpp (the loader) instead of pointer-rebinding
it like the static tables — this drops 9 dead 800KB zero-buffers (8
namespaced copies in LanguageStrings.cpp plus the standalone one) and
leaves no bind-ordering hazard for the XML load path.
-
ExportStrings.cpp privately recompiled one language's full text table
by #including the raw _<LANG>Text.cpp inside namespace Loc, keyed off
the exe-level ENGLISH/GERMAN/... compile macro (whichever the build
happened to select). That's redundant with the pointer globals every
other subsystem already uses (Text.h / LanguageStrings.cpp).
Drop the private copy; the unqualified table names in Loc::ExportStrings
now resolve to the global pointer externs, which BindLanguageStrings has
already rebound to the runtime g_lang by the time this runs (EXPORT_STRINGS
ini flag, checked after GetRuntimeSettings in sgp.cpp). gs_Lang (used only
by Loc::Translate for the Polish/Russian byte remap on raw .edt exports) is
now derived from g_lang via ToLocLanguage, so the export always matches
whatever language is actually active instead of a compile-time pick.
-
Editor/popupmenu.cpp and Strategic/Scheduling.cpp kept their own
call-site extern of gszScheduleActions as CHAR16[NUM_SCHEDULE_ACTIONS][20]
after the real definition changed into a rebindable pointer
(CHAR16 (*)[20], LanguageStrings.cpp). MSVC decays the outer array
dimension when mangling globals, so both declarations produce the same
symbol (?gszScheduleActions@@3PAY0BE@_WA) and the mismatch linked
silently -- but the array-typed TUs then indexed the 4-byte pointer
slot itself as string data, so the editor schedule popup and the map
schedule message text read garbage.
-
add text.def to be single-source of truth on symbol names and use it
.much simpler, less error prone if adding more strings
-
add pseudo interface for language state. MAX_SAGES_ON_BOTTOM must always
change in lockstep with g_lang. this isn't foolproof but better
---------
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
165 lines
5.3 KiB
CMake
165 lines
5.3 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
|
|
project(ja2)
|
|
|
|
include(cmake/CopyUserPresetTemplate.cmake)
|
|
CopyUserPresetTemplate()
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
option(LTO_OPTION "Enable link-time optimization if supported by compiler" OFF)
|
|
|
|
include(CheckIPOSupported)
|
|
check_ipo_supported(RESULT LinkTimeOptimization OUTPUT IpoError LANGUAGES C CXX)
|
|
if(LinkTimeOptimization AND LTO_OPTION)
|
|
message(STATUS "Configuring WITH link-time optimization")
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
else()
|
|
message(STATUS "Configuring WITHOUT link-time optimization ${IpoError}")
|
|
endif()
|
|
|
|
option(ADDRESS_SANITIZER OFF)
|
|
if(ADDRESS_SANITIZER)
|
|
message(STATUS "AddressSanitizer ENABLED for non-Release builds")
|
|
add_compile_options($<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>,-fsanitize=address,>)
|
|
endif()
|
|
|
|
if(MSVC)
|
|
add_compile_options("/wd4838") # silence implicit narrowing conversion warnings
|
|
endif()
|
|
|
|
# whether we are using MSBuild as a generator
|
|
set(usingMsBuild $<STREQUAL:${CMAKE_VS_PLATFORM_NAME},Win32>)
|
|
|
|
# lua51.lib and lua51.vc9.lib have been built with /MTx, so we must as well
|
|
# TODO: build our own Lua 5.1.2 from source so we can use whichever
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP _CRT_SECURE_NO_DEPRECATE)
|
|
include_directories(
|
|
"${CMAKE_SOURCE_DIR}/Ja2"
|
|
"${CMAKE_SOURCE_DIR}/ext/VFS/include"
|
|
"${CMAKE_SOURCE_DIR}/Utils"
|
|
"${CMAKE_SOURCE_DIR}/TileEngine"
|
|
"${CMAKE_SOURCE_DIR}/TacticalAI"
|
|
"${CMAKE_SOURCE_DIR}/ModularizedTacticalAI/include"
|
|
"${CMAKE_SOURCE_DIR}/Tactical"
|
|
"${CMAKE_SOURCE_DIR}/Strategic"
|
|
"${CMAKE_SOURCE_DIR}/sgp"
|
|
"${CMAKE_SOURCE_DIR}/Ja2/Res"
|
|
"${CMAKE_SOURCE_DIR}/lua"
|
|
"${CMAKE_SOURCE_DIR}/Laptop"
|
|
"${CMAKE_SOURCE_DIR}/Multiplayer"
|
|
"${CMAKE_SOURCE_DIR}/Editor"
|
|
"${CMAKE_SOURCE_DIR}/i18n/include"
|
|
)
|
|
|
|
# external libraries
|
|
add_subdirectory("ext/libpng")
|
|
add_subdirectory("ext/zlib")
|
|
add_subdirectory("ext/VFS")
|
|
target_link_libraries(bfVFS PRIVATE 7z)
|
|
|
|
# ja2export utility
|
|
add_subdirectory("ext/export/src")
|
|
|
|
# static libraries whose translation units don't rely on Application preprocessor definitions.
|
|
add_subdirectory(lua)
|
|
add_subdirectory(Multiplayer)
|
|
add_subdirectory(wine)
|
|
|
|
set(Ja2_Libraries
|
|
"${CMAKE_SOURCE_DIR}/binkw32.lib"
|
|
"${CMAKE_SOURCE_DIR}/libexpatMT.lib"
|
|
"${CMAKE_SOURCE_DIR}/lua51.lib"
|
|
"${CMAKE_SOURCE_DIR}/lua51.vc9.lib"
|
|
"${CMAKE_SOURCE_DIR}/SMACKW32.LIB"
|
|
"Dbghelp.lib"
|
|
"Winmm.lib"
|
|
"ws2_32.lib"
|
|
bfVFS
|
|
Lua
|
|
Multiplayer
|
|
wine
|
|
)
|
|
|
|
# static libraries whose translation units rely on Application preprocessor definitions.
|
|
set(Ja2_Libs
|
|
Editor
|
|
Ja2
|
|
Laptop
|
|
ModularizedTacticalAI
|
|
sgp
|
|
Strategic
|
|
Tactical
|
|
TacticalAI
|
|
TileEngine
|
|
Utils
|
|
)
|
|
foreach(lib IN LISTS Ja2_Libs)
|
|
add_subdirectory(${lib})
|
|
endforeach()
|
|
|
|
# language library relies on Application preprocessor definition; compiled once per app
|
|
# with all 8 languages built in and selected at runtime (docs/plans/language-design.md).
|
|
add_subdirectory(i18n)
|
|
|
|
# simple function to validate the Application choice
|
|
include(cmake/ValidateOptions.cmake)
|
|
|
|
set(ValidApplications JA2 JA2MAPEDITOR JA2UB JA2UBMAPEDITOR)
|
|
ValidateOptions("${ValidApplications}" "Applications" "${Applications}" "ApplicationTargets")
|
|
|
|
|
|
# preprocessor definitions for Debug build, per the legacy MSBuild
|
|
set(debugFlags $<IF:$<CONFIG:Debug>,JA2BETAVERSION;JA2TESTVERSION;DEBUG_ATTACKBUSY,>)
|
|
|
|
foreach(app IN LISTS ApplicationTargets)
|
|
set(isEditor $<STREQUAL:${app},JA2MAPEDITOR>)
|
|
set(isUb $<STREQUAL:${app},JA2UB>)
|
|
set(isUbEditor $<STREQUAL:${app},JA2UBMAPEDITOR>)
|
|
set(compilationFlags
|
|
$<IF:${isEditor},JA2EDITOR;JA2BETAVERSION,>
|
|
$<IF:${isUb},JA2UB;JA2UBMAPS,>
|
|
$<IF:${isUbEditor},JA2UB;JA2UBMAPS;JA2EDITOR;JA2BETAVERSION,>
|
|
)
|
|
|
|
foreach(lib IN LISTS Ja2_Libs)
|
|
# library for an application, e.g. JA2UB_sgp
|
|
set(game_library ${app}_${lib})
|
|
add_library(${game_library})
|
|
target_sources(${game_library} PRIVATE ${${lib}Src})
|
|
target_compile_definitions(${game_library} PRIVATE ${compilationFlags} ${debugFlags})
|
|
endforeach()
|
|
|
|
# executable for the application, e.g. JA2.exe
|
|
set(exe ${app})
|
|
add_executable(${exe} WIN32
|
|
sgp/sgp.cpp
|
|
Ja2/Res/ja2.rc
|
|
)
|
|
target_link_libraries(${exe} PRIVATE ${Ja2_Libraries} $<IF:${usingMsBuild},legacy_stdio_definitions.lib,>)
|
|
target_link_options(${exe} PRIVATE $<IF:${usingMsBuild},/SAFESEH:NO,>)
|
|
target_compile_definitions(${exe} PRIVATE ${compilationFlags} ${debugFlags})
|
|
|
|
# language library for the application, e.g. JA2MAPEDITOR_i18n — one per app, all 8
|
|
# languages compiled in, selected at runtime by BindLanguageStrings
|
|
set(language_library ${exe}_i18n)
|
|
add_library(${language_library})
|
|
target_sources(${language_library} PRIVATE ${i18nSrc})
|
|
target_compile_definitions(${language_library} PRIVATE ${compilationFlags} ${debugFlags})
|
|
target_link_libraries(${exe} PRIVATE ${language_library})
|
|
|
|
# go through all game libraries again and link them to the app executable
|
|
foreach(lib IN LISTS Ja2_Libs)
|
|
target_link_libraries(${exe} PRIVATE ${app}_${lib})
|
|
endforeach()
|
|
|
|
# for SGP only
|
|
target_link_libraries(${app}_sgp PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib")
|
|
target_link_libraries(${app}_sgp PRIVATE libpng)
|
|
target_compile_definitions(${app}_sgp PRIVATE ${compilationFlags} ${debugFlags} NO_ZLIB_COMPRESSION)
|
|
endforeach()
|