18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 23:14:59 +01:00

build(linux): load the shared libraries from the game folder and ship them in the build (#320)

This commit is contained in:
2026-11-11 03:29:36 +00:00
committed by GitHub
parent 226155d430
commit 5764e942a7
4 changed files with 136 additions and 1 deletions

View File

@@ -683,6 +683,41 @@ if (WIN32)
)
endif ()
# Linux: the game loads its shared libraries from its own folder first ($ORIGIN), and the build copies them there,
# so the folder runs on a system that doesn't have them, or has other versions. the RPATH is a DT_RPATH rather
# than a DT_RUNPATH, because only that one is also used for the libraries the copied ones load (libsndfile's codecs)
if (UNIX AND NOT APPLE)
option(BUNDLE_RUNTIME_LIBS "Linux: copy the shared libraries the game needs next to it and load them from there" ON)
endif()
if (UNIX AND NOT APPLE AND BUNDLE_RUNTIME_LIBS)
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN")
target_link_options(${PROJECT_NAME} PRIVATE "LINKER:--disable-new-dtags")
# the RPATH no longer leads to libraries outside the system folders (Python from setup-python, an OpenAL Soft
# in /usr/local), so their folders are given to the script as well
set(EU07_BUNDLE_SEARCH_DIRS "")
foreach(library IN LISTS Python3_LIBRARIES OPENAL_LIBRARY LUAJIT_LIBRARIES libserialport_LIBRARY)
if (IS_ABSOLUTE "${library}")
get_filename_component(library_dir "${library}" DIRECTORY)
list(APPEND EU07_BUNDLE_SEARCH_DIRS "${library_dir}")
endif()
endforeach()
list(APPEND EU07_BUNDLE_SEARCH_DIRS ${Python3_LIBRARY_DIRS})
list(REMOVE_DUPLICATES EU07_BUNDLE_SEARCH_DIRS)
string(REPLACE ";" "|" EU07_BUNDLE_SEARCH_DIRS "${EU07_BUNDLE_SEARCH_DIRS}")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND}
-DGAME=$<TARGET_FILE:${PROJECT_NAME}>
-DSEARCH_DIRS=${EU07_BUNDLE_SEARCH_DIRS}
-DCMAKE_OBJDUMP=${CMAKE_OBJDUMP}
-P "${CMAKE_CURRENT_SOURCE_DIR}/CMake_modules/bundle_runtime_libs.cmake"
COMMENT "Copying the shared libraries next to the game"
VERBATIM)
endif()
if(WIN32 AND WITH_PYTHON)
# the Python runtime next to the game, copied when it isn't there yet or the Python install changed, rather
# than after every link of the game: the library alone is thousands of files. the folder is the game's