CI/Flatpak: Improve install behaviour

Use "standard" install path.
This commit is contained in:
Stenzek 2024-09-23 17:22:33 +10:00
parent dae38cb309
commit d67b826033
No known key found for this signature in database
11 changed files with 51 additions and 20 deletions

View File

@ -33,6 +33,7 @@ detect_cache_line_size()
# Build options. Depends on system attributes.
include(DuckStationBuildOptions)
include(DuckStationDependencies)
# Enable PIC on Linux, otherwise the builds do not support ASLR.
if(LINUX OR BSD)
@ -94,6 +95,18 @@ endif()
# Write binaries to a seperate directory.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
# Installation directories. If INSTALL_SELF_CONTAINED is set, everything goes
# into one directory, otherwise CMAKE_INSTALL_PREFIX/bin is used (for Flatpak).
if(ALLOW_INSTALL)
if(INSTALL_SELF_CONTAINED)
set(CMAKE_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}")
set(CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}")
else()
# Let GNUInstallDirs set the destinations.
include(GNUInstallDirs)
endif()
endif()
# Enable large file support on Linux 32-bit platforms.
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions("-D_FILE_OFFSET_BITS=64")
@ -112,7 +125,6 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Recursively include the source tree.
include(DuckStationDependencies)
add_subdirectory(dep)
add_subdirectory(src)

View File

