Skip to content

Commit d2755fe

Browse files
committed
Use find_package instead of include to locate "weak-node-api"
1 parent 7151c82 commit d2755fe

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

.changeset/quick-poets-greet.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"gyp-to-cmake": minor
3+
"cmake-rn": minor
4+
"react-native-node-api": minor
5+
---
6+
7+
Use `find_package` instead of `include` to locate "weak-node-api"

packages/cmake-rn/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Android's dynamic linker imposes restrictions on the access to global symbols (s
1010

1111
The implementation of Node-API is split between Hermes and our host package and to avoid addons having to explicitly link against either, we've introduced a `weak-node-api` library (published in `react-native-node-api` package). This library exposes only Node-API and will have its implementation injected by the host.
1212

13-
To link against `weak-node-api` just include the CMake config exposed through `WEAK_NODE_API_CONFIG` and add `weak-node-api` to the `target_link_libraries` of the addon's library target.
13+
To link against `weak-node-api` just use `find_package` to import the `weak-node-api` target and add it to the `target_link_libraries` of the addon's library target.
1414

1515
```cmake
1616
cmake_minimum_required(VERSION 3.15...3.31)
1717
project(tests-buffers)
1818
1919
# Defines the "weak-node-api" target
20-
include(${WEAK_NODE_API_CONFIG})
20+
find_package(weak-node-api REQUIRED CONFIG)
2121
2222
add_library(addon SHARED addon.c)
2323
target_link_libraries(addon PRIVATE weak-node-api)

packages/cmake-rn/src/weak-node-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export function getWeakNodeApiVariables(
5858
triplet: SupportedTriplet | "apple",
5959
): Record<string, string> {
6060
return {
61-
// Expose an includable CMake config file declaring the weak-node-api target
61+
// Enable use of `find_package(weak-node-api REQUIRED CONFIG)`
62+
"weak-node-api_DIR": path.dirname(weakNodeApiCmakePath),
63+
// Enable use of `include(${WEAK_NODE_API_CONFIG})`
6264
WEAK_NODE_API_CONFIG: weakNodeApiCmakePath,
6365
WEAK_NODE_API_INC: getNodeApiIncludePaths().join(";"),
6466
WEAK_NODE_API_LIB: getWeakNodeApiPath(triplet),

packages/gyp-to-cmake/src/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function bindingGypToCmakeLists({
8585
];
8686

8787
if (weakNodeApi) {
88-
lines.push(`include(\${WEAK_NODE_API_CONFIG})`, "");
88+
lines.push(`find_package(weak-node-api REQUIRED CONFIG)`, "");
8989
}
9090

9191
for (const target of gyp.targets) {

0 commit comments

Comments
 (0)