Git Product home page Git Product logo

Comments (7)

TareHimself avatar TareHimself commented on May 20, 2024

I fixed it with this

 target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/node_modules/node-addon-api" "${CMAKE_SOURCE_DIR}/../../node-addon-api" "src" )

But is there a better way to handle this ?

from cmake-js.

TareHimself avatar TareHimself commented on May 20, 2024

Also while not related to the issue, Is it possible to have Native Package B, depend on Native Package A such that B can import and use all headers and such defined in A? Like in my case I have a torch package that has basic tensor operations and another package for torchvision. but I do not want to have to redefine tensors and all that and instead want to use what I already have done in the previous package.

from cmake-js.

Julusian avatar Julusian commented on May 20, 2024

cmake-js attempts to find node-addon-api, and adds it to the CMAKE_JS_INC variable if it finds it. I don't know why it wouldn't be successful in doing so

Also while not related to the issue, Is it possible to have Native Package B, depend on Native Package A such that B can import and use all headers and such defined in A?

I'm not entirely following what you are asking, but probably. It sounds like a more general cmake question than something specific to this lib

from cmake-js.

mmomtchev avatar mmomtchev commented on May 20, 2024

cmake-js does a very unusual check for if a module is using node-addon-api - based on the presence of:

  "binary": {
    "napi_versions": [
      7
    ]
  }

in package.json

If you include this property, it will correctly add the node-addon-api directory.

AFAIK, currently there is no such requirement for node-addon-api projects - but there seem to have been such an idea in the early days - napi-build-utils and @mapbox/node-pre-gyp both mention it.

Additionally, when cmake-js detects the presence of this napi_versions, it will also disable access to the low-level API - including uv.h. Normally a node-addon-api project is not supposed to access the low-level API - except for uv.h.

My proposal is to make it a little bit less intelligent. Always include the low-level API as retrieved from the remote server. And try to simply detect the presence of node_modules/node-addon-api and node_modules/nan. This will match the behavior of node-gyp.

from cmake-js.

mmomtchev avatar mmomtchev commented on May 20, 2024

@TareHimself open a separate issue with this question, and I will share my experience on this matter, which does not have a simple solution. gdal-exprtk does this.

from cmake-js.

remyjette avatar remyjette commented on May 20, 2024

cmake-js attempts to find node-addon-api, and adds it to the CMAKE_JS_INC variable if it finds it. I don't know why it wouldn't be successful in doing so

I was hitting this too, and figured out why by enabling --log-level silly and digging through the code a bit

If --directory is set to anything other than the package.json directory, it will fail

In my project, Node is only one of the many platforms we build for. Thus we have CMakeLists.txt in the root, and electron/package.json in a subfolder. Our build calls cmake-js --directory ../ to make this work.

The README says " -d, --directory specify CMake project's directory (where CMakeLists.txt located)` - it doesn't say package.json has to be in the same directory as the CMakeLists.txt (if it did I'm not sure why this option would exist). It also doesn't say where the directory needs to be in relation to the package.json, which is why my understanding is putting CMakeLists.txt in a parent dir should work.

this.options.isNodeApi = isNodeApi(this.log, this.options.directory) passes that directory to isNodeApi

isNode Api does

const tmpRequire = require('module').createRequire(path.join(projectRoot, 'package.json'))

<projectRoot>/package.json doesnt exist for me, my package.json is in <projectRoot>/electron/package.json, so this fails

from cmake-js.

TareHimself avatar TareHimself commented on May 20, 2024

I was missing node.lib this is the fixed CMakeList https://github.com/nodeml/torch/blob/main/CMakeLists.txt

from cmake-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.