From 894bbe5bc025468137e3b9003cf8c68b8c960db9 Mon Sep 17 00:00:00 2001 From: jcm <6864788+jcm93@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:20:31 -0600 Subject: [PATCH] Fix shader bundling, use idiomatic data prefix, create install components, update dependencies --- cmake/CMakeLists.txt | 1 + cmake/finders/Findslang_shaders.cmake | 60 +++++++++++++++++++++++++++ cmake/linux/helpers.cmake | 2 +- deps.json | 10 ++--- desktop-ui/cmake/os-linux.cmake | 42 +++++++++++-------- desktop-ui/cmake/os-macos.cmake | 28 +++++++------ desktop-ui/cmake/os-windows.cmake | 20 +++++---- nall/cmake/os-linux.cmake | 12 ++++++ nall/cmake/sources.cmake | 1 + nall/path.cpp | 4 ++ 10 files changed, 135 insertions(+), 45 deletions(-) create mode 100644 cmake/finders/Findslang_shaders.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 586c6c3a2d..ee7a9cc3d3 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources( common/osconfig.cmake common/versionconfig.cmake finders/Findlibrashader.cmake + finders/Findslang_shaders.cmake finders/FindMoltenVK.cmake finders/FindSDL.cmake finders/FindGTK.cmake diff --git a/cmake/finders/Findslang_shaders.cmake b/cmake/finders/Findslang_shaders.cmake new file mode 100644 index 0000000000..a4151c26d2 --- /dev/null +++ b/cmake/finders/Findslang_shaders.cmake @@ -0,0 +1,60 @@ +#[=======================================================================[.rst: +Findlibrashader +------- + +Finds the slang-shaders library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + +``libretro::slang_shaders`` + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``slang_shaders_FOUND`` + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``slang_shaders_LOCATION`` + The directory containing the libretro shader collection. + +#]=======================================================================] + +find_path( + slang_shaders_LOCATION + NAMES bilinear.slangp nearest.slangp + PATHS /usr/share/libretro/shaders/shaders_slang /usr/local/share/libretro/shaders/shaders_slang ${CMAKE_PREFIX_PATH}/share/libretro/shaders/shaders_slang + DOC "slang-shaders collection location" +) + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(SLANG_ERROR_REASON "Ensure that ares-deps are provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(SLANG_ERROR_REASON "Ensure slang-shaders are installed in local data paths or that ares-deps are provided as part of CMAKE_PREFIX_PATH.") +endif() + +find_package_handle_standard_args( + slang_shaders + REQUIRED_VARS slang_shaders_LOCATION + REASON_FAILURE_MESSAGE "${SLANG_ERROR_REASON}" +) + +if(NOT TARGET libretro::slang_shaders) + if(slang_shaders_LOCATION) + add_library(slang_shaders INTERFACE) + set_target_properties( + slang_shaders + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${slang_shaders_LOCATION}" + ) + add_library(libretro::slang_shaders ALIAS slang_shaders) + endif() +endif() diff --git a/cmake/linux/helpers.cmake b/cmake/linux/helpers.cmake index 62b78332f0..d811810647 100644 --- a/cmake/linux/helpers.cmake +++ b/cmake/linux/helpers.cmake @@ -19,6 +19,6 @@ function(ares_configure_executable target) VERBATIM ) - install(TARGETS ${target} RUNTIME DESTINATION "${ARES_INSTALL_EXECUTABLE_DESTINATION}" COMPONENT Runtime) + install(TARGETS ${target} RUNTIME DESTINATION "${ARES_INSTALL_EXECUTABLE_DESTINATION}" COMPONENT ${target}) endif() endfunction() diff --git a/deps.json b/deps.json index d26bacaab4..8bbd8a931a 100644 --- a/deps.json +++ b/deps.json @@ -1,14 +1,14 @@ { "dependencies": { "prebuilt": { - "version": "sdlwin", + "version": "main", "baseUrl": "https://github.com/jcm93/ares-deps/releases/download", "label": "Pre-Built ares-deps", "hashes": { - "linux-universal": "015de82d6f2b6811246015250148dde680853f96b0f71b349b7e78789f3ea679", - "macos-universal": "d3eb1425035ca3d0974dd81c79b2db0809c5e694f3abb05eddceff45b55f4578", - "windows-arm64": "ee87c169166443b0f8c8cdeafa0fa98ab48a593c8b97f9533b3c9e9bf2bb42ef", - "windows-x64": "30f3c1f7eccaf049be542d10c3277574782523cb9d9d6befed67e6ba1c96c621" + "linux-universal": "b632f511b2c20eef4089263808b474b8c0b6af6497e11437cffb91ebfdb89238", + "macos-universal": "7490e7cac9f37ecb8f9d8b79a19e2eb0d274973db1abfe733859a1ec0b614b81", + "windows-arm64": "a1065863246cdd60e21a9cdae14149ce401e7ff413f544c0209a0fce76fb7869", + "windows-x64": "e40fd5cb63b45b68ec6a23e1400de85fd3c3f1faac340d94480022fc89d23d49" } } }, diff --git a/desktop-ui/cmake/os-linux.cmake b/desktop-ui/cmake/os-linux.cmake index 06915def79..c102c1b03f 100644 --- a/desktop-ui/cmake/os-linux.cmake +++ b/desktop-ui/cmake/os-linux.cmake @@ -1,20 +1,26 @@ +option(ARES_BUNDLE_SHADERS "Add slang-shaders to the ares resources folder" ON) +mark_as_advanced(ARES_BUNDLE_SHADERS) + # Stage and install slang shaders if(ARES_ENABLE_LIBRASHADER) - add_custom_command( - TARGET desktop-ui - POST_BUILD - COMMAND - cp -R "${CMAKE_SOURCE_DIR}/.deps/ares-deps-linux-universal/lib/slang-shaders/." - "${ARES_BUILD_OUTPUT_DIR}/$/Shaders" - COMMENT "Copying slang shaders to staging directory" - ) - - install( - DIRECTORY "${CMAKE_SOURCE_DIR}/.deps/ares-deps-linux-universal/lib/slang-shaders/" - DESTINATION "${ARES_INSTALL_DATA_DESTINATION}/Shaders" - USE_SOURCE_PERMISSIONS - COMPONENT Runtime - ) + if(TARGET libretro::slang_shaders) + add_custom_command( + TARGET desktop-ui + POST_BUILD + COMMAND + cp -R "${slang_shaders_LOCATION}/." + "${ARES_BUILD_OUTPUT_DIR}/$/Shaders" + COMMENT "Copying slang shaders to staging directory" + ) + if(ARES_BUNDLE_SHADERS) + install( + DIRECTORY "${slang_shaders_LOCATION}" + DESTINATION "${ARES_INSTALL_DATA_DESTINATION}/Shaders" + USE_SOURCE_PERMISSIONS + COMPONENT desktop-ui + ) + endif() + endif() endif() # Stage and install mia database @@ -32,7 +38,7 @@ install( DIRECTORY "${CMAKE_SOURCE_DIR}/mia/Database/" DESTINATION "${ARES_INSTALL_DATA_DESTINATION}/Database" USE_SOURCE_PERMISSIONS - COMPONENT Runtime + COMPONENT desktop-ui ) # Stage and install icon, .desktop file @@ -51,11 +57,11 @@ add_custom_command( install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" - COMPONENT Runtime + COMPONENT desktop-ui ) install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/resource/ares.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" - COMPONENT Runtime + COMPONENT desktop-ui ) diff --git a/desktop-ui/cmake/os-macos.cmake b/desktop-ui/cmake/os-macos.cmake index 1fbe969380..3615508111 100644 --- a/desktop-ui/cmake/os-macos.cmake +++ b/desktop-ui/cmake/os-macos.cmake @@ -1,5 +1,7 @@ target_sources(desktop-ui PRIVATE cmake/os-macos.cmake) +find_package(slang_shaders) + set_target_xcode_properties( desktop-ui PROPERTIES PRODUCT_BUNDLE_IDENTIFIER com.ares-emulator.ares @@ -33,13 +35,13 @@ target_add_resource(desktop-ui "${CMAKE_CURRENT_SOURCE_DIR}/resource/Assets.xcas function(target_install_shaders target) message(DEBUG "Installing shaders for target ${target}...") - if(EXISTS "${CMAKE_SOURCE_DIR}/.deps/ares-deps-macos-universal/lib/slang-shaders") - file(GLOB_RECURSE data_files "${CMAKE_SOURCE_DIR}/.deps/ares-deps-macos-universal/lib/slang-shaders/*") + if(EXISTS "${slang_shaders_LOCATION}") + file(GLOB_RECURSE data_files "${slang_shaders_LOCATION}/*") foreach(data_file IN LISTS data_files) cmake_path( RELATIVE_PATH data_file - BASE_DIRECTORY "${CMAKE_SOURCE_DIR}/.deps/ares-deps-macos-universal/lib/slang-shaders/" + BASE_DIRECTORY "${slang_shaders_LOCATION}" OUTPUT_VARIABLE relative_path ) cmake_path(GET relative_path PARENT_PATH relative_path) @@ -71,15 +73,17 @@ endfunction() # Add slang-shaders as a post-build script so we don't have an exceedingly long "Copy Files" phase if(ARES_ENABLE_LIBRASHADER) - add_custom_command( - TARGET desktop-ui - POST_BUILD - COMMAND - ditto "${CMAKE_SOURCE_DIR}/.deps/ares-deps-macos-universal/lib/slang-shaders" - "$/Resources/Shaders/" - WORKING_DIRECTORY "$" - COMMENT "Copying slang shaders to app bundle" - ) + if(TARGET libretro::slang_shaders) + add_custom_command( + TARGET desktop-ui + POST_BUILD + COMMAND + ditto "${slang_shaders_LOCATION}" + "$/Resources/Shaders/" + WORKING_DIRECTORY "$" + COMMENT "Copying slang shaders to app bundle" + ) + endif() endif() # Can't use target_add_resource for this since we only want it to occur in debug configurations diff --git a/desktop-ui/cmake/os-windows.cmake b/desktop-ui/cmake/os-windows.cmake index 2eec28ff93..a9c5931420 100644 --- a/desktop-ui/cmake/os-windows.cmake +++ b/desktop-ui/cmake/os-windows.cmake @@ -3,15 +3,17 @@ target_sources(desktop-ui PRIVATE resource/ares.rc resource/ares.Manifest) set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT desktop-ui) if(ARES_ENABLE_LIBRASHADER) - add_custom_command( - TARGET desktop-ui - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E make_directory "${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$,$,>/Shaders/" - COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/.deps/ares-deps-windows-${arch}/lib/slang-shaders/" - "${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$,$,>/Shaders/" - WORKING_DIRECTORY "." - COMMENT "Copying slang shaders to rundir" - ) + if(TARGET libretro::slang_shaders) + add_custom_command( + TARGET desktop-ui + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E make_directory "${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$,$,>/Shaders/" + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${slang_shaders_LOCATION}" + "${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$,$,>/Shaders/" + WORKING_DIRECTORY "." + COMMENT "Copying slang shaders to rundir" + ) + endif() endif() if(EXISTS "${CMAKE_SOURCE_DIR}/mia/Database") diff --git a/nall/cmake/os-linux.cmake b/nall/cmake/os-linux.cmake index 12b719c99c..a9066a049d 100644 --- a/nall/cmake/os-linux.cmake +++ b/nall/cmake/os-linux.cmake @@ -7,3 +7,15 @@ target_sources( xorg/guard.hpp xorg/xorg.hpp ) + +if(DEFINED ARES_PREFIX) + + target_compile_definitions(nall PRIVATE "ARES_PREFIX=${ARES_PREFIX}") + + install(CODE " + if(NOT \"${CMAKE_INSTALL_PREFIX}\" STREQUAL \"${ARES_PREFIX}\") + message(FATAL_ERROR \" nall was configured and built with the data directory prefix ${ARES_PREFIX}, but the chosen CMake install prefix, ${CMAKE_INSTALL_PREFIX}, does not match. This is considered an error because it makes it unlikely for the program to properly locate shared resources in the shared data directory.\") + endif() + ") + +endif() diff --git a/nall/cmake/sources.cmake b/nall/cmake/sources.cmake index 1e591e38a6..bcee4409d4 100644 --- a/nall/cmake/sources.cmake +++ b/nall/cmake/sources.cmake @@ -77,6 +77,7 @@ target_sources( shared-pointer.hpp stdint.hpp string.hpp + stringize.hpp suffix-array.hpp terminal.cpp terminal.hpp diff --git a/nall/path.cpp b/nall/path.cpp index 96adaa0fd4..eeb9185a44 100644 --- a/nall/path.cpp +++ b/nall/path.cpp @@ -144,7 +144,11 @@ NALL_HEADER_INLINE auto sharedData() -> string { #elif defined(PLATFORM_MACOS) string result = "/Library/Application Support/"; #else +#if defined(ARES_PREFIX) string result = stringize(ARES_PREFIX/share/); +#else + string result = "/usr/local/share"; +#endif #endif if(!result) result = "."; if(!result.endsWith("/")) result.append("/");