diff --git a/.changeset/chilly-trains-nail.md b/.changeset/chilly-trains-nail.md new file mode 100644 index 00000000..65710b00 --- /dev/null +++ b/.changeset/chilly-trains-nail.md @@ -0,0 +1,5 @@ +--- +"cmake-rn": minor +--- + +Add support for building projects declaring multiple shared object libraries into Node-API addons diff --git a/.changeset/real-emus-jam.md b/.changeset/real-emus-jam.md new file mode 100644 index 00000000..d7e8a53c --- /dev/null +++ b/.changeset/real-emus-jam.md @@ -0,0 +1,5 @@ +--- +"gyp-to-cmake": minor +--- + +Add --namespaced-targets to allow a root project to add many sub-projects diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index b94e2fa2..141c039b 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -2,6 +2,7 @@ import assert from "node:assert/strict"; import path from "node:path"; import fs from "node:fs"; import { EventEmitter } from "node:events"; +import os from "node:os"; import { chalk, @@ -11,6 +12,7 @@ import { oraPromise, assertFixable, wrapAction, + pLimit, } from "@react-native-node-api/cli-utils"; import { @@ -23,7 +25,7 @@ import { Platform } from "./platforms/types.js"; import { getCcachePath } from "./ccache.js"; // We're attaching a lot of listeners when spawning in parallel -EventEmitter.defaultMaxListeners = 100; +EventEmitter.defaultMaxListeners = 500; const verboseOption = new Option( "--verbose", @@ -129,6 +131,16 @@ const ccachePathOption = new Option( "Specify the path to the ccache executable", ).default(getCcachePath()); +const concurrencyOption = new Option( + "--concurrency ", + "Limit the number of concurrent tasks", +) + .argParser((value) => parseInt(value, 10)) + .default( + os.availableParallelism(), + `${os.availableParallelism()} or 1 when verbose is enabled`, + ); + let program = new Command("cmake-rn") .description("Build React Native Node API modules with CMake") .addOption(tripletOption) @@ -144,7 +156,8 @@ let program = new Command("cmake-rn") .addOption(noAutoLinkOption) .addOption(noWeakNodeApiLinkageOption) .addOption(cmakeJsOption) - .addOption(ccachePathOption); + .addOption(ccachePathOption) + .addOption(concurrencyOption); for (const platform of platforms) { const allOption = new Option( @@ -181,6 +194,7 @@ program = program.action( out, build: buildPath, ccachePath, + concurrency, } = baseOptions; assertFixable( @@ -232,6 +246,8 @@ program = program.action( } } + const limit = pLimit(concurrency); + const tripletContexts = [...triplets].map((triplet) => { const platform = findPlatformForTriplet(triplet); @@ -244,17 +260,21 @@ program = program.action( triplet, platform, async spawn(command: string, args: string[], cwd?: string) { - const outputPrefix = verbose ? chalk.dim(`[${triplet}] `) : undefined; - if (verbose) { - console.log( - `${outputPrefix}» ${command} ${args.map((arg) => chalk.dim(`${arg}`)).join(" ")}`, - cwd ? `(in ${chalk.dim(cwd)})` : "", - ); - } - await spawn(command, args, { - outputMode: verbose ? "inherit" : "buffered", - outputPrefix, - cwd, + await limit(async () => { + const outputPrefix = verbose + ? chalk.dim(`[${triplet}] `) + : undefined; + if (verbose) { + console.log( + `${outputPrefix}» ${command} ${args.map((arg) => chalk.dim(`${arg}`)).join(" ")}`, + cwd ? `(in ${chalk.dim(cwd)})` : "", + ); + } + await spawn(command, args, { + outputMode: verbose ? "inherit" : "buffered", + outputPrefix, + cwd, + }); }); }, }; @@ -280,13 +300,15 @@ program = program.action( relevantTriplets, baseOptions, (command, args, cwd) => - spawn(command, args, { - outputMode: verbose ? "inherit" : "buffered", - outputPrefix: verbose - ? chalk.dim(`[${platform.name}] `) - : undefined, - cwd, - }), + limit(() => + spawn(command, args, { + outputMode: verbose ? "inherit" : "buffered", + outputPrefix: verbose + ? chalk.dim(`[${platform.name}] `) + : undefined, + cwd, + }), + ), ); } }), diff --git a/packages/cmake-rn/src/platforms/android.ts b/packages/cmake-rn/src/platforms/android.ts index da5f19c2..2a98c99a 100644 --- a/packages/cmake-rn/src/platforms/android.ts +++ b/packages/cmake-rn/src/platforms/android.ts @@ -164,7 +164,6 @@ export const platform: Platform = { await Promise.all( triplets.map(async ({ triplet, spawn }) => { const buildPath = getBuildPath(build, triplet, configuration); - const outputPath = path.join(buildPath, "out"); // We want to use the CMake File API to query information later await cmakeFileApi.createSharedStatelessQuery( buildPath, @@ -189,7 +188,6 @@ export const platform: Platform = { ...commonDefinitions, { // "CPACK_SYSTEM_NAME": `Android-${architecture}`, - CMAKE_LIBRARY_OUTPUT_DIRECTORY: outputPath, ANDROID_ABI: ANDROID_ARCHITECTURES[triplet], }, ]), @@ -232,41 +230,39 @@ export const platform: Platform = { type === "SHARED_LIBRARY" && (target.length === 0 || target.includes(name)), ); - assert.equal( - sharedLibraries.length, - 1, - "Expected exactly one shared library", - ); - const [sharedLibrary] = sharedLibraries; - const { artifacts } = sharedLibrary; - assert( - artifacts && artifacts.length === 1, - "Expected exactly one artifact", - ); - const [artifact] = artifacts; - // Add prebuild entry, creating a new entry if needed - if (!(sharedLibrary.name in prebuilds)) { - prebuilds[sharedLibrary.name] = []; - } - const libraryPath = path.join(buildPath, artifact.path); - assert( - fs.existsSync(libraryPath), - `Expected built library at ${libraryPath}`, - ); + await Promise.all( + sharedLibraries.map(async (sharedLibrary) => { + const { artifacts } = sharedLibrary; + assert( + artifacts && artifacts.length === 1, + "Expected exactly one artifact", + ); + const [artifact] = artifacts; + // Add prebuild entry, creating a new entry if needed + if (!(sharedLibrary.name in prebuilds)) { + prebuilds[sharedLibrary.name] = []; + } + const libraryPath = path.join(buildPath, artifact.path); + assert( + fs.existsSync(libraryPath), + `Expected built library at ${libraryPath}`, + ); - if (strip) { - const llvmBinPath = getNdkLlvmBinPath(getNdkPath(ndkVersion)); - const stripToolPath = path.join(llvmBinPath, `llvm-strip`); - assert( - fs.existsSync(stripToolPath), - `Expected llvm-strip to exist at ${stripToolPath}`, - ); - await spawn(stripToolPath, [libraryPath]); - } - prebuilds[sharedLibrary.name].push({ - triplet, - libraryPath, - }); + if (strip) { + const llvmBinPath = getNdkLlvmBinPath(getNdkPath(ndkVersion)); + const stripToolPath = path.join(llvmBinPath, `llvm-strip`); + assert( + fs.existsSync(stripToolPath), + `Expected llvm-strip to exist at ${stripToolPath}`, + ); + await spawn(stripToolPath, [libraryPath]); + } + prebuilds[sharedLibrary.name].push({ + triplet, + libraryPath, + }); + }), + ); } for (const [libraryName, libraries] of Object.entries(prebuilds)) { diff --git a/packages/cmake-rn/src/platforms/apple.ts b/packages/cmake-rn/src/platforms/apple.ts index 36c595b9..24eae5e9 100644 --- a/packages/cmake-rn/src/platforms/apple.ts +++ b/packages/cmake-rn/src/platforms/apple.ts @@ -170,7 +170,7 @@ function getBuildPath(baseBuildPath: string, triplet: Triplet) { return path.join(baseBuildPath, triplet.replace(/;/g, "_")); } -async function readCmakeSharedLibraryTarget( +async function readCmakeSharedLibraryTargets( buildPath: string, configuration: string, target: string[], @@ -180,18 +180,11 @@ async function readCmakeSharedLibraryTarget( configuration, "2.0", ); - const sharedLibraries = targets.filter( + return targets.filter( ({ type, name }) => type === "SHARED_LIBRARY" && (target.length === 0 || target.includes(name)), ); - assert.equal( - sharedLibraries.length, - 1, - "Expected exactly one shared library", - ); - const [sharedLibrary] = sharedLibraries; - return sharedLibrary; } const SIMULATOR_TRIPLET_SUFFIXES = [ @@ -375,88 +368,82 @@ export const platform: Platform = { const buildPath = getBuildPath(build, triplet); - const sharedLibrary = await readCmakeSharedLibraryTarget( + const sharedLibraries = await readCmakeSharedLibraryTargets( buildPath, configuration, target, ); - const isFramework = sharedLibrary.nameOnDisk?.includes(".framework/"); - - if (isFramework) { - const { project } = listXcodeProject(buildPath); - - const schemes = project.schemes.filter( - (scheme) => scheme !== "ALL_BUILD" && scheme !== "ZERO_CHECK", - ); - - assert( - schemes.length === 1, - `Expected exactly one buildable scheme, got ${schemes.join(", ")}`, - ); - - const [scheme] = schemes; - - if (target.length === 1) { - assert.equal( - scheme, - target[0], - "Expected the only scheme to match the requested target", - ); - } - - await spawn( - "xcodebuild", - [ - "archive", - "-scheme", - scheme, - "-configuration", - configuration, - "-destination", - DESTINATION_BY_TRIPLET[triplet], - ], - buildPath, - ); - await spawn( - "xcodebuild", - [ - "install", - "-scheme", - scheme, - "-configuration", - configuration, - "-destination", - DESTINATION_BY_TRIPLET[triplet], - ], - buildPath, - ); - } else { - await spawn("cmake", [ - "--build", - buildPath, - "--config", - configuration, - ...(target.length > 0 ? ["--target", ...target] : []), - "--", - - // Skip code-signing (needed when building free dynamic libraries) - // TODO: Make this configurable - "CODE_SIGNING_ALLOWED=NO", - ]); - // Create a framework - const { artifacts } = sharedLibrary; - assert( - artifacts && artifacts.length === 1, - "Expected exactly one artifact", - ); - const [artifact] = artifacts; - await createAppleFramework({ - libraryPath: path.join(buildPath, artifact.path), - kind: triplet.endsWith("-darwin") ? "versioned" : "flat", - bundleIdentifier: appleBundleIdentifier, - }); - } + await Promise.all( + sharedLibraries.map(async (sharedLibrary) => { + const { name, nameOnDisk, artifacts } = sharedLibrary; + const isFramework = nameOnDisk?.includes(".framework/"); + + if (isFramework) { + const { project } = listXcodeProject(buildPath); + + const schemes = project.schemes.filter( + (scheme) => scheme !== "ALL_BUILD" && scheme !== "ZERO_CHECK", + ); + + assert( + schemes.some((scheme) => scheme === name), + `Expected to find a scheme for ${name}, got ${schemes.join(", ")}`, + ); + + await spawn( + "xcodebuild", + [ + "archive", + "-scheme", + name, + "-configuration", + configuration, + "-destination", + DESTINATION_BY_TRIPLET[triplet], + ], + buildPath, + ); + await spawn( + "xcodebuild", + [ + "install", + "-scheme", + name, + "-configuration", + configuration, + "-destination", + DESTINATION_BY_TRIPLET[triplet], + ], + buildPath, + ); + } else { + await spawn("cmake", [ + "--build", + buildPath, + "--config", + configuration, + ...(target.length > 0 ? ["--target", ...target] : []), + "--", + + // Skip code-signing (needed when building free dynamic libraries) + // TODO: Make this configurable + "CODE_SIGNING_ALLOWED=NO", + ]); + // Create a framework + assert( + artifacts && artifacts.length === 1, + "Expected exactly one artifact", + ); + const [artifact] = artifacts; + await createAppleFramework({ + libraryPath: path.join(buildPath, artifact.path), + kind: triplet.endsWith("-darwin") ? "versioned" : "flat", + bundleIdentifier: appleBundleIdentifier, + }); + } + }), + ); }, isSupportedByHost: function (): boolean | Promise { return process.platform === "darwin"; @@ -466,93 +453,101 @@ export const platform: Platform = { triplets, { configuration, autoLink, xcframeworkExtension, target, build, strip }, ) { - const libraryNames = new Set(); - const frameworkPaths: string[] = []; + const frameworkPathsByName: Record = {}; + // TODO: Run this in parallel for (const { spawn, triplet } of triplets) { const buildPath = getBuildPath(build, triplet); assert(fs.existsSync(buildPath), `Expected a directory at ${buildPath}`); - const sharedLibrary = await readCmakeSharedLibraryTarget( + const sharedLibraries = await readCmakeSharedLibraryTargets( buildPath, configuration, target, ); - const { artifacts } = sharedLibrary; - assert( - artifacts && artifacts.length === 1, - "Expected exactly one artifact", + + await Promise.all( + sharedLibraries.map(async (sharedLibrary) => { + const { name: libraryName, artifacts } = sharedLibrary; + assert( + artifacts && artifacts.length === 1, + "Expected exactly one artifact", + ); + const [artifact] = artifacts; + + const artifactPath = path.join(buildPath, artifact.path); + + if (strip) { + // -r: All relocation entries. + // -S: All symbol table entries. + // -T: All text relocation entries. + // -x: All local symbols. + await spawn("strip", ["-rSTx", artifactPath]); + } + + // Locate the path of the framework, if a free dynamic library was built + if (artifact.path.includes(".framework/")) { + if (libraryName in frameworkPathsByName) { + frameworkPathsByName[libraryName].push( + path.dirname(artifactPath), + ); + } else { + frameworkPathsByName[libraryName] = [path.dirname(artifactPath)]; + } + } else { + const frameworkPath = path.join( + buildPath, + path.dirname(artifact.path), + `${libraryName}.framework`, + ); + assert( + fs.existsSync(frameworkPath), + `Expected to find a framework at: ${frameworkPath}`, + ); + if (libraryName in frameworkPathsByName) { + frameworkPathsByName[libraryName].push(frameworkPath); + } else { + frameworkPathsByName[libraryName] = [frameworkPath]; + } + } + }), ); - const [artifact] = artifacts; - - const artifactPath = path.join(buildPath, artifact.path); - - if (strip) { - // -r: All relocation entries. - // -S: All symbol table entries. - // -T: All text relocation entries. - // -x: All local symbols. - await spawn("strip", ["-rSTx", artifactPath]); - } - - libraryNames.add(sharedLibrary.name); - // Locate the path of the framework, if a free dynamic library was built - if (artifact.path.includes(".framework/")) { - frameworkPaths.push(path.dirname(artifactPath)); - } else { - const libraryName = path.basename( - artifact.path, - path.extname(artifact.path), - ); - const frameworkPath = path.join( - buildPath, - path.dirname(artifact.path), - `${libraryName}.framework`, - ); - assert( - fs.existsSync(frameworkPath), - `Expected to find a framework at: ${frameworkPath}`, - ); - frameworkPaths.push(frameworkPath); - } } - // Make sure none of the frameworks are symlinks - // We do this before creating an xcframework to avoid symlink paths being invalidated - // as the xcframework might be moved to a different location - await Promise.all( - frameworkPaths.map(async (frameworkPath) => { - const stat = await fs.promises.lstat(frameworkPath); - if (stat.isSymbolicLink()) { - await dereferenceDirectory(frameworkPath); - } - }), - ); - - const extension = xcframeworkExtension ? ".xcframework" : ".apple.node"; + for (const [libraryName, frameworkPaths] of Object.entries( + frameworkPathsByName, + )) { + // Make sure none of the frameworks are symlinks + // We do this before creating an xcframework to avoid symlink paths being invalidated + // as the xcframework might be moved to a different location + await Promise.all( + frameworkPaths.map(async (frameworkPath) => { + const stat = await fs.promises.lstat(frameworkPath); + if (stat.isSymbolicLink()) { + await dereferenceDirectory(frameworkPath); + } + }), + ); - assert( - libraryNames.size === 1, - "Expected all libraries to have the same name", - ); - const [libraryName] = libraryNames; + const extension = xcframeworkExtension ? ".xcframework" : ".apple.node"; - // Create the xcframework - const xcframeworkOutputPath = path.resolve( - outputPath, - `${libraryName}${extension}`, - ); + // Create the xcframework + const xcframeworkOutputPath = path.resolve( + outputPath, + `${libraryName}${extension}`, + ); - await oraPromise( - createXCframework({ - outputPath: xcframeworkOutputPath, - frameworkPaths, - autoLink, - }), - { - text: `Assembling XCFramework (${libraryName})`, - successText: `XCFramework (${libraryName}) assembled into ${prettyPath(xcframeworkOutputPath)}`, - failText: ({ message }) => - `Failed to assemble XCFramework (${libraryName}): ${message}`, - }, - ); + await oraPromise( + createXCframework({ + outputPath: xcframeworkOutputPath, + frameworkPaths, + autoLink, + }), + { + text: `Assembling XCFramework (${libraryName})`, + successText: `XCFramework (${libraryName}) assembled into ${prettyPath(xcframeworkOutputPath)}`, + failText: ({ message }) => + `Failed to assemble XCFramework (${libraryName}): ${message}`, + }, + ); + } }, }; diff --git a/packages/gyp-to-cmake/src/cli.ts b/packages/gyp-to-cmake/src/cli.ts index 45cefbaa..13ff8480 100644 --- a/packages/gyp-to-cmake/src/cli.ts +++ b/packages/gyp-to-cmake/src/cli.ts @@ -90,6 +90,11 @@ export const program = new Command("gyp-to-cmake") "Disable emitting target properties to produce Apple frameworks", ) .option("--cpp ", "C++ standard version", "17") + .option( + "--namespaced-targets", + "Use namespaced targets, to allow multiple targets with the same name to be referenced from a single parent project", + false, + ) .addOption(projectNameOption) .argument( "[path]", @@ -107,6 +112,7 @@ export const program = new Command("gyp-to-cmake") weakNodeApi, appleFramework, projectName, + namespacedTargets, }, ) => { const options: Omit = { @@ -117,6 +123,7 @@ export const program = new Command("gyp-to-cmake") defineNapiVersion, weakNodeApi, appleFramework, + namespacedTargets, }; const stat = fs.statSync(targetPath); if (stat.isFile()) { diff --git a/packages/gyp-to-cmake/src/transformer.ts b/packages/gyp-to-cmake/src/transformer.ts index 4901df4f..bc810f09 100644 --- a/packages/gyp-to-cmake/src/transformer.ts +++ b/packages/gyp-to-cmake/src/transformer.ts @@ -16,6 +16,7 @@ export type GypToCmakeListsOptions = { defineNapiVersion?: boolean; weakNodeApi?: boolean; appleFramework?: boolean; + namespacedTargets?: boolean; }; function isCmdExpansion(value: string) { @@ -50,6 +51,7 @@ export function bindingGypToCmakeLists({ weakNodeApi = false, appleFramework = true, compileFeatures = [], + namespacedTargets = false, }: GypToCmakeListsOptions): string { function mapExpansion(value: string): string[] { if (!isCmdExpansion(value)) { @@ -123,12 +125,16 @@ export function bindingGypToCmakeLists({ escapedIncludes.push("${CMAKE_JS_INC}"); } + const actualTargetName = namespacedTargets + ? `${projectName}-${targetName}` + : targetName; + function setTargetPropertiesLines( properties: Record, indent = "", ): string[] { return [ - `${indent}set_target_properties(${targetName} PROPERTIES`, + `${indent}set_target_properties(${actualTargetName} PROPERTIES`, ...Object.entries(properties).map( ([key, value]) => `${indent} ${key} ${value ? value : '""'}`, ), @@ -136,7 +142,9 @@ export function bindingGypToCmakeLists({ ]; } - lines.push(`add_library(${targetName} SHARED ${escapedSources.join(" ")})`); + lines.push( + `add_library(${actualTargetName} SHARED ${escapedSources.join(" ")})`, + ); if (appleFramework) { lines.push( @@ -161,6 +169,8 @@ export function bindingGypToCmakeLists({ { PREFIX: "", SUFFIX: ".node", + // Ensure the final library use the non-namespaced target name + ...(actualTargetName ? { OUTPUT_NAME: targetName } : {}), }, " ", ), @@ -178,13 +188,13 @@ export function bindingGypToCmakeLists({ if (libraries.length > 0) { lines.push( - `target_link_libraries(${targetName} PRIVATE ${libraries.join(" ")})`, + `target_link_libraries(${actualTargetName} PRIVATE ${libraries.join(" ")})`, ); } if (escapedIncludes.length > 0) { lines.push( - `target_include_directories(${targetName} PRIVATE ${escapedIncludes.join( + `target_include_directories(${actualTargetName} PRIVATE ${escapedIncludes.join( " ", )})`, ); @@ -192,17 +202,17 @@ export function bindingGypToCmakeLists({ if (escapedDefines.length > 0) { lines.push( - `target_compile_definitions(${targetName} PRIVATE ${escapedDefines.join(" ")})`, + `target_compile_definitions(${actualTargetName} PRIVATE ${escapedDefines.join(" ")})`, ); } if (compileFeatures.length > 0) { lines.push( - `target_compile_features(${targetName} PRIVATE ${compileFeatures.join(" ")})`, + `target_compile_features(${actualTargetName} PRIVATE ${compileFeatures.join(" ")})`, ); } - // `set_target_properties(${targetName} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)`, + // `set_target_properties(${actualTargetName} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)`, } if (!weakNodeApi) { diff --git a/packages/node-addon-examples/CMakeLists.txt b/packages/node-addon-examples/CMakeLists.txt new file mode 100644 index 00000000..5eab49f8 --- /dev/null +++ b/packages/node-addon-examples/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.15...3.31) +project(node-addon-examples) + +file(GLOB_RECURSE SUBDIR_CMAKE_LISTS + "${CMAKE_CURRENT_SOURCE_DIR}/examples/*/CMakeLists.txt" + "${CMAKE_CURRENT_SOURCE_DIR}/tests/*/CMakeLists.txt" +) + +foreach(SUBDIR_CMAKE ${SUBDIR_CMAKE_LISTS}) + get_filename_component(SUBDIR_PATH ${SUBDIR_CMAKE} DIRECTORY) + add_subdirectory(${SUBDIR_PATH}) +endforeach() diff --git a/packages/node-addon-examples/package.json b/packages/node-addon-examples/package.json index 6063927b..871d418f 100644 --- a/packages/node-addon-examples/package.json +++ b/packages/node-addon-examples/package.json @@ -21,8 +21,8 @@ }, "scripts": { "copy-examples": "tsx scripts/copy-examples.mts", - "gyp-to-cmake": "gyp-to-cmake --weak-node-api .", - "build": "tsx scripts/build-examples.mts", + "gyp-to-cmake": "gyp-to-cmake --namespaced-targets --weak-node-api .", + "build": "cmake-rn --configuration RelWithDebInfo", "copy-and-build": "node --run copy-examples && node --run gyp-to-cmake && node --run build", "verify": "tsx scripts/verify-prebuilds.mts", "test": "node --run copy-and-build && node --run verify", diff --git a/packages/node-addon-examples/scripts/build-examples.mts b/packages/node-addon-examples/scripts/build-examples.mts deleted file mode 100644 index bc447e71..00000000 --- a/packages/node-addon-examples/scripts/build-examples.mts +++ /dev/null @@ -1,14 +0,0 @@ -import { execSync } from "node:child_process"; - -import { findCMakeProjects } from "./cmake-projects.mjs"; - -const projectDirectories = findCMakeProjects(); - -for (const projectDirectory of projectDirectories) { - console.log(`Running "cmake-rn" in ${projectDirectory}`); - execSync("cmake-rn --configuration RelWithDebInfo", { - cwd: projectDirectory, - stdio: "inherit", - }); - console.log(); -} diff --git a/packages/node-addon-examples/tests/async/CMakeLists.txt b/packages/node-addon-examples/tests/async/CMakeLists.txt index 67e5448b..0057bdaa 100644 --- a/packages/node-addon-examples/tests/async/CMakeLists.txt +++ b/packages/node-addon-examples/tests/async/CMakeLists.txt @@ -3,12 +3,12 @@ project(async-test) find_package(weak-node-api REQUIRED CONFIG) -add_library(addon SHARED addon.c) +add_library(async-test-addon SHARED addon.c) option(BUILD_APPLE_FRAMEWORK "Wrap addon in an Apple framework" ON) if(APPLE AND BUILD_APPLE_FRAMEWORK) - set_target_properties(addon PROPERTIES + set_target_properties(async-test-addon PROPERTIES FRAMEWORK TRUE MACOSX_FRAMEWORK_IDENTIFIER async-test.addon MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0 @@ -16,11 +16,12 @@ if(APPLE AND BUILD_APPLE_FRAMEWORK) XCODE_ATTRIBUTE_SKIP_INSTALL NO ) else() - set_target_properties(addon PROPERTIES + set_target_properties(async-test-addon PROPERTIES PREFIX "" SUFFIX .node + OUTPUT_NAME addon ) endif() -target_link_libraries(addon PRIVATE weak-node-api) -target_compile_features(addon PRIVATE cxx_std_17) \ No newline at end of file +target_link_libraries(async-test-addon PRIVATE weak-node-api) +target_compile_features(async-test-addon PRIVATE cxx_std_17) \ No newline at end of file diff --git a/packages/node-addon-examples/tests/buffers/CMakeLists.txt b/packages/node-addon-examples/tests/buffers/CMakeLists.txt index da615db2..929ce9a2 100644 --- a/packages/node-addon-examples/tests/buffers/CMakeLists.txt +++ b/packages/node-addon-examples/tests/buffers/CMakeLists.txt @@ -3,12 +3,12 @@ project(buffers-test) find_package(weak-node-api REQUIRED CONFIG) -add_library(addon SHARED addon.c) +add_library(buffers-test-addon SHARED addon.c) option(BUILD_APPLE_FRAMEWORK "Wrap addon in an Apple framework" ON) if(APPLE AND BUILD_APPLE_FRAMEWORK) - set_target_properties(addon PROPERTIES + set_target_properties(buffers-test-addon PROPERTIES FRAMEWORK TRUE MACOSX_FRAMEWORK_IDENTIFIER buffers-test.addon MACOSX_FRAMEWORK_SHORT_VERSION_STRING 1.0 @@ -16,11 +16,12 @@ if(APPLE AND BUILD_APPLE_FRAMEWORK) XCODE_ATTRIBUTE_SKIP_INSTALL NO ) else() - set_target_properties(addon PROPERTIES + set_target_properties(buffers-test-addon PROPERTIES PREFIX "" SUFFIX .node + OUTPUT_NAME addon ) endif() -target_link_libraries(addon PRIVATE weak-node-api) -target_compile_features(addon PRIVATE cxx_std_17) \ No newline at end of file +target_link_libraries(buffers-test-addon PRIVATE weak-node-api) +target_compile_features(buffers-test-addon PRIVATE cxx_std_17) \ No newline at end of file