cmake: declare version and policy requirements once at the top level #808
No reviewers
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi!808
Loading…
Reference in a new issue
No description provided.
Delete branch "copilot/fix-warnings-ninja-build"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes: #805
Problem
When hidapi is built as a CMake subproject — e.g. through the Meson
cmake.subproject()integration that the rootmeson.builduses — a modern CMake (4.x) emits developer warnings for unset policiesCMP0156,CMP0181andCMP0200, pointing at theadd_library()calls in thelinux/andlibusb/backendCMakeLists.txt.Root cause: each backend subdirectory (
libusb,linux,mac,netbsd) calledcmake_minimum_required(VERSION <min>...3.25). That command also resets the CMake policy stack to the range's upper bound (3.25), discarding every policy introduced later — including ones the parent scope had already configured.Change
The backend
CMakeLists.txtfiles have noproject()of their own and are never configured standalone — they are only everadd_subdirectory()'d fromsrc/. Theircmake_minimum_required()calls therefore did nothing except reset policies.cmake_minimum_required()fromlibusb/,linux/,mac/,netbsd/— they now inherit one consistent policy baseline, exactly aswindows/CMakeLists.txtalready did.CMakeLists.txtrange to3.6.3...4.3.3.6.3is the honest floor (already required by the linux/libusb/netbsd backends); the4.3upper bound opts every current policy into NEW.hidtest/keeps its owncmake_minimum_required()since it is built both standalone and as a subdirectory; its upper bound is likewise raised to4.3so it behaves the same in either mode.The project now declares its CMake version and policy requirements once. Net: 6 files, +2 / -10.
Verification
Reproduced the CI "Check Meson build" step with CMake 4.3.2:
meson setupemitsCMake Warning (dev)forCMP0156/CMP0181/CMP0200inlinux/andlibusb/.meson setupfollowed byninjacomplete with no policy warnings.Both CMake 3.22 and 4.3.2 configure and build cleanly.
Assisted-by: Claude:claude-opus-4.7