cmake: declare version and policy requirements once at the top level #808

Merged
Copilot merged 1 commit from copilot/fix-warnings-ninja-build into master 2026-05-19 16:16:31 -05:00
Copilot commented 2026-05-19 06:20:25 -05:00 (Migrated from github.com)

Fixes: #805

Problem

When hidapi is built as a CMake subproject — e.g. through the Meson cmake.subproject() integration that the root meson.build uses — a modern CMake (4.x) emits developer warnings for unset policies CMP0156, CMP0181 and CMP0200, pointing at the add_library() calls in the linux/ and libusb/ backend CMakeLists.txt.

Root cause: each backend subdirectory (libusb, linux, mac, netbsd) called cmake_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.txt files have no project() of their own and are never configured standalone — they are only ever add_subdirectory()'d from src/. Their cmake_minimum_required() calls therefore did nothing except reset policies.

  • Remove cmake_minimum_required() from libusb/, linux/, mac/, netbsd/ — they now inherit one consistent policy baseline, exactly as windows/CMakeLists.txt already did.
  • Raise the top-level CMakeLists.txt range to 3.6.3...4.3. 3.6.3 is the honest floor (already required by the linux/libusb/netbsd backends); the 4.3 upper bound opts every current policy into NEW.
  • hidtest/ keeps its own cmake_minimum_required() since it is built both standalone and as a subdirectory; its upper bound is likewise raised to 4.3 so 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:

  • Before: meson setup emits CMake Warning (dev) for CMP0156 / CMP0181 / CMP0200 in linux/ and libusb/.
  • After: meson setup followed by ninja complete with no policy warnings.

Both CMake 3.22 and 4.3.2 configure and build cleanly.

Assisted-by: Claude:claude-opus-4.7

Fixes: #805 ## Problem When hidapi is built as a CMake subproject — e.g. through the Meson `cmake.subproject()` integration that the root `meson.build` uses — a modern CMake (4.x) emits developer warnings for unset policies `CMP0156`, `CMP0181` and `CMP0200`, pointing at the `add_library()` calls in the `linux/` and `libusb/` backend `CMakeLists.txt`. Root cause: each backend subdirectory (`libusb`, `linux`, `mac`, `netbsd`) called `cmake_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.txt` files have no `project()` of their own and are never configured standalone — they are only ever `add_subdirectory()`'d from `src/`. Their `cmake_minimum_required()` calls therefore did nothing except reset policies. - Remove `cmake_minimum_required()` from `libusb/`, `linux/`, `mac/`, `netbsd/` — they now inherit one consistent policy baseline, exactly as `windows/CMakeLists.txt` already did. - Raise the top-level `CMakeLists.txt` range to `3.6.3...4.3`. `3.6.3` is the honest floor (already required by the linux/libusb/netbsd backends); the `4.3` upper bound opts every current policy into NEW. - `hidtest/` keeps its own `cmake_minimum_required()` since it is built both standalone and as a subdirectory; its upper bound is likewise raised to `4.3` so 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: - **Before:** `meson setup` emits `CMake Warning (dev)` for `CMP0156` / `CMP0181` / `CMP0200` in `linux/` and `libusb/`. - **After:** `meson setup` followed by `ninja` complete with no policy warnings. Both CMake 3.22 and 4.3.2 configure and build cleanly. Assisted-by: Claude:claude-opus-4.7
Youw (Migrated from github.com) reviewed 2026-05-19 06:20:25 -05:00
Youw (Migrated from github.com) approved these changes 2026-05-19 08:13:58 -05:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!808
No description provided.