https://github.com/mathisloge/cmake-napi
https://github.com/mathisloge/cmake-napi
cmake cpp napi node nodejs
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mathisloge/cmake-napi
- Owner: mathisloge
- Created: 2021-11-19T12:40:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-19T09:31:21.000Z (over 4 years ago)
- Last Synced: 2025-10-27T20:49:41.557Z (7 months ago)
- Topics: cmake, cpp, napi, node, nodejs
- Language: CMake
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CMake for N-API
## usage
```cmake
include(FetchContent)
FetchContent_Declare(
napi
GIT_REPOSITORY https://github.com/mathisloge/cmake-napi.git
GIT_TAG
)
FetchContent_MakeAvailable(napi)
add_library(mynodelib MODULE)
target_link_libraries(mynodelib PRIVATE node::napi)
```
## usage with node-pre-gyp
Inside your `CMakeLists.txt`:
```cmake
include(FetchContent)
FetchContent_Declare(
napi_modules
GIT_REPOSITORY https://github.com/mathisloge/cmake-napi.git
GIT_TAG
)
FetchContent_MakeAvailable(napi_modules)
FetchContent_GetProperties(napi_modules SOURCE_DIR napi_src)
list(APPEND CMAKE_MODULE_PATH "${napi_src}/modules")
include(napi-gyp)
add_library(mynodelib MODULE)
target_link_libraries(mynodelib PRIVATE node::napi)
```
Your `binding.gyp`:
```
{
'targets': [
{
'target_name': 'build-mytarget',
'type': 'none',
'actions': [
{
'action_name': 'configure',
'message': 'configuring ...',
'inputs': [],
'outputs': ["build/CMakeCache.txt"],
'action': ['cmake', '.', '-B', 'build', '-DCMAKE_BUILD_TYPE=Release', '-DNAPI_VERSION=<(napi_build_version)', '-Dnode_root_dir=<(node_root_dir)', '-Dnode_lib_file=<(node_lib_file)'],
},
{
'action_name': 'build',
'message': 'Building ...',
'inputs': [],
'outputs': ["<(module_path)/"],
'action': ['cmake','--build', 'build', '--config Release'],
},
]
}
]
}
```