Is there a way to specify compiler flags (for example, macroprocessor definitions) on the node -gyp command line?

I am trying to integrate the Node.js addon into an existing build system based on CMake. Building addon requires a large number of macro preprocessor macros and library dependencies available in the context of CMake. I would like to be able to pass them to node-gyp when it is called by CMake. Unfortunately, I could not find an easy way to do this.

I tried using the approach used for plain old gyp as follows:

 node-gyp configure -d -DPOSIX=1 

but the -D option does not seem to be passed to node-gyp . Considering the source of node-gyp , this is not entirely surprising. Is there a direct, direct way to do this, or am I obsessed with programmatically creating entries in binding.gyp , pulling this information from the environment or something else along these lines?

+4
source share
2 answers

I'm not sure why you see the drawback of using the cflags parameter in bind.gyp - but I'm just doing something similar by setting flags using .bashrc

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

+1
source

Use "defines".

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

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

0
source

Source: https://habr.com/ru/post/1499257/


All Articles