From 0c949db50607259099673c54dcb6f69ca73c1496 Mon Sep 17 00:00:00 2001 From: weirdbeardgame Date: Thu, 25 Jul 2024 10:04:28 -0700 Subject: [PATCH] CMake: Added PACKAGE_MODE option Set paths, add check in SetResourcesDir --- .gitignore | 1 + cmake/BuildParameters.cmake | 12 ++++++++++++ pcsx2/CMakeLists.txt | 10 ++++++++++ pcsx2/Pcsx2Config.cpp | 10 +++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3a0d598f8f..b59e873da7 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,4 @@ oprofile_data/ CMakeSettings.json /ci-artifacts/ /out/ +/.cache/ diff --git a/cmake/BuildParameters.cmake b/cmake/BuildParameters.cmake index 6b2df0502b..21d9940a04 100644 --- a/cmake/BuildParameters.cmake +++ b/cmake/BuildParameters.cmake @@ -1,6 +1,8 @@ # Extra preprocessor definitions that will be added to all pcsx2 builds set(PCSX2_DEFS "") +include(GNUInstallDirs) + #------------------------------------------------------------------------------- # Misc option #------------------------------------------------------------------------------- @@ -8,6 +10,7 @@ option(ENABLE_TESTS "Enables building the unit tests" ON) option(ENABLE_GSRUNNER "Enables building the GSRunner" OFF) option(LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else") option(USE_VTUNE "Plug VTUNE to profile GS JIT.") +option(PACKAGE_MODE "Use this option to ease packaging of PCSX2 (developer/distribution option)") #------------------------------------------------------------------------------- # Graphical option @@ -199,6 +202,15 @@ if(MSVC) ) endif() +if(PACKAGE_MODE) + file(RELATIVE_PATH relative_datadir ${CMAKE_INSTALL_FULL_BINDIR} ${CMAKE_INSTALL_FULL_DATADIR}/PCSX2) + + # Compile all source codes with those defines + list(APPEND PCSX2_DEFS + PCSX2_APP_DATADIR="${relative_datadir}") +endif() + + if(USE_VTUNE) list(APPEND PCSX2_DEFS ENABLE_VTUNE) endif() diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 03d0197a29..33d8411ff0 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -1282,6 +1282,16 @@ function(setup_main_executable target) install(CODE "file(WRITE \"${CMAKE_SOURCE_DIR}/bin/qt.conf\" \"[Paths]\\nPlugins = ./QtPlugins\")") endif() + + if (UNIX AND NOT APPLE) + if (PACKAGE_MODE) + install(TARGETS pcsx2-qt DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/resources DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/PCSX2) + else() + install(TARGETS pcsx2-qt DESTINATION ${CMAKE_SOURCE_DIR}/bin) + endif() + endif() + if(APPLE) if(CMAKE_GENERATOR MATCHES "Xcode") # If we're generating an xcode project, you can just add the shaders to the main pcsx2 target and xcode will deal with them properly diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 2edeef3bc2..5add74f552 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -1870,9 +1870,13 @@ void EmuFolders::SetAppRoot() bool EmuFolders::SetResourcesDirectory() { -#ifndef __APPLE__ - // On Windows/Linux, these are in the binary directory. - Resources = Path::Combine(AppRoot, "resources"); +#ifndef __APPLE__ + #ifndef PCSX2_APP_DATADIR + // On Windows/Linux, these are in the binary directory. + Resources = Path::Combine(AppRoot, "resources"); + #else + Resources = Path::Canonicalize(Path::Combine(AppRoot, PCSX2_APP_DATADIR "/resources")); + #endif #else // On macOS, this is in the bundle resources directory. Resources = Path::Canonicalize(Path::Combine(AppRoot, "../Resources"));