From d67b826033b1b41a550bd901cf0008b74ca312b7 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 23 Sep 2024 17:22:33 +1000 Subject: [PATCH] CI/Flatpak: Improve install behaviour Use "standard" install path. --- CMakeLists.txt | 14 +++++++++++++- CMakeModules/CopyBaseTranslations.cmake | 2 ++ CMakeModules/DuckStationBuildOptions.cmake | 1 + CMakeModules/DuckStationBuildSummary.cmake | 7 +++++++ CMakeModules/DuckStationUtils.cmake | 2 +- CMakeModules/FindLibbacktrace.cmake | 4 ++-- scripts/flatpak/modules/21-libbacktrace.yaml | 2 +- .../flatpak/org.duckstation.DuckStation.yaml | 10 +++++----- src/core/CMakeLists.txt | 6 ++++-- src/duckstation-qt/CMakeLists.txt | 4 ++-- src/util/CMakeLists.txt | 19 +++++++++++++------ 11 files changed, 51 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27832e706..bdc61007d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeModules/CopyBaseTranslations.cmake b/CMakeModules/CopyBaseTranslations.cmake index b8b37e46d..07725304b 100644 --- a/CMakeModules/CopyBaseTranslations.cmake +++ b/CMakeModules/CopyBaseTranslations.cmake @@ -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}" "$/translations") diff --git a/CMakeModules/DuckStationBuildOptions.cmake b/CMakeModules/DuckStationBuildOptions.cmake index 6cdf94e04..a89fefce8 100644 --- a/CMakeModules/DuckStationBuildOptions.cmake +++ b/CMakeModules/DuckStationBuildOptions.cmake @@ -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) diff --git a/CMakeModules/DuckStationBuildSummary.cmake b/CMakeModules/DuckStationBuildSummary.cmake index b4e570083..a2e91e8b7 100644 --- a/CMakeModules/DuckStationBuildSummary.cmake +++ b/CMakeModules/DuckStationBuildSummary.cmake @@ -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) diff --git a/CMakeModules/DuckStationUtils.cmake b/CMakeModules/DuckStationUtils.cmake index 8cb4c85f2..bd6d1add7 100644 --- a/CMakeModules/DuckStationUtils.cmake +++ b/CMakeModules/DuckStationUtils.cmake @@ -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() diff --git a/CMakeModules/FindLibbacktrace.cmake b/CMakeModules/FindLibbacktrace.cmake index 930504a78..39f3efddc 100644 --- a/CMakeModules/FindLibbacktrace.cmake +++ b/CMakeModules/FindLibbacktrace.cmake @@ -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) diff --git a/scripts/flatpak/modules/21-libbacktrace.yaml b/scripts/flatpak/modules/21-libbacktrace.yaml index bb4e12d80..643a3b645 100644 --- a/scripts/flatpak/modules/21-libbacktrace.yaml +++ b/scripts/flatpak/modules/21-libbacktrace.yaml @@ -10,7 +10,7 @@ build-options: sources: - type: git url: "https://github.com/ianlancetaylor/libbacktrace.git" - commit: "ad106d5fdd5d960bd33fae1c48a351af567fd075" + commit: "86885d14049fab06ef8a33aac51664230ca09200" cleanup: - /include - /lib/*.a diff --git a/scripts/flatpak/org.duckstation.DuckStation.yaml b/scripts/flatpak/org.duckstation.DuckStation.yaml index 7f4815bce..1855db531 100644 --- a/scripts/flatpak/org.duckstation.DuckStation.yaml +++ b/scripts/flatpak/org.duckstation.DuckStation.yaml @@ -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 diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 76eff0496..94ec08862 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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 "$/resources" DESTINATION "${CMAKE_INSTALL_PREFIX}") + if(INSTALL_SELF_CONTAINED) + install_imported_dep_library(cpuinfo::cpuinfo) + endif() + install(DIRECTORY "$/resources" DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() endfunction() diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index 2ef7ef404..fbf9ae3f4 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -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() diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index c26460c78..085dcef60 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -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()