Files
xone_macos/CMakeLists.txt
T
portersky a7d7d0f253 chore: scaffold CMake build system
Add the CMake build for the Swift + C++ macOS port, mirroring the
refix layout: deps/ modules (Platform, Flags, Sanitizers, FindUnity),
per-module static libraries (usb, auth, mt76, gip, hid, api), a Swift
app entry point with a pure C bridge header, and a Unity test suite
behind BUILD_TESTING.

Swift requires the Ninja or Xcode generator; a guard in
CMakeLists.txt rejects anything else.

Co-Authored-By: qwen (qwen/qwen3.8-27b@q2_k_xl): scaffolded CMake build + tests
2026-08-17 14:18:03 +02:00

108 lines
4.2 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.0 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})
# Auth + crypto (AES-CCMP key setup, ECDH, RSA — port from auth/)
add_library(xone_auth STATIC
"src/auth/crypto.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})
# 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()