mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
Add /Zi (compiler) + /DEBUG (linker) so the Release build produces a line-level ClassicAPI.pdb alongside the existing linker map. /OPT:REF and /OPT:ICF stay explicit so /DEBUG does not re-enable dead code and the shipped DLL does not grow; the PDB is a separate file matched to the DLL by signature. CI release runs now bundle the pdb + map into one crash-symbols zip attached to the release, replacing the loose renamed map. The zip name is kept unappealing to normal players and carries the tag so a dev can match symbols to the exact build.
171 lines
7.9 KiB
CMake
171 lines
7.9 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
|
|
project(ClassicAPI LANGUAGES CXX RC)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
|
|
|
# minhook's CMakeLists.txt declares `cmake_minimum_required(VERSION 3.0...3.5)`,
|
|
# which CMake 4.x flags as a deprecation warning every reconfigure. Bumping
|
|
# the minimum policy version here promotes its policy set to 3.10 without
|
|
# patching the vendored submodule.
|
|
set(CMAKE_POLICY_VERSION_MINIMUM 3.10)
|
|
add_subdirectory(external/minhook)
|
|
|
|
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "src/*.cpp")
|
|
file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS "src/*.h")
|
|
|
|
set(TINYCBOR_SOURCES
|
|
external/tinycbor/src/cborencoder.c
|
|
external/tinycbor/src/cborencoder_close_container_checked.c
|
|
external/tinycbor/src/cborencoder_float.c
|
|
external/tinycbor/src/cborparser.c
|
|
external/tinycbor/src/cborparser_dup_string.c
|
|
external/tinycbor/src/cborparser_float.c
|
|
external/tinycbor/src/cborerrorstrings.c)
|
|
|
|
# Version derivation. Dev builds use a sentinel "newer than every
|
|
# plausible release" so addon-side `CLASSIC_API_VERSION >= X` gates
|
|
# always pass locally. CI release builds pass `-DCLASSICAPI_TAG=vX.Y.Z`,
|
|
# which drives BOTH the compiled `CLASSIC_API_VERSION` int AND the
|
|
# embedded addon's `## Version:` toc line (substituted in
|
|
# embed_addon.cmake). The on-disk source toc stays `## Version: DEV`;
|
|
# only the embedded copy is stamped, so a release build needs nothing
|
|
# but the flag — no source edit.
|
|
set(CLASSICAPI_VERSION_VALUE 99999999)
|
|
set(CLASSICAPI_VER_MAJOR 9999)
|
|
set(CLASSICAPI_VER_MINOR 99)
|
|
set(CLASSICAPI_VER_PATCH 99)
|
|
set(CLASSICAPI_TOC_VERSION "DEV")
|
|
|
|
set(CLASSICAPI_TAG
|
|
""
|
|
CACHE STRING "Release tag like v1.2.3")
|
|
|
|
if(CLASSICAPI_TAG MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
|
|
set(CLASSICAPI_VER_MAJOR "${CMAKE_MATCH_1}")
|
|
set(CLASSICAPI_VER_MINOR "${CMAKE_MATCH_2}")
|
|
set(CLASSICAPI_VER_PATCH "${CMAKE_MATCH_3}")
|
|
math(EXPR CLASSICAPI_VERSION_VALUE
|
|
"${CLASSICAPI_VER_MAJOR} * 10000 + ${CLASSICAPI_VER_MINOR} * 100 + ${CLASSICAPI_VER_PATCH}")
|
|
set(CLASSICAPI_TOC_VERSION
|
|
"${CLASSICAPI_VER_MAJOR}.${CLASSICAPI_VER_MINOR}.${CLASSICAPI_VER_PATCH}")
|
|
elseif(CLASSICAPI_TAG)
|
|
message(
|
|
FATAL_ERROR
|
|
"Invalid CLASSICAPI_TAG: ${CLASSICAPI_TAG} (expected vMAJOR.MINOR.PATCH)"
|
|
)
|
|
endif()
|
|
|
|
# Bundle `AddOns/!!!ClassicAPI/` into a generated header so the DLL can
|
|
# surface the addon to the engine even when the user doesn't have it
|
|
# installed on disk. The file-read hook in `src/addons/Embedded.cpp`
|
|
# returns these buffers when the engine asks for paths under
|
|
# `Interface\AddOns\!!!ClassicAPI\`.
|
|
set(EMBEDDED_CLASSICAPI_SRC "${CMAKE_CURRENT_SOURCE_DIR}/AddOns/!!!ClassicAPI")
|
|
set(EMBEDDED_CLASSICAPI_HEADER "${CMAKE_BINARY_DIR}/generated/embedded_classicapi.h")
|
|
file(GLOB_RECURSE EMBEDDED_CLASSICAPI_FILES CONFIGURE_DEPENDS
|
|
"${EMBEDDED_CLASSICAPI_SRC}/*")
|
|
# The `.classicapi-dev` marker is a disk-only developer signal — keep it
|
|
# out of the embed inputs (embed_addon.cmake filters it too).
|
|
list(FILTER EMBEDDED_CLASSICAPI_FILES EXCLUDE REGEX "/\\.classicapi-dev$")
|
|
add_custom_command(
|
|
OUTPUT "${EMBEDDED_CLASSICAPI_HEADER}"
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DSRC_DIR=${EMBEDDED_CLASSICAPI_SRC}
|
|
-DOUT_HEADER=${EMBEDDED_CLASSICAPI_HEADER}
|
|
-DADDON_NAME=ClassicAPI
|
|
-DADDON_VERSION=${CLASSICAPI_TOC_VERSION}
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_addon.cmake"
|
|
DEPENDS
|
|
${EMBEDDED_CLASSICAPI_FILES}
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_addon.cmake"
|
|
COMMENT "Embedding !!!ClassicAPI addon into ${EMBEDDED_CLASSICAPI_HEADER}"
|
|
VERBATIM)
|
|
|
|
# Bundle `src/bindings/Bindings.xml` (our TARGETING-group additions)
|
|
# into a generated header. `src/bindings/Inject.cpp` extracts the
|
|
# inner `<Binding>` elements from the embedded buffer and splices them
|
|
# into the engine's `Interface\FrameXML\Bindings.xml` at load time.
|
|
set(EMBEDDED_BINDINGS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/bindings/Bindings.xml")
|
|
set(EMBEDDED_BINDINGS_HEADER "${CMAKE_BINARY_DIR}/generated/embedded_bindings.h")
|
|
add_custom_command(
|
|
OUTPUT "${EMBEDDED_BINDINGS_HEADER}"
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DINPUT_FILE=${EMBEDDED_BINDINGS_SRC}
|
|
-DOUT_HEADER=${EMBEDDED_BINDINGS_HEADER}
|
|
-DSYMBOL=kEmbeddedBindingsXml
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_file.cmake"
|
|
DEPENDS
|
|
"${EMBEDDED_BINDINGS_SRC}"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/embed_file.cmake"
|
|
COMMENT "Embedding bindings XML into ${EMBEDDED_BINDINGS_HEADER}"
|
|
VERBATIM)
|
|
|
|
add_library(${PROJECT_NAME} SHARED
|
|
${SOURCES} ${HEADERS} ${TINYCBOR_SOURCES}
|
|
${EMBEDDED_CLASSICAPI_HEADER}
|
|
${EMBEDDED_BINDINGS_HEADER})
|
|
|
|
target_compile_definitions(
|
|
${PROJECT_NAME}
|
|
PRIVATE CLASSICAPI_VERSION_VALUE=${CLASSICAPI_VERSION_VALUE})
|
|
|
|
# Stamp the PE VERSIONINFO resource from the same version components, so the
|
|
# DLL's file/product version (Explorer -> Properties -> Details) matches the
|
|
# CLASSIC_API_VERSION Lua global. The .rsrc section the resource lands in is
|
|
# untouched by the .rdata/.pdata section merges below.
|
|
set(CLASSICAPI_VER_STRING
|
|
"${CLASSICAPI_VER_MAJOR}.${CLASSICAPI_VER_MINOR}.${CLASSICAPI_VER_PATCH}.0")
|
|
set(CLASSICAPI_VERSION_RC "${CMAKE_BINARY_DIR}/generated/version.rc")
|
|
configure_file(
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in"
|
|
"${CLASSICAPI_VERSION_RC}"
|
|
@ONLY)
|
|
target_sources(${PROJECT_NAME} PRIVATE "${CLASSICAPI_VERSION_RC}")
|
|
|
|
# ole32: COM (CoInitializeEx / CoCreateInstance / CoTaskMemFree) for the
|
|
# SAPI text-to-speech backend in src/voicechat/Tts.cpp. The SAPI GUIDs are
|
|
# instantiated in that TU via <initguid.h>, so no sapi.lib is needed.
|
|
# user32: Win32 clipboard API (OpenClipboard / SetClipboardData) for
|
|
# CopyToClipboard in src/clipboard/Copy.cpp.
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE minhook advapi32 ole32 user32)
|
|
|
|
target_include_directories(
|
|
${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${CMAKE_BINARY_DIR}/generated
|
|
external/minhook/include
|
|
external
|
|
external/tinycbor/src)
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "ClassicAPI")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
|
|
# /Zi retains full debug info (source file + line numbers, locals, types) in a
|
|
# separate PDB WITHOUT disabling optimization — the DLL stays a fully optimized
|
|
# /O2 release build; the symbols just live in ClassicAPI.pdb on the side. Feeds
|
|
# the linker's /DEBUG below.
|
|
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG /Zi")
|
|
set(CMAKE_SHARED_LINKER_FLAGS
|
|
# Two debug artifacts for triaging crashes from a SHIPPED DLL. Both are
|
|
# published as release artifacts, match this exact build, and have no effect
|
|
# on code layout:
|
|
# /MAP -> build/Release/ClassicAPI.map: a text symbol->address table
|
|
# that resolves the `0001:offset` addresses in WoW's ERROR #132
|
|
# crash log back to functions by hand (no debugger/dump needed).
|
|
# /DEBUG -> build/Release/ClassicAPI.pdb: full symbols (paired with the
|
|
# compiler's /Zi) so WinDbg/x64dbg/VS produce a line-level
|
|
# symbolicated call stack from a crash dump. A SEPARATE file —
|
|
# it is NOT embedded in the DLL, only a small signature record
|
|
# linking the two is.
|
|
# /DEBUG implicitly disables /OPT:REF and /OPT:ICF (dead-code strip +
|
|
# identical-COMDAT fold); they are listed explicitly below so they stay ON
|
|
# and the shipped DLL does not grow. (/OPT:ICF folds identical functions, so
|
|
# a few map symbols share an address — harmless.)
|
|
# /DEF exports `Load` (VanillaFixes' post-injection entry point) undecorated
|
|
# so its GetProcAddress(module, "Load") resolves. See src/ClassicAPI.def and
|
|
# the loader-lock rationale in src/DllMain.cpp.
|
|
"/OPT:REF /OPT:ICF /MERGE:.rdata=.text /MERGE:.pdata=.text /SECTION:.text,EWR /NODEFAULTLIB:MSVCRT /MAP /DEBUG /DEF:${CMAKE_CURRENT_SOURCE_DIR}/src/ClassicAPI.def"
|
|
)
|