I'm trying to build a native Node.js module that links against a 3rd party shared library. This library is delivered as part of a bundle that includes pre-built versions for different OSes and Architectures in different directories.
e.g.
/opt/Foo/linux/x86/lib/libfoo.so
/opt/Foo/linux/x86/include/foo.h
/opt/Foo/linux/x86_64/lib/libfoo.so
/opt/Foo/linux/x86_64/include/foo.h
/opt/Foo/linux/arm/lib/libfoo.so
/opt/Foo/linux/arm/include/foo.h
/opt/Foo/mac/x86_64/lib/libfoo.so
/opt/Foo/mac/x86_64/include/foo.h
my binding.gyp currently looks like this:
{
'targets': [
{
'target_name': 'foo',
'sources': ['foo.cpp', 'foo.h'],
'include_dirs': ["<!(node -e \"require('nan')\")"],
'conditions': [
['OS=="mac"', {
'include_dirs': ['/opt/Foo/mac/x86_64/include'],
'libraries': ['-L/opt/Foo/mac/x86_64/lib', '-lfoo']
}
],
['OS=="linux"', {
'include_dirs': ['/opt/Foo/linux/x86_64/include'],
'libraries': ['-L/opt/Foo/linux/x86_64/lib', '-lfoo']
}
]
]
}
]
}
I don't seem to be able to find the syntax for conditions
to differentiate on the current platform architecture.
Having not found any other solutions I came up with the following:
...
['OS=="linux"', {
'include_dirs': ["<!(node -e \"console.log('/opt/Foo/linux/%s/include',require('process').arch);\")"],
'libraries': ["<!(node -e \"console.log('-L/opt/Foo/linux/%s/lib',require('process').arch);\")", '-lfoo']
}
]
...
I had to rename the /opt/Foo/Linux/x86_64
to directory to /opt/Foo/Linux/x64
to match the output from process.arch.