From e03076c6fffb75a791f10f73ad0ff06d9aea9825 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 11 Dec 2021 23:51:35 -0600 Subject: [PATCH] CMake: Fix macOS resource packaging Previously was just putting in empty folders --- CMakeLists.txt | 2 -- pcsx2/CMakeLists.txt | 40 +++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36124fc1b7..c7d9e9dbc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,8 +58,6 @@ endif() # Install some files to ease package creation if(PACKAGE_MODE) - INSTALL(DIRECTORY "${CMAKE_SOURCE_DIR}/bin/resources" DESTINATION "${CMAKE_INSTALL_DATADIR}/PCSX2") - # set categories depending on system/distribution in pcsx2.desktop if(openSUSE) set(PCSX2_MENU_CATEGORIES "System;Emulator;") diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 4d931ec54c..e44e51f1cc 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -1469,6 +1469,28 @@ if(COMMAND target_precompile_headers) target_precompile_headers(PCSX2_FLAGS INTERFACE PrecompiledHeader.h) endif() +# Copy resource files if needed +function(pcsx2_resource path basedir) + get_filename_component(dir ${path} DIRECTORY) + file(RELATIVE_PATH subdir ${basedir} ${dir}) + if(APPLE) + target_sources(PCSX2 PRIVATE ${path}) + set_source_files_properties(${path} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/${subdir}) + elseif(PACKAGE_MODE) + install(FILES ${path} DESTINATION ${CMAKE_INSTALL_DATADIR}/PCSX2/resources/${subdir}) + endif() + source_group(Resources/${subdir} FILES ${path}) +endfunction() + +file(GLOB_RECURSE RESOURCE_FILES ${CMAKE_SOURCE_DIR}/bin/resources/*) +foreach(path IN LISTS RESOURCE_FILES) + get_filename_component(file ${path} NAME) + if("${file}" MATCHES "^\\.") # Don't copy macOS garbage (mainly Finder's .DS_Store files) into application + continue() + endif() + pcsx2_resource(${path} ${CMAKE_SOURCE_DIR}/bin/resources/) +endforeach() + if (APPLE) # MacOS defaults to having a maximum protection of the __DATA segment of rw (non-executable) # We have a bunch of page-sized arrays in bss that we use for jit @@ -1481,22 +1503,7 @@ if (APPLE) OUTPUT_NAME PCSX2 ) - target_sources(PCSX2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/gui/Resources/PCSX2.icns") - set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/gui/Resources/PCSX2.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - - # Add in shaders and other resources. - file(GLOB resource_files "${CMAKE_SOURCE_DIR}/bin/resources/*") - foreach(file ${resource_files}) - target_sources(PCSX2 PRIVATE "${file}") - set_source_files_properties("${file}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - endforeach() - - # Add in shaders and other resources. - file(GLOB resource_files "${CMAKE_SOURCE_DIR}/bin/resources/*") - foreach(file ${resource_files}) - target_sources(PCSX2 PRIVATE "${file}") - set_source_files_properties("${file}" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - endforeach() + pcsx2_resource(${CMAKE_CURRENT_SOURCE_DIR}/gui/Resources/PCSX2.icns ${CMAKE_CURRENT_SOURCE_DIR}/gui/Resources) # If they say to skip postprocess bundle, leave the target in but make it so they have # to manually run it @@ -1541,5 +1548,4 @@ source_group(System/Ps2/USB REGULAR_EXPRESSION USB/*) source_group(Resources/GUI FILES ${pcsx2GuiResources}) source_group(Resources/PAD FILES ${pcsx2PADResources}) source_group(Resources/Recording FILES ${pcsx2RecordingVirtualPadResources}) -source_group(Resources FILES gui/Resources/PCSX2.icns) source_group(Resources REGULAR_EXPRESSION ${CMAKE_CURRENT_BINARY_DIR}/*)