Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there way to specify compiler flags (e.g., preprocessor macro definitions) on the node-gyp command line?

I'm trying to integrate a Node.js addon into an existing build system based on CMake. The addon build requires a large number of preprocessor macro definitions and library dependencies that are available in the CMake context. I would like to be able to pass these into node-gyp when it is invoked by CMake. Unfortunately, I have not been able to find a simple way to do so.

I've tried using the approach used for plain old gyp like this:

node-gyp configure -d -DPOSIX=1

but the -D option doesn't seem to be passed on by node-gyp. Looking at the source for node-gyp, this isn't entirely surprising. Is there a straightforward, direct way to do this, or am I stuck with generating the entries in binding.gyp programmatically, pulling in this information from the environment or something else along those lines?

like image 729
Jim Wong Avatar asked Oct 04 '22 03:10

Jim Wong


2 Answers

Use "defines".

{
  "targets": [
    {
      "target_name": "MyAddon",
      "sources": [ "File1.cpp", "File2.cpp" ],
      "libraries": [ "MyNeeded.lib" ],
      "defines": [ "_UNICODE", "UNICODE" ]
    }
  ]
}

This adds the defines to the in your config.gypi when running node-gyp configure

like image 79
huha Avatar answered Oct 12 '22 12:10

huha


I'm not sure why you see a downside to using the cflags setting in binding.gyp - but I just make something similar work by setting the flags using .bashrc

export CFLAGS='-m32' export CXXFLAGS='-m32' export LDFLAGS='-m3'

like image 43
Darren White Avatar answered Oct 12 '22 10:10

Darren White