UNPKG

4.38 kBMarkdownView Raw
1# NodeJS.cmake Manual
2
3# Defaults
4
5Default options used by the init function when not otherwise specified (via ncmake or via arguments to [nodejs_init](#nodejsinit--options--)):
6
7```CMake
8set(NODEJS_DEFAULT_URL https://nodejs.org/download/release)
9set(NODEJS_DEFAULT_VERSION installed)
10set(NODEJS_VERSION_FALLBACK latest)
11set(NODEJS_DEFAULT_NAME node)
12set(NODEJS_DEFAULT_CHECKSUM SHASUMS256.txt)
13set(NODEJS_DEFAULT_CHECKTYPE SHA256)
14```
15
16# Functions
17
18## `nodejs_init([options])`
19
20Configures the version of Node.js to use when running the build. Downloads required dependencies (headers, libraries) from a distribution server and configures
21a number of variables for use in other functions.
22
23#### Arguments
24
25All options can be overridden on the command line via `NODEJS_<OPTION>` properties passed to CMake. [ncmake](NcmakeManual.md) sets these via its command line flags.
26
27* **URL** - The location of the distribution server to download dependencies from. Expects a layout similar to the one used by Node.js. (Default: [https://nodejs.org/download/release](https://nodejs.org/download/release))
28* **NAME** - The name of the main binary for the Node.js variant. (Default: `node`)
29* **VERSION** - The version of Node.js (or variant) to build against. Typically starts with a `v` followed by semver (e.g. v6.4.0). Two special version strings can be used:
30 * **installed** - Use the currently installed version of Node.js (Default)
31 * **latest** - Interrogate the server for the latest version of Node.js. Requires that the distribution server has a `latest` folder at the same level as the other version specific folders
32* **CHECKSUM** - The name of the checksum file to download from the distribution server. (Default: `SHASUMS256.txt`)
33* **CHECKTYPE** - The type of checksum used by the checksum file. See the CMake `file(DOWNLOAD)` documentation for options. (Default: `SHA256`)
34
35#### Output
36
37Sets the following variables:
38
39* **NODEJS_VERSION** - The resolved version of Node.js to use
40* **NODEJS_SOURCES** - A list of required sources to link into native modules
41* **NODEJS_INCLUDE_DIRS** - The set of include directories for native modules
42* **NODEJS_LIBRARIES** - The set of dependencies required for native modules
43* **NODEJS_LINK_FLAGS** - Link flags to set when building modules
44* **NODEJS_DEFINITIONS** - Compile definitions to set when building modules
45
46#### Example
47
48```CMake
49nodejs_init(
50 URL https://atom.io/download/atom-shell
51 NAME iojs
52 VERSION v1.3.4
53)
54```
55
56Configures the system to build Node.js modules compatible with electron, version 1.3.4.
57
58## `add_nodejs_module(<NAME> <SOURCES>...)`
59
60Creates a new CMake `target` to build a node native module (shared library) from the provided sources. The `<NAME>` target can be used like any other shared library target produced by `add_library`. The target is pre-configured to use the output variables of [nodejs_init](#nodejsinit--options--) to build the module against the configured version of Node.js.
61
62#### Arguments
63
64* **`<NAME>`** The name of the module to create. Exposed to the build as the define `MODULE_NAME`since this much match exactly to the parameter passed to `NODE_MODULE`
65* **`<SOURCES>...`** The list of sources to build into the module. All parameters after the name are treated as additional arguments to `add_library`, see the CMake documentation for details.
66
67#### Output
68
69A new `target` named `<NAME>` that builds the node module.
70
71## `find_path_parent(<NAME> <BASE> <PATH>)`
72
73Finds a path suffix `<NAME>` by searching upward from `<BASE>`, setting the
74variable `<PATH>` to the result (or False if not found).
75
76#### Arguments
77
78* **`<NAME>`** - The path suffix to search for
79* **`<BASE>`** - The path to start searching from
80* **`<PATH>`** - The name of a CMake variable to set to the result
81
82#### Output
83
84The found path, or False
85
86#### Example
87
88```CMake
89find_path_parent(
90 node_modules
91 ${CMAKE_CURRENT_SOURCE_DIR}
92 NODE_MODULES_PATH
93)
94```
95
96Sets `${NODE_MODULES_PATH}` to the closest `node_modules` folder relative to `${CMAKE_CURRENT_SOURCE_DIR}`, starting from `${CMAKE_CURRENT_SOURCE_DIR}` moving upward (parent directory).
97
98## `find_nodejs_module(<NAME> <BASE> <PATH>)`
99
100A shortcut for `find_path_parent(node_modules/<NAME> <BASE> <PATH>)`
101
102# Internal Functions
103
104## `nodejs_generate_delayload_hook()`
105## `download_file()`
106
107Internal functions used by `nodejs_init`.
\No newline at end of file