Files
xone_macos/CMakeLists.txt
T
portersky aab44fd7aa fix: use class matching and double-pointer refs
IOServiceMatching on idVendor/idProduct numbers is unreliable (single-key
matches fail), so match the IOUSBDevice class and filter VID/PID in user
space via the idVendor/idProduct properties.

QI'd interfaces are double-pointer references: *ref is the interface
struct and methods are called as (*ref)->Method(ref, ...). The old code
treated the slot as the struct and crashed on the first method call.

Verified on a physical dongle (PID 0x02E6): probe opens the device,
enumerates EP 0x04 IN/OUT and EP 0x05 IN, and register reads via
DeviceRequest return valid values (MT7612 ASIC version).

Co-Authored-By: qwen3.8-27b@q2_k_xl: fixed USB transport for hardware
2026-08-17 16:06:53 +02:00

115 lines
4.5 KiB
CMake

# CMake supports Swift only with the Ninja and Xcode generators.
if(NOT CMAKE_GENERATOR MATCHES "^(Ninja|Xcode)$")
message(FATAL_ERROR
"This project requires the Ninja or Xcode generator for Swift support.\n"
" Configure with: cmake -S . -B build -G Ninja")
endif()
cmake_minimum_required(VERSION 3.21)
project(xone_macos VERSION 0.1.4 LANGUAGES CXX Swift)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Add the deps directory to the module path
# Required for find_package injection
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps")
# Platform and compiler detection
include(Platform)
include(Flags)
include(Sanitizers)
# ==============================================================================
# Module libraries (bottom-up layering, mirrors medusalix/xone structure)
# ==============================================================================
# USB transport (IOKit / IOUSBFamily)
add_library(xone_usb STATIC
"src/usb/usb_transport.cpp"
)
target_include_directories(xone_usb PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_usb PRIVATE cxx_std_23)
target_compile_options(xone_usb PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_usb PRIVATE ${BASE_DEFINITIONS})
find_library(XONE_IOKIT IOKit)
find_library(XONE_COREFOUNDATION CoreFoundation)
target_link_libraries(xone_usb PUBLIC "${XONE_IOKIT}" "${XONE_COREFOUNDATION}")
# Auth + crypto (AES-CCMP key setup, ECDH, RSA — port from auth/)
add_library(xone_auth STATIC
"src/auth/crypto.cpp"
"src/auth/auth.cpp"
)
target_include_directories(xone_auth PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_auth PRIVATE cxx_std_23)
target_compile_options(xone_auth PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_auth PRIVATE ${BASE_DEFINITIONS})
find_library(XONE_SECURITY Security)
find_library(XONE_COREFOUNDATION CoreFoundation)
target_link_libraries(xone_auth PUBLIC "${XONE_SECURITY}" "${XONE_COREFOUNDATION}")
# MT76 chip protocol (firmware load, EFUSE, radio init, beacons)
add_library(xone_mt76 STATIC
"src/mt76/mt76.cpp"
)
target_include_directories(xone_mt76 PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_mt76 PRIVATE cxx_std_23)
target_compile_options(xone_mt76 PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_mt76 PRIVATE ${BASE_DEFINITIONS})
target_link_libraries(xone_mt76 PUBLIC xone_usb)
# GIP protocol (client lifecycle, handshake, status reports)
add_library(xone_gip STATIC
"src/gip/protocol.cpp"
)
target_include_directories(xone_gip PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_gip PRIVATE cxx_std_23)
target_compile_options(xone_gip PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_gip PRIVATE ${BASE_DEFINITIONS})
target_link_libraries(xone_gip PUBLIC xone_auth xone_mt76)
# Virtual HID gamepad presentation
add_library(xone_hid STATIC
"src/hid/hid_device.cpp"
)
target_include_directories(xone_hid PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_hid PRIVATE cxx_std_23)
target_compile_options(xone_hid PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_hid PRIVATE ${BASE_DEFINITIONS})
target_link_libraries(xone_hid PUBLIC xone_gip)
# C ABI bridge consumed by the Swift app and the test suite
add_library(xone_api STATIC
"src/app/api.cpp"
)
target_include_directories(xone_api PUBLIC "${CMAKE_SOURCE_DIR}/include")
target_compile_features(xone_api PRIVATE cxx_std_23)
target_compile_options(xone_api PRIVATE ${BASE_OPTIONS})
target_compile_definitions(xone_api PRIVATE XONE_VERSION="${PROJECT_VERSION}")
target_link_libraries(xone_api PUBLIC xone_hid)
# ==============================================================================
# macOS app (Swift entry point)
# ==============================================================================
add_executable(xone_app
"src/app/main.swift"
)
target_include_directories(xone_app PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_compile_definitions(xone_app PRIVATE ${BASE_DEFINITIONS})
target_link_libraries(xone_app PRIVATE xone_api ${BASE_LIBRARIES})
# Swift sees the C ABI via a bridging header (no module map required)
target_compile_options(xone_app PRIVATE
-import-objc-header "${CMAKE_SOURCE_DIR}/include/app/xone_api.h"
)
# ==============================================================================
# Tests
# ==============================================================================
option(BUILD_TESTING OFF "Build Unity test suites")
if (BUILD_TESTING)
enable_testing()
find_package(Unity REQUIRED)
add_subdirectory(tests)
endif()