Files
dusklight/cmake/AndroidExports.cmake
T
Luke Street d2cdbf0a83 Mods: Rework mod linking
Apple: mods are now MH_BUNDLE (.so) linked with -bundle_loader,
replacing the deprecated (on iOS) -undefined dynamic_lookup.

Windows: clang-cl mods link dusklight.exe directly; lld's mingw driver
synthesizes imports from the export table. cl still requires the
import library.
2026-07-13 20:42:57 -06:00

71 lines
2.8 KiB
CMake

include_guard(GLOBAL)
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
# Android mod linking: symgen scans and filters the game's exports, generating a version script used for the executable
# link step, and generates a shared object stub that mods can link against without having to build the whole game.
function(setup_android_exports target)
include("${_dir}/SymbolManifest.cmake")
ensure_symgen(TRUE)
add_dependencies(${target} symgen)
set(_rsp_lines "$<TARGET_OBJECTS:${target}>")
foreach (_lib IN LISTS JSYSTEM_LIBRARIES)
list(APPEND _rsp_lines "$<TARGET_FILE:${_lib}>")
endforeach ()
list(JOIN _rsp_lines "\n" _rsp_content)
set(_rsp "${CMAKE_BINARY_DIR}/dusklight_exports_input.rsp")
file(GENERATE OUTPUT "${_rsp}" CONTENT "${_rsp_content}")
set(_sdk_args)
foreach (_lib aurora_card aurora_core aurora_dvd aurora_gd aurora_gx aurora_mtx
aurora_os aurora_pad aurora_si aurora_vi)
if (TARGET ${_lib})
list(APPEND _sdk_args --sdk-lib "$<TARGET_FILE:${_lib}>")
endif ()
endforeach ()
if (TARGET dawn::webgpu_dawn)
get_target_property(_dawn_type dawn::webgpu_dawn TYPE)
if (_dawn_type STREQUAL "STATIC_LIBRARY")
list(APPEND _sdk_args --sdk-lib "$<TARGET_FILE:dawn::webgpu_dawn>")
endif ()
endif ()
set(_vscript "${CMAKE_BINARY_DIR}/dusklight_exports.ver")
add_custom_command(TARGET ${target} PRE_LINK
# TODO: src/dusk/ is NOT excluded: inline code in game headers
# currently call into it (e.g. dusk::frame_interp::lookup_replacement).
COMMAND "${SYMGEN_EXE}" exports
--rsp "${_rsp}"
--out "${_vscript}"
--format version-script
--exclude cmake_pch
--exclude miniz
--exclude asan_options
# Resolved from the Java side; the SDL ones live in the statically-linked
# SDL archive, outside the provenance scan.
--extra-sym JNI_OnLoad
--extra-sym SDL_main
--extra-sym "Java_*"
${_sdk_args}
COMMENT "Generating dusklight exports"
VERBATIM)
target_link_options(${target} PRIVATE "-Wl,--version-script=${_vscript}")
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _arch)
if (_arch STREQUAL "aarch64")
set(_machine "arm64")
else ()
set(_machine "amd64")
endif ()
set(_stub "${CMAKE_BINARY_DIR}/stub-android-${_arch}.so")
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${SYMGEN_EXE}" stub -f elf "$<TARGET_FILE:${target}>" -o "${_stub}"
--soname "$<TARGET_FILE_NAME:${target}>" --machine "${_machine}"
BYPRODUCTS "${_stub}"
COMMENT "Generating dusklight link stub"
VERBATIM)
install(FILES "${_stub}" DESTINATION sdk)
endfunction()