Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake + Vcpkg example #575

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

Pospelove
Copy link

@Pospelove Pospelove commented Jan 8, 2025

WIP, will extend docs and add node-addon-api example

@mhdawson mhdawson requested a review from vmoroz January 17, 2025 16:11
@gabrielschulhof
Copy link
Contributor

@Pospelove thanks for the examples! Is there a reason build_with_cmake is being replaced with build_with_cmakejs rather than being shown as an example in addition to build_with_cmake?

@Pospelove
Copy link
Author

Hello everyone, and thanks for the interest! I’m planning to finish this PR by adding a C++ example and running the necessary tests.

There are a few points I’d like to discuss further, as they might need some consensus:

  1. vcpkg submodule: In the draft, I’ve included a vcpkg submodule, which is the recommended approach for manifest mode. Do you think we should stick with this? Or would it be better to simply mention it as an option, provide a link to the relevant documentation, and let users rely on their system-installed vcpkg instead?

  2. CMake/CMake.js naming: @gabrielschulhof raised a good point about the naming inconsistency between cmake and cmakejs. I’d love to hear your thoughts on how we can make this clearer.

I updated the CMake.js section of the docs because the mismatch between CMake and CMake.js can be confusing for developers who are coming from a C++ background.

To provide some context, the node-api-headers and node-addon-api vcpkg ports are quite handy for building native addons without needing CMake.js or npm at all. Here’s why they might be a good fit for many projects:

  1. They’re ideal for existing C++ projects that are already managed with CMake and vcpkg, where CMake.js isn’t typically used.
  2. They make it straightforward to connect Node.js to your C++ code—similar to integrating Lua or Boost.Python. But! Unlike the C++ Embedder API, this method still creates a native addon.

@Pospelove
Copy link
Author

Pospelove commented Jan 17, 2025

P.S. I'll be able to get back to this PR once examples land

P.S.S. I use the node-addon-api in https://github.com/skyrim-multiplayer/skymp for a long time and it works so much better than anything else like node-gyp or cmake.js. The mix of C++ and TypeScript code is being built by CMake build system. In the past the project was invoking cmake.js via npm as a subprocess from root CMake build system. Imagine what a rabbithole there was!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Need Triage
Development

Successfully merging this pull request may close these issues.

2 participants