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
This commit is contained in:
portersky
2026-08-17 14:18:03 +02:00
parent 78f042ab84
commit a7d7d0f253
25 changed files with 742 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
set(TEST_TARGETS "")
add_executable(test_version test_version.cpp)
target_include_directories(test_version PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(test_version PRIVATE xone_api Unity::Unity)
target_compile_features(test_version PRIVATE cxx_std_23)
target_compile_definitions(test_version PRIVATE XONE_VERSION="${PROJECT_VERSION}")
add_test(NAME test_version COMMAND test_version)
list(APPEND TEST_TARGETS test_version)
add_executable(test_types test_types.cpp)
target_include_directories(test_types PRIVATE "${CMAKE_SOURCE_DIR}/include")
target_link_libraries(test_types PRIVATE Unity::Unity)
target_compile_features(test_types PRIVATE cxx_std_23)
add_test(NAME test_types COMMAND test_types)
list(APPEND TEST_TARGETS test_types)
add_custom_target(check
COMMAND ${CMAKE_CTEST_COMMAND}
--test-dir "${CMAKE_BINARY_DIR}"
--output-on-failure
--progress
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
USES_TERMINAL
DEPENDS ${TEST_TARGETS}
)
+46
View File
@@ -0,0 +1,46 @@
#include "unity.h"
#include "common/types.hpp"
void setUp() {}
void tearDown() {}
void test_store_le16_little_endian(void)
{
std::uint8_t buf[2];
xone::store_le16(buf, 0x1234);
TEST_ASSERT_EQUAL_UINT8(0x34, buf[0]);
TEST_ASSERT_EQUAL_UINT8(0x12, buf[1]);
}
void test_load_le16_roundtrip(void)
{
std::uint8_t buf[2] = { 0xCD, 0xAB };
TEST_ASSERT_EQUAL_UINT16(0xABCD, xone::load_le16(buf));
}
void test_store_le32_little_endian(void)
{
std::uint8_t buf[4];
xone::store_le32(buf, 0xDEADBEEF);
TEST_ASSERT_EQUAL_UINT8(0xEF, buf[0]);
TEST_ASSERT_EQUAL_UINT8(0xBE, buf[1]);
TEST_ASSERT_EQUAL_UINT8(0xAD, buf[2]);
TEST_ASSERT_EQUAL_UINT8(0xDE, buf[3]);
}
void test_load_le32_roundtrip(void)
{
std::uint8_t buf[4] = { 0x01, 0x02, 0x03, 0x04 };
TEST_ASSERT_EQUAL_UINT32(0x04030201, xone::load_le32(buf));
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_store_le16_little_endian);
RUN_TEST(test_load_le16_roundtrip);
RUN_TEST(test_store_le32_little_endian);
RUN_TEST(test_load_le32_roundtrip);
return UNITY_END();
}
+22
View File
@@ -0,0 +1,22 @@
#include "unity.h"
#include "app/xone_api.h"
#ifndef XONE_VERSION
#define XONE_VERSION "0.1.0"
#endif
void setUp() {}
void tearDown() {}
void test_version_matches_project(void)
{
TEST_ASSERT_EQUAL_STRING(XONE_VERSION, xone_version());
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_version_matches_project);
return UNITY_END();
}