cmake: declare version and policy requirements once at the top level#808
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix warnings when using ninja build
Suppress Meson+ninja CMake policy warnings in backend subprojects
May 19, 2026
Youw
approved these changes
May 19, 2026
Each backend subdirectory (libusb, linux, mac, netbsd) called cmake_minimum_required() with its own version range. That call resets the CMake policy stack to the range's upper bound, discarding policies introduced later. When hidapi is built as a CMake subproject (e.g. the Meson cmake.subproject path), a modern CMake then emits dev warnings for CMP0156/CMP0181/CMP0200 right after each backend's call. The backends have no project() of their own and are never configured standalone, so their cmake_minimum_required() calls served no purpose beyond resetting policies. Remove them; the backends now inherit the single policy baseline from the top-level CMakeLists.txt, matching what windows/CMakeLists.txt already did. Raise the top-level range to 3.6.3...4.3: 3.6.3 is the real floor (it was already required by the linux/libusb/netbsd backends), and the 4.3 upper bound sets every current policy to NEW. hidtest keeps its own cmake_minimum_required() because it is also built as a standalone project; its upper bound is raised to 4.3 so it behaves identically whether built standalone or as a subdirectory. Assisted-by: Claude:claude-opus-4.7
5a0a29b to
02b6441
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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