diff --git a/cmake/SystemDeps.cmake b/cmake/SystemDeps.cmake index e08c7b504..c679aaab3 100644 --- a/cmake/SystemDeps.cmake +++ b/cmake/SystemDeps.cmake @@ -9,6 +9,8 @@ if(NOT ANYPS5_USE_SYSTEM_DEPS) return() endif() +include(CheckCXXSourceCompiles) + find_package(SDL2 CONFIG REQUIRED) if(NOT TARGET SDL2::SDL2) message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: SDL2 was found but does not provide SDL2::SDL2") @@ -19,6 +21,17 @@ get_target_property(ANYPS5_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTO if(NOT ANYPS5_SDL2_INCLUDE_DIR) message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: SDL2::SDL2 exposes no INTERFACE_INCLUDE_DIRECTORIES") endif() +set(ANYPS5_SDL2_PROBE_INCLUDES ${ANYPS5_SDL2_INCLUDE_DIR}) +foreach(_dir IN LISTS ANYPS5_SDL2_INCLUDE_DIR) + list(APPEND ANYPS5_SDL2_PROBE_INCLUDES "${_dir}/SDL2") +endforeach() +list(REMOVE_DUPLICATES ANYPS5_SDL2_PROBE_INCLUDES) +set(CMAKE_REQUIRED_INCLUDES ${ANYPS5_SDL2_PROBE_INCLUDES}) +check_cxx_source_compiles("#include \"SDL_config.h\"\n#ifndef SDL_JOYSTICK_HIDAPI\n#error SDL_JOYSTICK_HIDAPI is not defined\n#endif\nint main() { return 0; }" ANYPS5_SDL2_HAS_HIDAPI) +unset(CMAKE_REQUIRED_INCLUDES) +if(NOT ANYPS5_SDL2_HAS_HIDAPI) + message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: the system SDL2 does not define SDL_JOYSTICK_HIDAPI, so a DualSense gets no light bar, touchpad or trigger effects and the disk audio driver does not preserve the requested format; sdl2-compat (SDL3 underneath) and SDL2 builds with HIDAPI disabled both fail the pad and audio tests; install a real SDL2 2.x built with HIDAPI") +endif() find_package(Freetype REQUIRED) if(NOT TARGET Freetype::Freetype) @@ -35,7 +48,6 @@ get_target_property(ANYPS5_VULKAN_HEADERS_INCLUDE_DIR Vulkan::Headers INTERFACE_ if(NOT ANYPS5_VULKAN_HEADERS_INCLUDE_DIR) message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: Vulkan::Headers exposes no INTERFACE_INCLUDE_DIRECTORIES") endif() -include(CheckCXXSourceCompiles) set(CMAKE_REQUIRED_INCLUDES ${ANYPS5_VULKAN_HEADERS_INCLUDE_DIR}) check_cxx_source_compiles("#include \nint main() { VkPhysicalDeviceMaintenance8FeaturesKHR features{}; (void)features; return 0; }" ANYPS5_VULKAN_HAS_MAINTENANCE8) unset(CMAKE_REQUIRED_INCLUDES) @@ -79,8 +91,16 @@ set_target_properties(glslang-standalone PROPERTIES IMPORTED_LOCATION "${ANYPS5_ if(ANYPS5_ENABLE_SPIRV_TOOLS) find_package(SPIRV-Tools-opt CONFIG REQUIRED) - if(NOT TARGET SPIRV-Tools-opt OR NOT TARGET SPIRV-Tools-static) - message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: SPIRV-Tools was found but does not provide SPIRV-Tools-opt and SPIRV-Tools-static") + if(NOT TARGET SPIRV-Tools-opt) + message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: SPIRV-Tools was found but does not provide SPIRV-Tools-opt") + endif() + if(NOT TARGET SPIRV-Tools-static) + if(TARGET SPIRV-Tools) + add_library(SPIRV-Tools-static INTERFACE) + target_link_libraries(SPIRV-Tools-static INTERFACE SPIRV-Tools) + else() + message(FATAL_ERROR "ANYPS5_USE_SYSTEM_DEPS: SPIRV-Tools was found but provides neither SPIRV-Tools-static nor SPIRV-Tools") + endif() endif() endif() diff --git a/docs/dev/BUILD.md b/docs/dev/BUILD.md index 1c30aa947..50e7023fe 100644 --- a/docs/dev/BUILD.md +++ b/docs/dev/BUILD.md @@ -75,7 +75,7 @@ Build configuration parameters: SDL and FreeType settings forced by the root `CMakeLists.txt` cannot be overridden with `-D`. -With `ANYPS5_USE_SYSTEM_DEPS=ON` those libraries come from the system (on Debian and Ubuntu: `libsdl2-dev`, `libfreetype-dev`, `libvulkan-dev`, `spirv-headers`, `glslang-dev`, `glslang-tools` and `spirv-tools`). A missing package, or Vulkan-Headers older than 1.4.310 (the agc driver uses `VK_KHR_maintenance8`), fails the configure with an error and never falls back to the submodule. The prx libraries are shared objects, so SDL2 is linked from the system as a shared library; the default build keeps its own static SDL2. `ffmpeg-core`, `libjpeg-turbo`, `stb`, `VulkanMemoryAllocator` and `LibAtrac9` always stay bundled and still need `git submodule update --init`. +With `ANYPS5_USE_SYSTEM_DEPS=ON` those libraries come from the system (on Debian and Ubuntu: `libsdl2-dev`, `libfreetype-dev`, `libvulkan-dev`, `spirv-headers`, `glslang-dev`, `glslang-tools` and `spirv-tools`). A missing package, Vulkan-Headers older than 1.4.310 (the agc driver uses `VK_KHR_maintenance8`), or an SDL2 without the HIDAPI joystick driver (sdl2-compat over SDL3, or a build with HIDAPI disabled, which breaks the pad and disk-audio tests), fails the configure with an error and never falls back to the submodule. The forced SDL and FreeType settings from the root `CMakeLists.txt` do not apply with the flag ON: the system SDL2 comes with whatever its distribution enabled. The prx libraries are shared objects, so SDL2 is linked from the system as a shared library; the default build keeps its own static SDL2. `ffmpeg-core`, `libjpeg-turbo`, `stb`, `VulkanMemoryAllocator` and `LibAtrac9` always stay bundled and still need `git submodule update --init`. ## Write watch tests