Install deps properly

This commit is contained in:
AnyOldName3
2026-10-04 18:52:47 +01:00
parent 4969186f34
commit 3dfebe8681
15 changed files with 201 additions and 60 deletions
+55 -21
View File
@@ -19,11 +19,15 @@ endif()
if (APPLE OR WIN32)
set(DEPLOY_QT_TRANSLATIONS_DEFAULT ON)
set(deploy_runtime_dependencies_default ON)
else ()
set(DEPLOY_QT_TRANSLATIONS_DEFAULT OFF)
set(deploy_runtime_dependencies_default OFF)
endif ()
option(DEPLOY_QT_TRANSLATIONS "Deploy standard Qt translations to resources folder. Needed when OpenMW applications are deployed with Qt libraries" ${DEPLOY_QT_TRANSLATIONS_DEFAULT})
# this has overlap with OPENMW_LOCAL_INSTALL, so needs some tidying
option(OPENMW_DEPLOY_RUNTIME_DEPENDENCIES "Deploy runtime dependency libraries. Needed when not relying on a system-wide insallation of these libraries existing" ${deploy_runtime_dependencies_default})
# Apps and tools
option(BUILD_OPENMW "Build OpenMW" ON)
@@ -117,6 +121,7 @@ endif(EXISTS ${PROJECT_SOURCE_DIR}/.git)
# Macros
include(OpenMWMacros)
include(WholeArchive)
include(escape_regex_control_characters)
# doxygen main page
@@ -460,8 +465,39 @@ endif()
if(OPENMW_USE_SYSTEM_OSG)
find_package(OpenSceneGraph 3.6.5 REQUIRED ${USED_OSG_COMPONENTS}) # Bump to 3.6.6 when released
if(OSG_STATIC)
if(OSG_STATIC OR OPENMW_DEPLOY_RUNTIME_DEPENDENCIES)
find_package(OSGPlugins REQUIRED COMPONENTS ${USED_OSG_PLUGINS})
if(OSG_STATIC)
set(module_or_static STATIC)
else()
set(module_or_static MODULE)
endif()
foreach(osgplugin ${USED_OSG_PLUGINS})
if(NOT TARGET ${osgplugin})
add_library(${osgplugin} ${module_or_static} IMPORTED)
string(TOUPPER ${osgplugin} pluginnameupper)
if (${pluginnameupper}_LIBRARY_RELEASE)
set_property(TARGET ${osgplugin} APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE
)
set_target_properties(${osgplugin} PROPERTIES
IMPORTED_LOCATION_RELEASE "${${pluginnameupper}_LIBRARY_RELEASE}"
)
endif()
if (${pluginnameupper}_LIBRARY_DEBUG)
set_property(TARGET ${osgplugin} APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG
)
set_target_properties(${osgplugin} PROPERTIES
IMPORTED_LOCATION_DEBUG "${${pluginnameupper}_LIBRARY_DEBUG}"
)
endif()
endif()
endforeach()
install(IMPORTED_RUNTIME_ARTIFACTS ${USED_OSG_PLUGINS} DESTINATION "${CMAKE_INSTALL_LIBDIR}/osgPlugins-${OPENSCENEGRAPH_VERSION}" RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
endif()
@@ -623,10 +659,12 @@ if (APPLE)
endif()
if (UNIX AND NOT APPLE)
if (OPENMW_LOCAL_INSTALL AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
if (OPENMW_DEPLOY_RUNTIME_DEPENDENCIES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
# file(RELATIVE_PATH ...) can't handle pure lexical relativity, but cmake_path only came with 3.20.0
cmake_path(RELATIVE_PATH CMAKE_INSTALL_LIBDIR BASE_DIRECTORY "${CMAKE_INSTALL_BINDIR}" OUTPUT_VARIABLE origin_relative_libdir)
set(CMAKE_INSTALL_RPATH "$ORIGIN/${origin_relative_libdir}")
else()
message(WARNING "CMake is too old to work out how to adjust RPATH, please do so manually or update to something newer than 2017.")
endif()
endif()
@@ -804,6 +842,14 @@ endif()
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CUSTOM_CPACK_OS_NAME}-${CUSTOM_CPACK_ARCHITECTURE}")
if (NOT APPLE AND OPENMW_DEPLOY_RUNTIME_DEPENDENCIES)
install(RUNTIME_DEPENDENCY_SET openmw-dependencies
POST_EXCLUDE_REGEXES
^/lib64/
^/usr/lib64/
)
endif ()
# Apple bundling
if (APPLE)
if(CMAKE_VERSION VERSION_LESS 3.19)
@@ -936,25 +982,13 @@ if (APPLE)
include(CPack)
elseif(NOT APPLE)
if(WIN32)
INSTALL(DIRECTORY "${RUNTIME_OUTPUT_DIRECTORY}/" DESTINATION "." FILES_MATCHING PATTERN "*.dll"
PATTERN ".cmake" EXCLUDE
PATTERN ".qt" EXCLUDE
PATTERN "_CPack_Packages" EXCLUDE
PATTERN "_deps" EXCLUDE
PATTERN "apps" EXCLUDE
PATTERN "bin" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE
PATTERN "components" EXCLUDE
PATTERN "deps" EXCLUDE
PATTERN "docs" EXCLUDE
PATTERN "extern" EXCLUDE
PATTERN "files" EXCLUDE
PATTERN "lib" EXCLUDE
PATTERN "SymStore" EXCLUDE
PATTERN "symstore-venv" EXCLUDE
PATTERN "Testing" EXCLUDE
PATTERN "tests_output" EXCLUDE
PATTERN "try-compile" EXCLUDE)
# this just deals with Qt plugins now as if we get windeployqt.exe to do it, it adds things we don't need like ANGLE
INSTALL(DIRECTORY
"${RUNTIME_OUTPUT_DIRECTORY}/iconengines"
"${RUNTIME_OUTPUT_DIRECTORY}/imageformats"
"${RUNTIME_OUTPUT_DIRECTORY}/platforms"
"${RUNTIME_OUTPUT_DIRECTORY}/styles"
DESTINATION "." FILES_MATCHING PATTERN "*.dll")
INSTALL(DIRECTORY "${RUNTIME_OUTPUT_DIRECTORY}/" DESTINATION "." CONFIGURATIONS Debug;RelWithDebInfo FILES_MATCHING PATTERN "*.pdb"
PATTERN ".cmake" EXCLUDE
PATTERN ".qt" EXCLUDE
+1 -1
View File
@@ -23,7 +23,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
install(TARGETS bsatool)
install(TARGETS bsatool RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+1 -1
View File
@@ -20,7 +20,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
install(TARGETS openmw-bulletobjecttool)
install(TARGETS openmw-bulletobjecttool RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+1 -1
View File
@@ -30,7 +30,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
install(TARGETS esmtool)
install(TARGETS esmtool RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+1 -1
View File
@@ -47,7 +47,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
INSTALL(TARGETS openmw-essimporter)
install(TARGETS openmw-essimporter RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+25 -4
View File
@@ -53,7 +53,7 @@ if(NOT WIN32)
endif(NOT WIN32)
# Main executable
openmw_add_executable(openmw-launcher
openmw_add_qt_executable(openmw-launcher
${GUI_TYPE}
${LAUNCHER}
${LAUNCHER_HEADER}
@@ -63,16 +63,37 @@ openmw_add_executable(openmw-launcher
add_dependencies(openmw-launcher qm-files)
if (NOT APPLE)
INSTALL(TARGETS openmw-launcher)
install(TARGETS openmw-launcher RUNTIME_DEPENDENCY_SET openmw-dependencies)
if (LINUX AND OPENMW_DEPLOY_RUNTIME_DEPENDENCIES)
if (Qt6Core_VERSION VERSION_LESS 6.10)
message(FATAL_ERROR "Deployment of Qt on Linux requires at least 6.10 (for the INCLUDE_PLUGINS argument)")
endif ()
# don't bother with this on Windows yet as windeployqt includes a bunch of DLLs we don't use
cmake_path(NORMAL_PATH QT_DIR OUTPUT_VARIABLE QT_BASE_DIR)
string(REGEX REPLACE "(.+)/lib/cmake/Qt[0-9]+" "\\1" QT_BASE_DIR "${QT_BASE_DIR}")
escape_regex_control_characters(QT_BASE_REGEX "${QT_BASE_DIR}")
qt_generate_deploy_app_script(TARGET openmw-launcher
OUTPUT_SCRIPT deploy_script
NO_TRANSLATIONS
NO_COMPILER_RUNTIME
INCLUDE_PLUGINS wayland
POST_INCLUDE_REGEXES
"${QT_BASE_REGEX}"
POST_EXCLUDE_REGEXES
".*"
)
install(SCRIPT ${deploy_script})
endif()
endif ()
target_link_libraries(openmw-launcher
target_link_libraries(openmw-launcher PUBLIC
SDL2::SDL2
${OPENAL_LIBRARY}
components_qt
)
target_link_libraries(openmw-launcher Qt::Widgets Qt::Core Qt::Svg)
target_link_libraries(openmw-launcher PUBLIC Qt::Widgets Qt::Core Qt::Svg)
if (WIN32)
target_sources(openmw-launcher PRIVATE ${CMAKE_SOURCE_DIR}/files/windows/other-apps.manifest)
+1 -1
View File
@@ -23,7 +23,7 @@ if (WIN32)
endif()
if (NOT APPLE)
INSTALL(TARGETS openmw-iniimporter)
install(TARGETS openmw-iniimporter RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MINGW)
+1 -1
View File
@@ -30,7 +30,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
install(TARGETS openmw-navmeshtool)
install(TARGETS openmw-navmeshtool RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+1 -1
View File
@@ -22,7 +22,7 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE)
install(TARGETS niftest)
install(TARGETS niftest RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+26 -5
View File
@@ -172,7 +172,7 @@ add_library(openmw-cs-lib STATIC
)
if(BUILD_OPENCS)
openmw_add_executable(openmw-cs
openmw_add_qt_executable(openmw-cs
MACOSX_BUNDLE
${OPENCS_MAC_ICON}
${OPENCS_CFG}
@@ -182,7 +182,7 @@ if(BUILD_OPENCS)
main.cpp
)
target_link_libraries(openmw-cs openmw-cs-lib)
target_link_libraries(openmw-cs PRIVATE openmw-cs-lib)
set_property(TARGET openmw-cs PROPERTY AUTOMOC ON)
set_property(TARGET openmw-cs PROPERTY AUTOUIC_SEARCH_PATHS ui)
@@ -190,7 +190,7 @@ if(BUILD_OPENCS)
if (BUILD_WITH_CODE_COVERAGE)
target_compile_options(openmw-cs PRIVATE --coverage)
target_link_libraries(openmw-cs gcov)
target_link_libraries(openmw-cs PRIVATE gcov)
endif()
endif()
@@ -250,8 +250,29 @@ if (WIN32)
endif()
if (NOT APPLE AND BUILD_OPENCS)
INSTALL(TARGETS openmw-cs)
install(TARGETS openmw-cs RUNTIME_DEPENDENCY_SET openmw-dependencies)
INSTALL(FILES "$<TARGET_FILE_DIR:openmw-cs>/defaults-cs.bin" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}")
if (LINUX AND OPENMW_DEPLOY_RUNTIME_DEPENDENCIES)
if (Qt6Core_VERSION VERSION_LESS 6.10)
message(FATAL_ERROR "Deployment of Qt on Linux requires at least 6.10 (for the INCLUDE_PLUGINS argument)")
endif ()
# don't bother with this on Windows yet as windeployqt includes a bunch of DLLs we don't use
cmake_path(NORMAL_PATH QT_DIR OUTPUT_VARIABLE QT_BASE_DIR)
string(REGEX REPLACE "(.+)/lib/cmake/Qt[0-9]+" "\\1" QT_BASE_DIR "${QT_BASE_DIR}")
escape_regex_control_characters(QT_BASE_REGEX "${QT_BASE_DIR}")
qt_generate_deploy_app_script(TARGET openmw-cs
OUTPUT_SCRIPT deploy_script
NO_TRANSLATIONS
NO_COMPILER_RUNTIME
INCLUDE_PLUGINS wayland
POST_INCLUDE_REGEXES
"${QT_BASE_REGEX}"
POST_EXCLUDE_REGEXES
".*"
)
install(SCRIPT ${deploy_script})
endif()
endif()
if (MSVC)
@@ -273,7 +294,7 @@ endif(USE_QT)
if (BUILD_WITH_CODE_COVERAGE)
target_compile_options(openmw-cs-lib PRIVATE --coverage)
target_link_libraries(openmw-cs-lib gcov)
target_link_libraries(openmw-cs-lib PRIVATE gcov)
endif()
if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
+1 -1
View File
@@ -272,5 +272,5 @@ if (BUILD_WITH_CODE_COVERAGE)
endif()
if (NOT APPLE AND BUILD_OPENMW)
INSTALL(TARGETS openmw)
install(TARGETS openmw RUNTIME_DEPENDENCY_SET openmw-dependencies)
endif()
+27 -6
View File
@@ -63,7 +63,7 @@ if (OPENMW_USE_UNSHIELD)
include_directories(${LIBUNSHIELD_INCLUDE_DIRS})
endif()
openmw_add_executable(openmw-wizard
openmw_add_qt_executable(openmw-wizard
${GUI_TYPE}
${WIZARD}
${WIZARD_HEADER}
@@ -72,14 +72,14 @@ openmw_add_executable(openmw-wizard
add_dependencies(openmw-wizard qm-files)
target_link_libraries(openmw-wizard
target_link_libraries(openmw-wizard PRIVATE
components_qt
)
target_link_libraries(openmw-wizard Qt::Widgets Qt::Core Qt::Svg)
target_link_libraries(openmw-wizard PRIVATE Qt::Widgets Qt::Core Qt::Svg)
if (OPENMW_USE_UNSHIELD)
target_link_libraries(openmw-wizard ${LIBUNSHIELD_LIBRARIES})
target_link_libraries(openmw-wizard PRIVATE ${LIBUNSHIELD_LIBRARIES})
endif()
if (WIN32)
@@ -88,11 +88,32 @@ endif()
if (BUILD_WITH_CODE_COVERAGE)
target_compile_options(openmw-wizard PRIVATE --coverage)
target_link_libraries(openmw-wizard gcov)
target_link_libraries(openmw-wizard PRIVATE gcov)
endif()
if (NOT APPLE)
INSTALL(TARGETS openmw-wizard)
install(TARGETS openmw-wizard RUNTIME_DEPENDENCY_SET openmw-dependencies)
if (LINUX AND OPENMW_DEPLOY_RUNTIME_DEPENDENCIES)
if (Qt6Core_VERSION VERSION_LESS 6.10)
message(FATAL_ERROR "Deployment of Qt on Linux requires at least 6.10 (for the INCLUDE_PLUGINS argument)")
endif ()
# don't bother with this on Windows yet as windeployqt includes a bunch of DLLs we don't use
cmake_path(NORMAL_PATH QT_DIR OUTPUT_VARIABLE QT_BASE_DIR)
string(REGEX REPLACE "(.+)/lib/cmake/Qt[0-9]+" "\\1" QT_BASE_DIR "${QT_BASE_DIR}")
escape_regex_control_characters(QT_BASE_REGEX "${QT_BASE_DIR}")
qt_generate_deploy_app_script(TARGET openmw-wizard
OUTPUT_SCRIPT deploy_script
NO_TRANSLATIONS
NO_COMPILER_RUNTIME
INCLUDE_PLUGINS wayland
POST_INCLUDE_REGEXES
"${QT_BASE_REGEX}"
POST_EXCLUDE_REGEXES
".*"
)
install(SCRIPT ${deploy_script})
endif()
endif()
if(USE_QT)
+25
View File
@@ -136,6 +136,31 @@ macro (openmw_add_executable target)
endif (MSVC)
endmacro (openmw_add_executable)
macro (openmw_add_qt_executable target)
set(OMW_ADD_EXE_OPTIONS WIN32 MACOSX_BUNDLE EXCLUDE_FROM_ALL)
set(OMW_ADD_EXE_VALUES)
set(OMW_ADD_EXE_MULTI_VALUES)
cmake_parse_arguments(OMW_ADD_EXE "${OMW_ADD_EXE_OPTIONS}" "${OMW_ADD_EXE_VALUES}" "${OMW_ADD_EXE_MULTI_VALUES}" ${ARGN})
if (OMW_ADD_EXE_WIN32)
set(OMW_ADD_EXE_WIN32_VALUE WIN32)
endif (OMW_ADD_EXE_WIN32)
if (OMW_ADD_EXE_MACOSX_BUNDLE)
set(OMW_ADD_EXE_MACOSX_BUNDLE_VALUE MACOSX_BUNDLE)
endif (OMW_ADD_EXE_MACOSX_BUNDLE)
if (OMW_ADD_EXE_EXCLUDE_FROM_ALL)
set(OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE EXCLUDE_FROM_ALL)
endif (OMW_ADD_EXE_EXCLUDE_FROM_ALL)
qt_add_executable(${target} ${OMW_ADD_EXE_WIN32_VALUE} ${OMW_ADD_EXE_MACOSX_BUNDLE_VALUE} ${OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE} ${OMW_ADD_EXE_UNPARSED_ARGUMENTS})
if (MSVC)
set_target_properties(${target} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:${target}>")
endif (MSVC)
endmacro (openmw_add_qt_executable)
macro (get_generator_is_multi_config VALUE)
# TODO: make git version getter less dumb so everywhere that calls this macro can just call the function this calls instead
if (DEFINED generator_is_multi_config_var)
@@ -0,0 +1,13 @@
# Taken from vcpkg's z_vcpkg_escape_regex_control_characters
# MIT licence
# Someone should check this preamble is up to our usual high standards of legal compliance
function(escape_regex_control_characters out_var string)
if(ARGC GREATER "2")
message(FATAL_ERROR "escape_regex_control_characters passed extra arguments: ${ARGN}")
endif()
# OpenMW should use CMake 4.2's string(REGEX QUOTE out_var input) if available
# uses | instead of [] to avoid confusion; additionally, CMake doesn't support `]` in a `[]`
string(REGEX REPLACE [[\[|\]|\(|\)|\.|\+|\*|\^|\\|\$|\?|\|]] [[\\\0]] escaped_content "${string}")
set("${out_var}" "${escaped_content}" PARENT_SCOPE)
endfunction()
+22 -16
View File
@@ -684,22 +684,28 @@ target_compile_definitions(components PUBLIC
)
if(OSG_STATIC)
unset(_osg_plugins_static_files)
add_library(components_osg_plugins INTERFACE)
foreach(_plugin ${USED_OSG_PLUGINS})
string(TOUPPER ${_plugin} _plugin_uc)
if(OPENMW_USE_SYSTEM_OSG)
list(APPEND _osg_plugins_static_files ${${_plugin_uc}_LIBRARY})
else()
list(APPEND _osg_plugins_static_files $<TARGET_FILE:${${_plugin_uc}_LIBRARY}>)
target_link_libraries(components_osg_plugins INTERFACE $<TARGET_PROPERTY:${${_plugin_uc}_LIBRARY},LINK_LIBRARIES>)
add_dependencies(components_osg_plugins ${${_plugin_uc}_LIBRARY})
endif()
endforeach()
# We use --whole-archive because OSG plugins use registration.
get_whole_archive_options(_opts ${_osg_plugins_static_files})
target_link_options(components_osg_plugins INTERFACE ${_opts})
target_link_libraries(components components_osg_plugins ${COLLADA_DOM_LIBRARIES})
if(CMAKE_VERSION VERSION_LESS 3.24)
unset(_osg_plugins_static_files)
add_library(components_osg_plugins INTERFACE)
foreach(_plugin ${USED_OSG_PLUGINS})
string(TOUPPER ${_plugin} _plugin_uc)
if(OPENMW_USE_SYSTEM_OSG)
list(APPEND _osg_plugins_static_files ${${_plugin_uc}_LIBRARY})
else()
list(APPEND _osg_plugins_static_files $<TARGET_FILE:${${_plugin_uc}_LIBRARY}>)
target_link_libraries(components_osg_plugins INTERFACE $<TARGET_PROPERTY:${${_plugin_uc}_LIBRARY},LINK_LIBRARIES>)
add_dependencies(components_osg_plugins ${${_plugin_uc}_LIBRARY})
endif()
endforeach()
# We use --whole-archive because OSG plugins use registration.
get_whole_archive_options(_opts ${_osg_plugins_static_files})
target_link_options(components_osg_plugins INTERFACE ${_opts})
target_link_libraries(components components_osg_plugins)
else()
target_link_libraries(components "$<LINK_LIBRARY:WHOLE_ARCHIVE,${USED_OSG_PLUGINS}>")
endif()
target_link_libraries(components ${COLLADA_DOM_LIBRARIES})
if(OPENMW_USE_SYSTEM_OSG)
# OSG plugin pkgconfig files are missing these dependencies.