Skip to content

fix!(cmake): require CMake 3.10 and quote custom command comments - #361

Merged
legendecas merged 1 commit into
nodejs:mainfrom
gengjiawen:cmake-generator-modernize
Sep 29, 2026
Merged

legendecas merged 1 commit into
nodejs:mainfrom
gengjiawen:cmake-generator-modernize

Conversation

@gengjiawen

@gengjiawen gengjiawen commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

The CMake generator's output doesn't work cleanly with current CMake releases:

  • cmake_minimum_required(VERSION 2.8.8) is a hard error on CMake 4.0+ (compatibility with < 3.5 was removed) unless -DCMAKE_POLICY_VERSION_MINIMUM=3.5 is passed, and CMake 3.31+ warns for anything below 3.10.
  • COMMENT for actions, rules and copies is written unquoted, so a message like Checking inspector protocol compatibility becomes several arguments. CMake 3.31+ warns under CMP0175 (and errors once the policy is NEW). A # or an unbalanced parenthesis in a message would also break parsing.

This requires CMake 3.10 (dropping the now redundant cmake_policy() call) and writes COMMENT as a quoted, escaped string. ${...} references such as ${RULE_INPUT_NAME} are still expanded.

Tested by generating Node.js with tools/gyp_node.py -f cmake and configuring with CMake 4.4:

before after
needs CMAKE_POLICY_VERSION_MINIMUM yes no
CMP0175 warnings 52 0
deprecation warnings 2 0

Added unit tests in pylib/gyp/generator/cmake_test.py and updated the cmake integration test fixtures.

BEGIN_COMMIT_OVERRIDE
fix(cmake): require CMake 3.10 and quote custom command comments (#361)
END_COMMIT_OVERRIDE

The generated `cmake_minimum_required(VERSION 2.8.8)` is rejected by
CMake 4.0+, which removed compatibility with versions older than 3.5,
unless `CMAKE_POLICY_VERSION_MINIMUM` is set. CMake 3.31+ also warns for
anything older than 3.10. Require 3.10; it sets the policy version too,
so the separate `cmake_policy()` call is dropped.

`COMMENT` values of actions, rules and copies were written unquoted, so
any message containing spaces was split into several arguments. CMake
3.31+ reports this under CMP0175 (and errors once the policy is NEW).
A `#` or an unbalanced parenthesis in a message would also break
parsing. Quote and escape them like other generated strings; variable
references such as `${RULE_INPUT_NAME}` are still expanded.

Assisted-by: Claude Code
Signed-off-by: gengjiawen <technicalcute@gmail.com>
@legendecas legendecas changed the title fix(cmake): require CMake 3.10 and quote custom command comments fix!(cmake): require CMake 3.10 and quote custom command comments Sep 29, 2026
@legendecas
legendecas merged commit b418211 into nodejs:main Sep 29, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants