Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable to node-gyp when running npm install

I am using node-gyp to create a Node.js addon and my binding.gyp contains some variables as follows:

...
"link_settings": {
   "libraries": [
      "-lboost_program_options",
      "-lboost_log",
    ],
    "ldflags": [
       "-L<@(boost_root)/stage/lib",
       "-Wl,-rpath,<@(boost_root)/stage/lib",
     ]
  },
...

(complete gyp file from here ). I use node-gyp configure --boost_root=/PATH/TO/BOOST build to build the C++ sources. The problem arises when I run npm install since it just calls node-gyp rebuild without any parameters.

Is there any way to do any of the following?

  • Not run node-gyp rebuild when running npm install
  • Pass parameters to node-gyp when running npm install
like image 969
Yan Foto Avatar asked Mar 18 '26 09:03

Yan Foto


1 Answers

After a lenghty discussion with @robertklep, I found out that passing the path as a command line flag also solves the problem:

npm install --boost_path=/PATH/TO/BOOST

however as he mentioned it is not known what happens if another package requires my package and tries to pass the parameter to it.

UPDATE:

As it turns out this solution can be applied also if another package uses original package:

npm link /PATH/TO/ORIGINAL_PACKET --boost_path=/PATH/TO/BOOST

or if you have installed from directly from the package manager and now want to install it through the depending package:

npm install --boost_path=/PATH/TO/BOOST
like image 61
Yan Foto Avatar answered Mar 20 '26 21:03

Yan Foto