Skip to content

fix(cmake): add a dummy source to libraries without sources - #362

Merged
gengjiawen merged 1 commit into
nodejs:mainfrom
gengjiawen:cmake-empty-library-sources
Sep 29, 2026
Merged

gengjiawen merged 1 commit into
nodejs:mainfrom
gengjiawen:cmake-empty-library-sources

Conversation

@gengjiawen

@gengjiawen gengjiawen commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

The CMake generator only gives an executable without sources a generated, empty dummy.c. A static_library, shared_library or loadable_module without sources is written as e.g. add_library(v8 STATIC), which CMake rejects at generate time:

CMake Error at CMakeLists.txt:18527 (add_library):
  No SOURCES given to target: v8

Libraries without sources are used to aggregate dependencies. Node.js's v8 target in tools/v8_gypfiles/v8.gyp is one: in non-shared builds it is a static_library with no sources that only pulls in v8_snapshot for its dependents. The make generator builds an empty library for such targets; this makes the CMake generator do the same by giving every target except none the dummy source when it has none.

Tested by generating Node.js with tools/gyp_node.py -f cmake and configuring with CMake 4.4: configuring failed with the error above before this change and succeeds after it with no errors or warnings, and ninja v8 libuv builds (libv8.a is empty, as with the make generator).

Added unit tests in pylib/gyp/generator/cmake_test.py.

Only executable targets without sources got an empty generated dummy.c.
A static_library, shared_library or loadable_module without sources was
written as e.g. `add_library(v8 STATIC)`, which CMake rejects at generate
time with "No SOURCES given to target". Such libraries are used to
aggregate dependencies, e.g. the `v8` target in Node.js's v8.gyp, and the
make generator builds an empty library for them.

Give every target except `none` the dummy source when it has none.

Assisted-by: Claude Code
Signed-off-by: gengjiawen <technicalcute@gmail.com>
@gengjiawen
gengjiawen force-pushed the cmake-empty-library-sources branch from d3359e9 to 6241c36 Compare September 29, 2026 04:16
@gengjiawen
gengjiawen requested review from addaleax and legendecas and removed request for addaleax September 29, 2026 04:22
@gengjiawen
gengjiawen merged commit 391165e into nodejs:main Sep 29, 2026
68 of 72 checks passed
@gengjiawen
gengjiawen deleted the cmake-empty-library-sources branch September 29, 2026 15:01
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