@ -42,6 +42,8 @@ function(copy_base_translations target)
target_sources(${target} PRIVATE ${path})
if(APPLE)
set_source_files_properties(${path} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
elseif(ALLOW_INSTALL)
install(FILES "${path}" DESTINATION "${CMAKE_INSTALL_BINDIR}/translations")
else()
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${path}" "$<TARGET_FILE_DIR:${target}>/translations")

View File

@ -10,6 +10,7 @@ if(LINUX OR BSD)
option(ENABLE_X11 "Support X11 window system" ON)
option(ENABLE_WAYLAND "Support Wayland window system" ON)
option(ALLOW_INSTALL "Allow installation to CMAKE_INSTALL_PREFIX" OFF)
option(INSTALL_SELF_CONTAINED "Make self-contained install, i.e. everything in one directory" ON)
endif()
if(APPLE)
option(SKIP_POSTPROCESS_BUNDLE "Disable bundle post-processing, including Qt additions" OFF)

View File

@ -28,6 +28,13 @@ if(ALLOW_INSTALL)
message(WARNING "Install target is enabled. This will install all DuckStation files into:
${CMAKE_INSTALL_PREFIX}
It does **not** use the LSB subdirectories of bin, share, etc, so you should disable this option if it is set to /usr or /usr/local.")
if(INSTALL_SELF_CONTAINED)
message(STATUS "Creating self-contained install at ${CMAKE_INSTALL_PREFIX}")
else()
message(STATUS "Creating relative install at ${CMAKE_INSTALL_PREFIX}")
message(STATUS " CMAKE_INSTALL_BINDIR: ${CMAKE_INSTALL_BINDIR}")
endif()
endif()
if(NOT IS_SUPPORTED_COMPILER)

View File

@ -225,5 +225,5 @@ endfunction()
function(install_imported_dep_library name)
get_target_property(SONAME "${name}" IMPORTED_SONAME_RELEASE)
get_target_property(LOCATION "${name}" IMPORTED_LOCATION_RELEASE)
install(FILES "${LOCATION}" RENAME "${SONAME}" DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(FILES "${LOCATION}" RENAME "${SONAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endfunction()

View File

@ -6,14 +6,14 @@
FIND_PATH(
LIBBACKTRACE_INCLUDE_DIR backtrace.h
HINTS /usr/include /usr/local/include
HINTS "${CMAKE_PREFIX_PATH}/include" /usr/include /usr/local/include
${LIBBACKTRACE_PATH_INCLUDES}
)
FIND_LIBRARY(
LIBBACKTRACE_LIBRARY
NAMES backtrace
PATHS ${ADDITIONAL_LIBRARY_PATHS} ${LIBBACKTRACE_PATH_LIB}
PATHS "${CMAKE_PREFIX_PATH}/lib" "${CMAKE_PREFIX_PATH}/lib64" ${ADDITIONAL_LIBRARY_PATHS} ${LIBBACKTRACE_PATH_LIB}
)
include(FindPackageHandleStandardArgs)

View File

@ -10,7 +10,7 @@ build-options:
sources:
- type: git
url: "https://github.com/ianlancetaylor/libbacktrace.git"
commit: "ad106d5fdd5d960bd33fae1c48a351af567fd075"
commit: "86885d14049fab06ef8a33aac51664230ca09200"
cleanup:
- /include
- /lib/*.a

View File

@ -43,7 +43,6 @@ modules:
- name: duckstation
buildsystem: cmake-ninja
builddir: true
no-make-install: true
build-options:
# Preserve debug information, it is needed for backtraces.
strip: false
@ -60,7 +59,11 @@ modules:
- "-DCMAKE_BUILD_TYPE=Release"
# We're not running tests as part of the flatpak build.
- '-DBUILD_TESTS=OFF'
- "-DBUILD_TESTS=OFF"
# Install to /app/bin, use /app/lib for dependencies.
- "-DALLOW_INSTALL=ON"
- "-DINSTALL_SELF_CONTAINED=OFF"
# Make sure we're using ThinLTO.
- "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON"
@ -74,9 +77,6 @@ modules:
path: ../..
post-install:
# Copy the binary distribution.
- "cp -a bin \"${FLATPAK_DEST}\""
# Manually copy desktop file/metadata, it's not done as part of the regular build.
- >-
install -Dm644

View File

@ -215,7 +215,9 @@ function(add_core_resources target)
add_resources(${target} ${path} ${CMAKE_SOURCE_DIR}/data/resources/)
endforeach()
if(ALLOW_INSTALL)
install_imported_dep_library(cpuinfo::cpuinfo)
install(DIRECTORY "$<TARGET_FILE_DIR:${target}>/resources" DESTINATION "${CMAKE_INSTALL_PREFIX}")
if(INSTALL_SELF_CONTAINED)
install_imported_dep_library(cpuinfo::cpuinfo)
endif()
install(DIRECTORY "$<TARGET_FILE_DIR:${target}>/resources" DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
endfunction()

View File

@ -250,7 +250,7 @@ endif()
if(ALLOW_INSTALL)
# Install main binary.
install(TARGETS duckstation-qt RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(TARGETS duckstation-qt RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
# Compile qrc to a binary file.
@ -276,7 +276,7 @@ if(NOT APPLE)
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${QM_FILE}" "${QM_OUTPUT_DIR}/${QM_FILE_NAME}")
if(ALLOW_INSTALL)
install(FILES "${QM_FILE}" DESTINATION "${CMAKE_INSTALL_PREFIX}/translations")
install(FILES "${QM_FILE}" DESTINATION "${CMAKE_INSTALL_BINDIR}/translations")
endif()
endforeach()
else()

View File

@ -308,12 +308,19 @@ function(add_util_resources target)
set_source_files_properties(${target} PRIVATE ${version_lib} PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks)
endforeach()
elseif(ALLOW_INSTALL)
# Ensure we look for dependency libraries in the installation directory.
set_target_properties(${target} PROPERTIES INSTALL_RPATH "$ORIGIN")
if(INSTALL_SELF_CONTAINED)
# Ensure we look for dependency libraries in the installation directory.
set_target_properties(${target} PROPERTIES INSTALL_RPATH "$ORIGIN")
# Copy dependency libraries to installation directory.
install_imported_dep_library(Shaderc::shaderc_shared)
install_imported_dep_library(spirv-cross-c-shared)
install_imported_dep_library(SoundTouch::SoundTouchDLL)
# Copy dependency libraries to installation directory.
install_imported_dep_library(Shaderc::shaderc_shared)
install_imported_dep_library(spirv-cross-c-shared)
install_imported_dep_library(SoundTouch::SoundTouchDLL)
install_imported_dep_library(lunasvg::lunasvg)
else()
# Prevent CMake from overriding the RPATH in the binary. i.e. use the build locations.
# This is needed for Flatpak builds, since the libs are in /app.
set_target_properties(${target} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
endif()
endfunction()