Hi,
Is there a way to default a variable in binding.gyp yet allow a different user externally set a different value.
https://github.com/HDF-NI/hdf5.node/blob/master/binding.gyp#L3
Some people have a hard coded path to native dependencies while others like a more app packaged deployment and/or the ability to have more than one version installed
"hdf5_home_linux": "/usr/local"
How to keep a default yet make it adaptable for other choices?
In theory, you can pass custom defines to node-gyp like this:
$ node-gyp -Dhdf5_home_linux=/foo/bar rebuild
You need to declare the variable as configurable in your binding.gyp, like this:
'variables': { 'hdf5_home_linux%': '/usr/local' }
Having said that, I had a look at the code that implements argument parsing and it looks broken to me. I'll see if I can come up with a PR.
Also, how to get npm to pass the -D option to node-gyp is something I'll have to leave as an exercise to the reader because I don't know. :-)
Thank you for looking into this. I'll test further
I found that this does work to make npm (node-v5.0.0) pick up the variable as a switch.
npm install --hdf5_home_linux=<pathtoyourhdf5install>
for example where this was a dependent project that used my module
For anyone coming here through a search engine, you can alternatively pass options through the GYP_DEFINES environment variable:
$ env GYP_DEFINES="name=value name2=value" npm install
That should work with any node-gyp version.
For anyone coming here through a search engine
The GYP_DEFINES is enabled by command line option "--ignore-environment", which by default is true.
Most helpful comment
For anyone coming here through a search engine, you can alternatively pass options through the GYP_DEFINES environment variable:
That should work with any node-gyp version.