Skip to content

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

Merged
Youw merged 1 commit into
masterfrom
copilot/fix-warnings-ninja-build
May 19, 2026
Merged

cmake: declare version and policy requirements once at the top level#808
Youw merged 1 commit into
masterfrom
copilot/fix-warnings-ninja-build

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

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

Copilot AI linked an issue May 19, 2026 that may be closed by this pull request
@mcuee mcuee added the build system/CI Anything related to building the project or running on CI label May 19, 2026
Copilot AI changed the title [WIP] Fix warnings when using ninja build Suppress Meson+ninja CMake policy warnings in backend subprojects May 19, 2026
Copilot finished work on behalf of Youw May 19, 2026 11:26
Copilot AI requested a review from Youw May 19, 2026 11:26
Copilot finished work on behalf of Youw May 19, 2026 11:49
Copilot finished work on behalf of Youw May 19, 2026 11:53
@Youw Youw marked this pull request as ready for review May 19, 2026 13:14
@Youw Youw marked this pull request as draft May 19, 2026 13:16
Copilot AI requested a review from Youw May 19, 2026 13:25
Copilot finished work on behalf of Youw May 19, 2026 13:25
Copilot finished work on behalf of Youw May 19, 2026 20:16
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
@Youw Youw force-pushed the copilot/fix-warnings-ninja-build branch from 5a0a29b to 02b6441 Compare May 19, 2026 20:54
@Youw Youw changed the title Suppress Meson+ninja CMake policy warnings in backend subprojects cmake: declare version and policy requirements once at the top level May 19, 2026
@Youw Youw marked this pull request as ready for review May 19, 2026 21:02
@Youw Youw merged commit 762470b into master May 19, 2026
23 checks passed
@Youw Youw deleted the copilot/fix-warnings-ninja-build branch May 19, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build system/CI Anything related to building the project or running on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warnings when using ninja build

3 participants