Skip to content

Commit

Permalink
Fix shader bundling, use idiomatic data prefix, create install compon…
Browse files Browse the repository at this point in the history
…ents, update dependencies
  • Loading branch information
jcm93 committed Nov 7, 2024
1 parent 3114227 commit 894bbe5
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 45 deletions.
1 change: 1 addition & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions cmake/finders/Findslang_shaders.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion cmake/linux/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 5 additions & 5 deletions deps.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
},
Expand Down
42 changes: 24 additions & 18 deletions desktop-ui/cmake/os-linux.cmake
Original file line number Diff line number Diff line change
@@ -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}/$<CONFIG>/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}/$<CONFIG>/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
Expand All @@ -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
Expand All @@ -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
)
28 changes: 16 additions & 12 deletions desktop-ui/cmake/os-macos.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
"$<TARGET_BUNDLE_CONTENT_DIR:desktop-ui>/Resources/Shaders/"
WORKING_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:desktop-ui>"
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}"
"$<TARGET_BUNDLE_CONTENT_DIR:desktop-ui>/Resources/Shaders/"
WORKING_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:desktop-ui>"
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
Expand Down
20 changes: 11 additions & 9 deletions desktop-ui/cmake/os-windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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/$<IF:$<BOOL:${MULTI_CONFIG}>,$<CONFIG>,>/Shaders/"
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_SOURCE_DIR}/.deps/ares-deps-windows-${arch}/lib/slang-shaders/"
"${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$<IF:$<BOOL:${MULTI_CONFIG}>,$<CONFIG>,>/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/$<IF:$<BOOL:${MULTI_CONFIG}>,$<CONFIG>,>/Shaders/"
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${slang_shaders_LOCATION}"
"${ARES_EXECUTABLE_DESTINATION}/desktop-ui/$<IF:$<BOOL:${MULTI_CONFIG}>,$<CONFIG>,>/Shaders/"
WORKING_DIRECTORY "."
COMMENT "Copying slang shaders to rundir"
)
endif()
endif()

if(EXISTS "${CMAKE_SOURCE_DIR}/mia/Database")
Expand Down
12 changes: 12 additions & 0 deletions nall/cmake/os-linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions nall/cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ target_sources(
shared-pointer.hpp
stdint.hpp
string.hpp
stringize.hpp
suffix-array.hpp
terminal.cpp
terminal.hpp
Expand Down
4 changes: 4 additions & 0 deletions nall/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
Expand Down

0 comments on commit 894bbe5

Please sign in to comment.