Skip to content

Commit 7e59003

Browse files
committed
build: support cmake
Refs: nodejs#12425
1 parent f76ce0a commit 7e59003

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ icu_config.gypi
117117
deps/uv/.github/
118118
deps/uv/docs/code/
119119
deps/uv/docs/src/guide/
120+
121+
# CMake
122+
CMakeLists.txt
123+
cmake-build-*

BUILDING.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,17 @@ $ ./configure
117117
$ make -j4
118118
```
119119

120-
Running `make` with the `-j4` flag will cause it to run 4 compilation jobs
120+
Alternatively, to build Node.js via [CMake](https://cmake.org/):
121+
```console
122+
$ ./configure
123+
$ make configure-cmake-[debug/release]
124+
$ cmake --build cmake-build-[debug/release] --target node -- -j 4
125+
```
126+
127+
Running `make` or `cmake` with the `-j4` flag will cause it to run 4 compilation jobs
121128
concurrently which may significantly reduce build time. The number after `-j`
122129
can be changed to best suit the number of processor cores on your machine. If
123-
you run into problems running `make` with concurrency, try running it without
130+
you run into problems running `make` or `cmake` with concurrency, try running it without
124131
the `-j4` flag. See the
125132
[GNU Make Documentation](https://www.gnu.org/software/make/manual/html_node/Parallel.html)
126133
for more information.

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp \
9191
config.gypi
9292
$(PYTHON) tools/gyp_node.py -f make
9393

94+
generate-cmake-files:
95+
$(PYTHON) tools/gyp_node.py -f cmake && $(PYTHON) tools/fix-cmake-lists.py
96+
97+
configure-cmake-debug: generate-cmake-files
98+
cp -f out/Debug/CMakeLists.txt .
99+
100+
configure-cmake-release: generate-cmake-files
101+
cp -f out/Release/CMakeLists.txt .
102+
94103
config.gypi: configure
95104
$(error Missing or stale $@, please run ./$<)
96105

tools/fix-cmake-lists.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
import os
3+
4+
script_dir = os.path.dirname(__file__)
5+
node_root = os.path.normpath(os.path.join(script_dir, os.pardir))
6+
output_dir = os.path.join(os.path.abspath(node_root), 'out')
7+
8+
cmake_debug_path = os.path.join(output_dir, 'Debug', 'CMakeLists.txt')
9+
cmake_release_path = os.path.join(output_dir, 'Release', 'CMakeLists.txt')
10+
11+
def fix_cmake_list(path):
12+
with open(path, 'r') as f:
13+
fixed_lines = []
14+
for line in f.readlines():
15+
line = line.replace('"../../', '"')
16+
line = line.replace('${CMAKE_CURRENT_LIST_DIR}/../..', '${CMAKE_CURRENT_LIST_DIR}')
17+
line = line.replace(' "src/tracing/trace_event.hsrc/util.h"\n', ' "src/tracing/trace_event.h"\n "src/util.h"\n')
18+
line = line.replace('"deps/include/v8-inspector.h"', '"deps/v8/include/v8-inspector.h"')
19+
line = line.replace('"deps/include/v8-inspector-protocol.h"', '"deps/v8/include/v8-inspector-protocol.h"')
20+
line = line.replace('"${builddir}/obj.target/node/gen', '"${builddir}/CMakeFiles/node.dir/obj/gen')
21+
line = line.replace('"${builddir}/obj.target/node', '"${builddir}/CMakeFiles/node.dir')
22+
fixed_lines.append(line)
23+
24+
with open(path, 'w') as f:
25+
f.writelines(fixed_lines)
26+
27+
def fix_cmake_lists():
28+
fix_cmake_list(cmake_debug_path)
29+
fix_cmake_list(cmake_release_path)
30+
31+
if __name__ == '__main__':
32+
fix_cmake_lists()

0 commit comments

Comments
 (0)