This is a breaking change and will likely require some small changes to your cmake config to keep your project building.
Summary
A lot of work has gone into this release, to try and make the general usage of the library smoother. It has better support for building modules with node-api. The on disk footprint of the library is much smaller than before, with various dependencies removed, or updated.
Upgrading
We recommend having the following at the top of your cmake file, before the project(...)
definition.
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0042 NEW)
This will force MSVC to do a MT build, so if you were doing that another way, it should be possible to remove that. If you need to keep it building as MD, you can add set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
in your cmake file.
If you are using node-api, make sure that your package.json
has the following, but with the correct NAPI_VERSION filled in. We use this to autodetect that your module is building with node-api.
"binary": {
"napi_versions": [7]
},
You should also add the following to the bottom of your cmake file. This lets us avoid downloading the full nodejs headers, and lets us use bundle a much more lightweight copy instead
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
# Generate node.lib
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()
If you have something like:
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
in your file, it is no longer needed. We will inject the correct include paths for you, similar to what is done for nan
.
That should be everything.
If we missed something in these steps, or if you are having problems getting your module building again, let us know in an issue.
All changes:
- update dependencies
- replace some dependencies with modern language features
- follow node-gyp behaviour for visual-studio version detection and selection
- automatically locate node-addon-api and add to include paths
- avoid downloads when building for node-api
- encourage use of MT builds with MSVC, rather than MD