Fix HID-enabled build automoc registration#2577
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes HID-enabled builds by ensuring Qt’s AUTOMOC processes the HID QObject header when hidapi support is enabled, preventing missing meta-object/signal symbol link errors.
Changes:
- Add
src/core/HidEncoderManager.hto the HIDAPI conditionaltarget_sources()list so MOC is generated for theQ_OBJECTclass. - Add
src/core/HidDeviceParser.halongside its.cppfor consistent source registration underHIDAPI_FOUND.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ten9876
left a comment
There was a problem hiding this comment.
Claude here, reviewing on Jeremy's behalf.
Verdict
Clean, trivial-but-important fix. Merge.
Verified
Q_OBJECTis present inHidEncoderManager.h— confirmed by direct grep.HidDeviceParser.hdoes not contain Q_OBJECT (listed only for consistency with its.cpppairing).- Current
CMakeLists.txtHIDAPI block only lists.cppfiles — confirmed at the block starting around theHIDAPI_FOUNDconditional. The PR adds the two.hfiles to the sametarget_sources()call. - CI all green —
build,analyze (cpp),check-paths,check-windows, CodeQL.check-windowsran (not skipped) because CMakeLists.txt changed. - Built locally with hidapi installed — Linux clean build, MOC produced
build/AetherSDR_autogen/PRMOGMWJPH/moc_HidEncoderManager.cppcorrectly, link succeeded.
Why this fix is the right one
Qt's AUTOMOC has two ways to find Q_OBJECT in a header:
- Explicit: the header is listed in
target_sources()— guaranteed scan - Implicit: a listed
.cpp#includes the header — AUTOMOC follows the include and scans
The implicit path is fragile in practice. It can break with:
- Generator differences (Ninja vs. Xcode vs. VS — the failure Pat hit on macOS, where the generator may be Xcode-style)
- AUTOMOC_DEPEND_FILTERS edge cases
- Header that's forward-declared in the
.cppinstead of#included directly - Cross-build / install-tree relocation
The explicit path (this PR) is the canonical Qt + CMake idiom and works identically across every generator. This is the right level to fix it at.
My Linux box happens to build successfully without the fix because AUTOMOC's implicit detection works in this configuration — the fact that Pat's macOS build fails is the standard "works on my machine" trap that the explicit fix eliminates. No need to characterize why the implicit path failed on Pat's setup; the explicit fix removes the dependency on that fragile heuristic entirely.
Recommendation
Merge. Trivial, correctly diagnosed, makes builds reproducible across generators and platforms.
Thanks @rfoust — these CMake-script papercuts are the kind that silently bite contributors trying to enable optional features. Documenting the AUTOMOC mechanism in the PR description is a nice touch that future archaeologists will appreciate.
73, Jeremy KK7GWY & Claude (AI dev partner)
ten9876
left a comment
There was a problem hiding this comment.
Approved — correct AUTOMOC fix, built clean locally.
Summary
Bug
AetherSDR builds normally when hidapi is not installed because the HID encoder code is skipped. After installing the optional hidapi dependency, CMake enables HAVE_HIDAPI and compiles HidEncoderManager.cpp.
HidEncoderManager inherits QObject and uses Q_OBJECT/signals in HidEncoderManager.h. Qt must run MOC on that header to generate the class meta-object, signal methods, and vtable-related code. The current hidapi-enabled target_sources() block only lists the .cpp files, so AUTOMOC does not reliably scan HidEncoderManager.h.
That causes the HID-enabled build to compile but fail during the final app link with missing symbols such as:
Fix
Add the HID headers to the same conditional target_sources() block used when HIDAPI_FOUND is true:
The key file is HidEncoderManager.h because it contains Q_OBJECT. Listing it as a target source lets Qt AUTOMOC generate the missing meta-object/signal code. HidDeviceParser.h is included alongside its matching .cpp for consistency.
Testing
Configured and built on macOS with optional hidapi installed:
CMake reported:
The app linked successfully after this change.