Skip to content

Commit

Permalink
build: support cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
lev-kazakov committed Dec 26, 2017
1 parent dc4f1b9 commit 930ba56
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ icu_config.gypi
deps/uv/.github/
deps/uv/docs/code/
deps/uv/docs/src/guide/

# CMake
CMakeLists.txt
cmake-build-*
11 changes: 9 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ $ ./configure
$ make -j4
```

Running `make` with the `-j4` flag will cause it to run 4 compilation jobs
Alternatively, to build Node.js via [CMake](https://cmake.org/):
```console
$ ./configure
$ make configure-cmake-[debug/release]
$ cmake --build cmake-build-[debug/release] --target node -- -j 4
```

Running `make` or `cmake` with the `-j4` flag will cause it to run 4 compilation jobs
concurrently which may significantly reduce build time. The number after `-j`
can be changed to best suit the number of processor cores on your machine. If
you run into problems running `make` with concurrency, try running it without
you run into problems running `make` or `cmake` with concurrency, try running it without
the `-j4` flag. See the
[GNU Make Documentation](https://www.gnu.org/software/make/manual/html_node/Parallel.html)
for more information.
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp \
config.gypi
$(PYTHON) tools/gyp_node.py -f make

generate-cmake-files:
$(PYTHON) tools/gyp_node.py -f cmake && $(PYTHON) tools/fix-cmake-lists.py

configure-cmake-debug: generate-cmake-files
cp -f out/Debug/CMakeLists.txt .

configure-cmake-release: generate-cmake-files
cp -f out/Release/CMakeLists.txt .

config.gypi: configure
$(error Missing or stale $@, please run ./$<)

Expand Down
32 changes: 32 additions & 0 deletions tools/fix-cmake-lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
import os

script_dir = os.path.dirname(__file__)
node_root = os.path.normpath(os.path.join(script_dir, os.pardir))
output_dir = os.path.join(os.path.abspath(node_root), 'out')

cmake_debug_path = os.path.join(output_dir, 'Debug', 'CMakeLists.txt')
cmake_release_path = os.path.join(output_dir, 'Release', 'CMakeLists.txt')

def fix_cmake_list(path):
with open(path, 'r') as f:
fixed_lines = []
for line in f.readlines():
line = line.replace('"../../', '"')
line = line.replace('${CMAKE_CURRENT_LIST_DIR}/../..', '${CMAKE_CURRENT_LIST_DIR}')
line = line.replace(' "src/tracing/trace_event.hsrc/util.h"\n', ' "src/tracing/trace_event.h"\n "src/util.h"\n')
line = line.replace('"deps/include/v8-inspector.h"', '"deps/v8/include/v8-inspector.h"')
line = line.replace('"deps/include/v8-inspector-protocol.h"', '"deps/v8/include/v8-inspector-protocol.h"')
line = line.replace('"${builddir}/obj.target/node/gen', '"${builddir}/CMakeFiles/node.dir/obj/gen')
line = line.replace('"${builddir}/obj.target/node', '"${builddir}/CMakeFiles/node.dir')
fixed_lines.append(line)

with open(path, 'w') as f:
f.writelines(fixed_lines)

def fix_cmake_lists():
fix_cmake_list(cmake_debug_path)
fix_cmake_list(cmake_release_path)

if __name__ == '__main__':
fix_cmake_lists()

0 comments on commit 930ba56

Please sign in to comment.